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

jesse at bestpractical.com jesse at bestpractical.com
Sat Aug 9 22:13:07 EDT 2008


Author: jesse
Date: Sat Aug  9 22:13:07 2008
New Revision: 14970

Modified:
   Net-Trac/trunk/lib/Net/Trac.pm
   Net-Trac/trunk/lib/Net/Trac/Connection.pm
   Net-Trac/trunk/lib/Net/Trac/Mechanize.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/lib/Net/Trac/TicketPropChange.pm

Log:
perltidy

Modified: Net-Trac/trunk/lib/Net/Trac.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac.pm	Sat Aug  9 22:13:07 2008
@@ -1,10 +1,6 @@
 package Net::Trac;
 use Moose;
 
-
 our $VERSION = '0.01_01';
 
-
-
-
 'This is the end of the file';

Modified: Net-Trac/trunk/lib/Net/Trac/Connection.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/Connection.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/Connection.pm	Sat Aug  9 22:13:07 2008
@@ -8,78 +8,79 @@
 use Params::Validate;
 use Net::Trac::Mechanize;
 
-
 has url => (
     isa => 'Str',
-    is => 'ro'
-    );
+    is  => 'ro'
+);
 has user => (
     isa => 'Str',
-    is => 'ro'
-    );
+    is  => 'ro'
+);
 
 has password => (
     isa => 'Str',
-    is => 'ro'
+    is  => 'ro'
 );
 
-
-has logged_in => ( 
+has logged_in => (
     isa => 'Bool',
-    is => 'rw');
+    is  => 'rw'
+);
 
 has mech => (
-    isa => 'Net::Trac::Mechanize',
-    is => 'ro',
-   lazy => 1,
-    default => sub {my $self = shift; my $m = Net::Trac::Mechanize->new();
-    $m->cookie_jar({});
-    $m->trac_user($self->user);
-        $m->trac_password( $self->password);
-        return $m;  
-        
-        }
+    isa     => 'Net::Trac::Mechanize',
+    is      => 'ro',
+    lazy    => 1,
+    default => sub {
+        my $self = shift;
+        my $m    = Net::Trac::Mechanize->new();
+        $m->cookie_jar( {} );
+        $m->trac_user( $self->user );
+        $m->trac_password( $self->password );
+        return $m;
+
+    }
 );
 
 sub _fetch {
-    my $self = shift;
-    my $query = shift;
-    my $abs_url = $self->url.$query;
+    my $self    = shift;
+    my $query   = shift;
+    my $abs_url = $self->url . $query;
     $self->mech->get($abs_url);
     $self->_die_on_error($abs_url);
-    return $self->mech->content; 
+    return $self->mech->content;
 }
 
-
 sub _die_on_error {
     my $self = shift;
-    my $url = shift;
-    if (!$self->mech->response->is_success)  {
-        die "Server threw an error ". $self->mech->response->status_line . " for " .$url;
-    }
-    elsif ($self->mech->content =~ qr{
+    my $url  = shift;
+    if ( !$self->mech->response->is_success ) {
+        die "Server threw an error "
+            . $self->mech->response->status_line . " for "
+            . $url;
+    } elsif (
+        $self->mech->content =~ qr{
    <div id="content" class="error">
           <h1>(.*?)</h1>
-            <p class="message">(.*?)</p>}ismx ) {
-            die "$1 $2";
-        }
+            <p class="message">(.*?)</p>}ismx
+        )
+    {
+        die "$1 $2";
+    }
 
-    else { return undef}
+    else { return undef }
 }
 
-
 sub ensure_logged_in {
     my $self = shift;
-    if (!defined $self->logged_in) {
-    $self->_fetch( "/login");
-    warn $self->mech->response;
-    $self->logged_in(1); 
+    if ( !defined $self->logged_in ) {
+        $self->_fetch("/login");
+        warn $self->mech->response;
+        $self->logged_in(1);
     }
     return $self->logged_in;
-    
-}
-
 
+}
 
 sub _fetch_feed {
     my $self  = shift;
@@ -89,21 +90,22 @@
 
     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 $x = $args{'data'};
-    my $io   = IO::Scalar->new( $x);
-    my @cols =  @{$csv->getline($io)||[]};
+    my $x    = $args{'data'};
+    my $io   = IO::Scalar->new($x);
+    my @cols = @{ $csv->getline($io) || [] };
     return unless defined $cols[0];
-    $csv->column_names( @cols);
+    $csv->column_names(@cols);
     my $hashref;
+
     while ( my $row = $csv->getline_hr($io) ) {
         $hashref->{ $row->{ $args{'key'} } } = $row;
     }
     return $hashref;
 }
 
-
 1;

Modified: Net-Trac/trunk/lib/Net/Trac/Mechanize.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/Mechanize.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/Mechanize.pm	Sat Aug  9 22:13:07 2008
@@ -3,11 +3,11 @@
 use Moose;
 extends 'WWW::Mechanize';
 
-has trac_user => ( isa => 'Str', is => 'rw');
-has trac_password => ( isa => 'Str', is => 'rw');
+has trac_user     => ( isa => 'Str', is => 'rw' );
+has trac_password => ( isa => 'Str', is => 'rw' );
 
 sub get_basic_credentials {
     my $self = shift;
-    return ($self->trac_user => $self->trac_password);
+    return ( $self->trac_user => $self->trac_password );
 }
 1;

Modified: Net-Trac/trunk/lib/Net/Trac/Ticket.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/Ticket.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/Ticket.pm	Sat Aug  9 22:13:07 2008
@@ -31,11 +31,10 @@
     my ($id) = validate_pos( @_, { type => SCALAR } );
     $self->connection->_fetch( "/ticket/" . $id . "?format=csv" );
 
-
-           my $content =      $self->connection->mech->content;
+    my $content = $self->connection->mech->content;
 
     my $stateref
-        = $self->connection->_csv_to_struct( data => \$content , key => 'id' );
+        = $self->connection->_csv_to_struct( data => \$content, key => 'id' );
     return undef unless $stateref;
     $self->state( $stateref->{$id} );
     return $id;
@@ -90,7 +89,7 @@
             component   => 0,
             version     => 0,
             keywords    => 0,
-            cc => 0,
+            cc          => 0,
             status      => 0
 
         }
@@ -98,16 +97,12 @@
 
     my $form = $self->_get_new_ticket_form();
 
+    my %form = map { 'field_' . $_ => $args{$_} } keys %args;
 
-    my %form = map {
-            'field_'.$_ => $args{$_}
-    } keys %args;
-
-    $self->connection->mech->submit_form( form_number => 2, # BRITTLE
-            fields => {
-                %form,
-                submit => 1
-            });
+    $self->connection->mech->submit_form(
+        form_number => 2,                  # BRITTLE
+        fields => { %form, submit => 1 }
+    );
 
     my $reply = $self->connection->mech->response;
 }

Modified: Net-Trac/trunk/lib/Net/Trac/TicketHistory.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/TicketHistory.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/TicketHistory.pm	Sat Aug  9 22:13:07 2008
@@ -4,34 +4,36 @@
 
 has connection => (
     isa => 'Net::Trac::Connection',
-    is => 'ro'
-    );
+    is  => 'ro'
+);
 
 has ticket => (
     isa => 'Str',
-    is => 'ro'
+    is  => 'ro'
 );
 
 has entries => (
     isa => 'ArrayRef',
-    is => 'rw');
+    is  => 'rw'
+);
 
 sub load {
     my $self = shift;
-    my $feed = $self->connection->_fetch_feed("/ticket/".$self->ticket."?format=rss");
+    my $feed = $self->connection->_fetch_feed(
+        "/ticket/" . $self->ticket . "?format=rss" );
 
     my @entries = $feed->entries;
     my @history;
     foreach my $entry (@entries) {
-        my $e = Net::Trac::TicketHistoryEntry->new( { connection => $self->connection});
+        my $e = Net::Trac::TicketHistoryEntry->new(
+            { connection => $self->connection } );
         $e->parse_feed_entry($entry);
         push @history, $e;
     }
+
     # http://barnowl.mit.edu/ticket/1?format=rss
-    $self->entries(\@history);
+    $self->entries( \@history );
     return 1;
 }
 
-
-
 1;

Modified: Net-Trac/trunk/lib/Net/Trac/TicketHistoryEntry.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/TicketHistoryEntry.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/TicketHistoryEntry.pm	Sat Aug  9 22:13:07 2008
@@ -2,19 +2,17 @@
 use Moose;
 use Net::Trac::TicketPropChange;
 
-
 has connection => (
     isa => 'Net::Trac::Connection',
     is  => 'ro'
 );
 
-has prop_changes  => ( isa => 'HashRef', is => 'rw' );
+has prop_changes => ( isa => 'HashRef', is => 'rw' );
 
-has author   => ( isa => 'Str', is => 'rw' );
+has author   => ( isa => 'Str',      is => 'rw' );
 has date     => ( isa => 'DateTime', is => 'rw' );
-has category => ( isa => 'Str', is => 'rw' );
-has content => ( isa => 'Str', is => 'rw');
-
+has category => ( isa => 'Str',      is => 'rw' );
+has content  => ( isa => 'Str',      is => 'rw' );
 
 sub parse_feed_entry {
     my $self = shift;
@@ -26,47 +24,50 @@
 
     my $desc = $e->content->body;
 
-    if ($desc =~ s/^\s*<ul>\s*?<li>(.*?)<\/li>\s*?<\/ul>//gism) {
+    if ( $desc =~ s/^\s*<ul>\s*?<li>(.*?)<\/li>\s*?<\/ul>//gism ) {
 
         my $props = $1;
-        $self->prop_changes($self->_parse_props($props));
+        $self->prop_changes( $self->_parse_props($props) );
 
     }
 
-
     $self->content($desc);
     return 1;
 }
 
 sub _parse_props {
-    my $self = shift;
-    my $raw = shift;
-    my @prop_lines = split(m#</li>\s*<li>#, $raw); 
-    my $props = {};
-foreach my $line (@prop_lines) {
-    my $prop  = '';
-    my $new = '';
-    my $old = '';
-    if ($line =~ /<strong>(.*?)<\/strong> changed from <em>(.*)<\/em> to <em>(.*)<\/em>/) {
-         $prop = $1;
-         $old = $2;
-         $new = $3;
+    my $self       = shift;
+    my $raw        = shift;
+    my @prop_lines = split( m#</li>\s*<li>#, $raw );
+    my $props      = {};
+    foreach my $line (@prop_lines) {
+        my $prop = '';
+        my $new  = '';
+        my $old  = '';
+        if ( $line
+            =~ /<strong>(.*?)<\/strong> changed from <em>(.*)<\/em> to <em>(.*)<\/em>/
+            )
+        {
+            $prop = $1;
+            $old  = $2;
+            $new  = $3;
+        } elsif ( $line =~ /<strong>(.*?)<\/strong> set to <em>(.*)<\/em>/ ) {
+            $prop = $1;
+            $old  = '';
+            $new  = $2;
+        } elsif ( $line =~ /<strong>(.*?)<\/strong> deleted/ ) {
+            $prop = $1;
+            $new  = '';
+        }
+
+        my $pc = Net::Trac::TicketPropChange->new(
+            property  => $prop,
+            new_value => $new,
+            old_value => $old
+        );
+        $props->{$prop} = $pc;
     }
-    elsif ($line =~ /<strong>(.*?)<\/strong> set to <em>(.*)<\/em>/) {
-         $prop = $1;
-        $old = '';
-         $new = $2;
-    } 
-    elsif ($line =~ /<strong>(.*?)<\/strong> deleted/) {
-         $prop = $1;
-         $new = '';
-    } 
-
-    my $pc = Net::Trac::TicketPropChange->new( property => $prop, new_value => $new, old_value => $old  );
-    $props->{$prop} = $pc; 
-}
     return $props;
 }
 
-
 1;

Modified: Net-Trac/trunk/lib/Net/Trac/TicketPropChange.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/TicketPropChange.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/TicketPropChange.pm	Sat Aug  9 22:13:07 2008
@@ -1,8 +1,8 @@
 package Net::Trac::TicketPropChange;
 use Moose;
 
-has property => (isa => 'Str', is => 'rw');
-has old_value => (isa => 'Str', is => 'rw');
-has new_value => (isa => 'Str', is => 'rw');
+has property  => ( isa => 'Str', is => 'rw' );
+has old_value => ( isa => 'Str', is => 'rw' );
+has new_value => ( isa => 'Str', is => 'rw' );
 
 1;



More information about the Bps-public-commit mailing list