[Bps-public-commit] r19707 - in Net-Google-Code/trunk: . lib/Net/Google lib/Net/Google/Code lib/Net/Google/Code/Issue lib/Net/Google/Code/Role

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon May 18 09:43:55 EDT 2009


Author: sunnavy
Date: Mon May 18 09:43:55 2009
New Revision: 19707

Added:
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/DateTime.pm
Modified:
   Net-Google-Code/trunk/Makefile.PL
   Net-Google-Code/trunk/lib/Net/Google/Code.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Download.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Comment.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm
   Net-Google-Code/trunk/t/03.comment.t

Log:
make parse_datetime a role, also update relative stuff accordingly

Modified: Net-Google-Code/trunk/Makefile.PL
==============================================================================
--- Net-Google-Code/trunk/Makefile.PL	(original)
+++ Net-Google-Code/trunk/Makefile.PL	Mon May 18 09:43:55 2009
@@ -12,6 +12,7 @@
 requires 'WWW::Mechanize';
 requires 'HTML::TreeBuilder';
 requires 'Params::Validate';
+requires 'DateTime';
 
 recursive_author_tests('xt/');
 

Modified: Net-Google-Code/trunk/lib/Net/Google/Code.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code.pm	Mon May 18 09:43:55 2009
@@ -3,7 +3,8 @@
 use Moose;
 with 'Net::Google::Code::Role::Fetchable', 'Net::Google::Code::Role::URL',
   'Net::Google::Code::Role::Pageable', 'Net::Google::Code::Role::HTMLTree',
-  'Net::Google::Code::Role::Authentication';
+  'Net::Google::Code::Role::Authentication',
+  'Net::Google::Code::Role::DateTime';
 use Scalar::Util qw/blessed/;
 
 our $VERSION = '0.05';
@@ -130,39 +131,6 @@
     return 1;
 }
 
-our %MONMAP = (
-    Jan => 1,
-    Feb => 2,
-    Mar => 3,
-    Apr => 4,
-    May => 5,
-    Jun => 6,
-    Jul => 7,
-    Aug => 8,
-    Sep => 9,
-    Oct => 10,
-    Nov => 11,
-    Dec => 12
-    );
-sub parse_datetime {
-    my $self = shift;
-    my $base_date = shift;
-    if ($base_date =~ /\w{3}\s+(\w+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\d{4})/) {
-        my $mon =  $1;
-        my $dom = $2;
-        my $h = $3;
-        my $m = $4;
-        my $s = $5;
-        my $y = $6;
-        my $dt = DateTime->new( year => $y,
-                                month => $MONMAP{$mon},
-                                day => $dom,
-                                hour => $h,
-                                minute => $m,
-                                second => $s);
-                            return $dt;
-    }
-}
 
 sub load_downloads {
     my $self = shift;

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Download.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Download.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Download.pm	Mon May 18 09:43:55 2009
@@ -5,7 +5,9 @@
 use Scalar::Util qw/blessed/;
 
 with 'Net::Google::Code::Role::Fetchable', 'Net::Google::Code::Role::URL',
-  'Net::Google::Code::Role::HTMLTree', 'Net::Google::Code::Role::Authentication';
+  'Net::Google::Code::Role::HTMLTree',
+  'Net::Google::Code::Role::Authentication',
+  'Net::Google::Code::Role::DateTime';
 
 has 'project' => (
     isa      => 'Str',

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm	Mon May 18 09:43:55 2009
@@ -3,7 +3,8 @@
 use Params::Validate qw(:all);
 with 'Net::Google::Code::Role::Fetchable', 'Net::Google::Code::Role::URL',
      'Net::Google::Code::Role::HTMLTree',
-     'Net::Google::Code::Role::Authentication';
+     'Net::Google::Code::Role::Authentication',
+     'Net::Google::Code::Role::DateTime';
 use Net::Google::Code::Issue::Comment;
 use Net::Google::Code::Issue::Attachment;
 use Scalar::Util qw/blessed/;
@@ -100,7 +101,7 @@
     my $description = $tree->look_down( class => 'vt issuedescription' );
     my $author_tag = $description->look_down( class => "author" );
     $self->reporter( $author_tag->content_array_ref->[1]->as_text );
-    $self->reported(Net::Google::Code->parse_datetime($author_tag->look_down( class => 'date' )->attr('title') ));
+    $self->reported( $self->parse_datetime($author_tag->look_down( class => 'date' )->attr('title') ));
 
 
     my $text = $description->find_by_tag_name('pre')->as_text;

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Comment.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Comment.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Comment.pm	Mon May 18 09:43:55 2009
@@ -1,7 +1,7 @@
 package Net::Google::Code::Issue::Comment;
 use Moose;
 use Net::Google::Code::Issue::Attachment;
-with 'Net::Google::Code::Role::HTMLTree';
+with 'Net::Google::Code::Role::HTMLTree', 'Net::Google::Code::Role::DateTime';
 
 has 'updates' => ( isa => 'HashRef', is => 'rw', default => sub { {} } );
 has 'author'  => ( isa => 'Str',     is => 'rw' );
@@ -23,7 +23,7 @@
     my @a       = $author->find_by_tag_name('a');
     $self->sequence( $a[0]->content_array_ref->[0] );
     $self->author( $a[1]->content_array_ref->[0] );
-    $self->date(Net::Google::Code->parse_datetime( $element->look_down( class => 'date' )->attr('title') ));
+    $self->date($self->parse_datetime( $element->look_down( class => 'date' )->attr('title') ));
     my $content = $element->find_by_tag_name('pre')->as_text;
     $content =~ s/^\s+//;
     $content =~ s/\s+$/\n/;

Added: Net-Google-Code/trunk/lib/Net/Google/Code/Role/DateTime.pm
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/DateTime.pm	Mon May 18 09:43:55 2009
@@ -0,0 +1,71 @@
+package Net::Google::Code::Role::DateTime;
+use Moose::Role;
+use DateTime;
+
+our %MONMAP = (
+    Jan => 1,
+    Feb => 2,
+    Mar => 3,
+    Apr => 4,
+    May => 5,
+    Jun => 6,
+    Jul => 7,
+    Aug => 8,
+    Sep => 9,
+    Oct => 10,
+    Nov => 11,
+    Dec => 12,
+);
+
+sub parse_datetime {
+    my $self      = shift;
+    my $base_date = shift;
+    if (
+        $base_date =~ /\w{3}\s+(\w+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\d{4})/ )
+    {
+        my $mon = $1;
+        my $dom = $2;
+        my $h   = $3;
+        my $m   = $4;
+        my $s   = $5;
+        my $y   = $6;
+        my $dt  = DateTime->new(
+            year   => $y,
+            month  => $MONMAP{$mon},
+            day    => $dom,
+            hour   => $h,
+            minute => $m,
+            second => $s
+        );
+        return $dt;
+    }
+}
+
+no Moose::Role;
+
+1;
+
+__END__
+
+=head1 NAME
+
+Net::Google::Code::Role::DateTime - DateTime Role
+
+=head1 DESCRIPTION
+
+=head1 INTERFACE
+
+=head2 parse_datetime
+
+=head1 AUTHOR
+
+sunnavy  C<< <sunnavy at bestpractical.com> >>
+
+=head1 LICENCE AND COPYRIGHT
+
+Copyright 2008-2009 Best Practical Solutions.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm	Mon May 18 09:43:55 2009
@@ -3,7 +3,9 @@
 use Moose;
 use Params::Validate qw(:all);
 with 'Net::Google::Code::Role::Fetchable', 'Net::Google::Code::Role::URL',
-  'Net::Google::Code::Role::HTMLTree', 'Net::Google::Code::Role::Authentication';
+  'Net::Google::Code::Role::HTMLTree',
+  'Net::Google::Code::Role::Authentication',
+  'Net::Google::Code::Role::DateTime';
 
 has 'project' => (
     isa      => 'Str',

Modified: Net-Google-Code/trunk/t/03.comment.t
==============================================================================
--- Net-Google-Code/trunk/t/03.comment.t	(original)
+++ Net-Google-Code/trunk/t/03.comment.t	Mon May 18 09:43:55 2009
@@ -24,7 +24,7 @@
 my %info = (
     sequence => 18,
     author   => 'jsykari',
-    date     => 'Wed Sep  3 04:44:39 2008',
+    date     => '2008-09-03T04:44:39',
     content  => "haha\n",
 );
 



More information about the Bps-public-commit mailing list