[Bps-public-commit] r14039 - in Net-Trac/trunk: lib lib/Net/Trac t

jesse at bestpractical.com jesse at bestpractical.com
Sun Jul 13 14:16:37 EDT 2008


Author: jesse
Date: Sun Jul 13 14:16:37 2008
New Revision: 14039

Added:
   Net-Trac/trunk/lib/
   Net-Trac/trunk/lib/Net/
   Net-Trac/trunk/lib/Net/Trac/
   Net-Trac/trunk/lib/Net/Trac/.Connection.pm.swp   (contents, props changed)
   Net-Trac/trunk/lib/Net/Trac/.Ticket.pm.swp   (contents, props changed)
   Net-Trac/trunk/lib/Net/Trac/.TicketHistory.pm.swp   (contents, props changed)
   Net-Trac/trunk/lib/Net/Trac/.TicketHistoryEntry.pm.swp   (contents, props changed)
   Net-Trac/trunk/lib/Net/Trac/Connection.pm
   Net-Trac/trunk/lib/Net/Trac/Ticket.pm
   Net-Trac/trunk/lib/Net/Trac/TicketHistory.pm
   Net-Trac/trunk/lib/Net/Trac/TicketHistoryEntry.pm
   Net-Trac/trunk/t/
   Net-Trac/trunk/t/.basic.t.swp   (contents, props changed)
   Net-Trac/trunk/t/basic.t

Log:
Initial import of trac hacking

Added: Net-Trac/trunk/lib/Net/Trac/.Connection.pm.swp
==============================================================================
Binary file. No diff available.

Added: Net-Trac/trunk/lib/Net/Trac/.Ticket.pm.swp
==============================================================================
Binary file. No diff available.

Added: Net-Trac/trunk/lib/Net/Trac/.TicketHistory.pm.swp
==============================================================================
Binary file. No diff available.

Added: Net-Trac/trunk/lib/Net/Trac/.TicketHistoryEntry.pm.swp
==============================================================================
Binary file. No diff available.

Added: Net-Trac/trunk/lib/Net/Trac/Connection.pm
==============================================================================
--- (empty file)
+++ Net-Trac/trunk/lib/Net/Trac/Connection.pm	Sun Jul 13 14:16:37 2008
@@ -0,0 +1,54 @@
+package Net::Trac::Connection;
+use Moose;
+use LWP::Simple;
+    use XML::Feed;
+use URI;
+use Text::CSV_XS;
+use IO::Scalar;
+use Params::Validate;
+
+has url => (
+    isa => 'Str',
+    is => 'ro'
+    );
+has user => (
+    isa => 'Str',
+    is => 'ro'
+    );
+
+has password => (
+    isa => 'Str',
+    is => 'ro'
+);
+
+
+sub _fetch {
+    my $self = shift;
+    my $query = shift;
+    return LWP::Simple::get($self->url.$query); 
+
+}
+
+sub _fetch_feed {
+    my   $self = shift;
+    my  $query = shift;
+    my $feed = XML::Feed->parse(URI->new($self->url .$query))
+        or die XML::Feed->errstr;
+
+    return $feed;
+}
+sub _csv_to_struct {
+    my $self = shift;
+    my %args = validate( @_, { data => 1, key => 1 } );
+    my $csv  = Text::CSV_XS->new( { binary => 1 } );
+    my $io   = IO::Scalar->new( $args{'data'} );
+    $csv->column_names( $csv->getline($io) );
+    my $hashref;
+    while ( my $row = $csv->getline_hr($io) ) {
+        $hashref->{ $row->{ $args{'key'} } } = $row;
+    }
+    return $hashref;
+}
+
+
+1;

Added: Net-Trac/trunk/lib/Net/Trac/Ticket.pm
==============================================================================
--- (empty file)
+++ Net-Trac/trunk/lib/Net/Trac/Ticket.pm	Sun Jul 13 14:16:37 2008
@@ -0,0 +1,45 @@
+package Net::Trac::Ticket;
+use Moose;
+use Params::Validate qw(:all);
+use Net::Trac::TicketHistory;
+
+has connection => (
+    isa => 'Net::Trac::Connection',
+    is => 'ro'
+    );
+
+has state => (
+    isa => 'HashRef',
+    is => 'rw'
+);
+
+our @PROPS = qw(cc component description id keywords milestone
+                owner priority reporter resolution status summary type);
+
+
+for my $prop (@PROPS) {
+    no strict 'refs';
+    *{"Net::Trac::Ticket::".$prop} = sub { shift->state->{$prop}};
+}
+
+
+sub load {
+    my $self = shift;
+    my ($id) = validate_pos( @_, { type => SCALAR } );
+    my $state = $self->connection->_fetch( "/ticket/" . $id . "?format=csv" );
+    my $stateref = $self->connection->_csv_to_struct(data => \$state, key => 'id');
+    $self->state($stateref->{$id});
+}
+
+sub history {
+    my $self = shift;
+    my $hist = Net::Trac::TicketHistory->new( {connection => $self->connection, ticket => $self->id });
+    $hist->load;
+
+}
+
+
+
+
+#http://barnowl.mit.edu/ticket/36?format=tab
+1;

Added: Net-Trac/trunk/lib/Net/Trac/TicketHistory.pm
==============================================================================
--- (empty file)
+++ Net-Trac/trunk/lib/Net/Trac/TicketHistory.pm	Sun Jul 13 14:16:37 2008
@@ -0,0 +1,29 @@
+package Net::Trac::TicketHistory;
+use Moose;
+
+has connection => (
+    isa => 'Net::Trac::Connection',
+    is => 'ro'
+    );
+
+has ticket => (
+    isa => 'Str',
+    is => 'ro'
+);
+
+sub load {
+    my $self = shift;
+    my $feed = $self->connection->_fetch_feed("/ticket/".$self->ticket."?format=rss");
+
+    my @entries = $feed->entries;
+    die "Found ".$#entries; 
+    foreach my $entry (@entries) {
+        my $e = Net::Trac::TicektHistory->new( { connection => $self->connection});
+        $e->parse_feed_entry($entry);
+    }
+    # http://barnowl.mit.edu/ticket/1?format=rss
+}
+
+
+
+1;

Added: Net-Trac/trunk/lib/Net/Trac/TicketHistoryEntry.pm
==============================================================================
--- (empty file)
+++ Net-Trac/trunk/lib/Net/Trac/TicketHistoryEntry.pm	Sun Jul 13 14:16:37 2008
@@ -0,0 +1,19 @@
+package Net::Trac::TicketHistoryEntry;
+use Moose;
+
+has connection => (
+    isa => 'Net::Trac::Connection',
+    is => 'ro'
+    );
+
+
+sub parse_feed_entry {
+    my $self = shift;
+    my $xml_feed_entry = shift;
+    warn $xml_feed_entry;
+
+    return 1;
+}
+
+
+1;

Added: Net-Trac/trunk/t/.basic.t.swp
==============================================================================
Binary file. No diff available.

Added: Net-Trac/trunk/t/basic.t
==============================================================================
--- (empty file)
+++ Net-Trac/trunk/t/basic.t	Sun Jul 13 14:16:37 2008
@@ -0,0 +1,16 @@
+use Test::More qw/no_plan/;
+
+use_ok('Net::Trac::Connection');
+my $trac = Net::Trac::Connection->new(url => "http://scripts.mit.edu/~jrv/trac");
+isa_ok($trac, "Net::Trac::Connection");
+is($trac->url, "http://scripts.mit.edu/~jrv/trac");
+
+can_ok($trac, '_fetch');
+use_ok('Net::Trac::Ticket');
+my $ticket = Net::Trac::Ticket->new( connection => $trac);
+isa_ok($ticket, 'Net::Trac::Ticket');
+can_ok($ticket, 'load');
+ok($ticket->load(1));
+like($ticket->state->{'summary'}, qr/pony/);
+like($ticket->summary, qr/pony/);
+ok($ticket->history);



More information about the Bps-public-commit mailing list