[Bps-public-commit] r19703 - in Net-Google-Code/trunk/lib/Net/Google: . Code/Issue Code/Role
jesse at bestpractical.com
jesse at bestpractical.com
Fri May 15 23:51:03 EDT 2009
Author: jesse
Date: Fri May 15 23:51:03 2009
New Revision: 19703
Modified:
Net-Google-Code/trunk/lib/Net/Google/Code.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/Role/Fetchable.pm
Log:
Begin the transformation from dates as strings to DateTime objects
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 Fri May 15 23:51:03 2009
@@ -130,6 +130,39 @@
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/Issue.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm (original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm Fri May 15 23:51:03 2009
@@ -44,7 +44,7 @@
);
has 'reported' => (
- isa => 'Str',
+ isa => 'DateTime',
is => 'rw',
);
@@ -100,7 +100,9 @@
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( $author_tag->look_down( class => 'date' )->attr('title') );
+ $self->reported(Net::Google::Code->parse_datetime($author_tag->look_down( class => 'date' )->attr('title') ));
+
+
my $text = $description->find_by_tag_name('pre')->as_text;
$text =~ s/^\s+//;
$text =~ s/\s+$/\n/;
@@ -291,7 +293,6 @@
}
}
-
no Moose;
__PACKAGE__->meta->make_immutable;
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 Fri May 15 23:51:03 2009
@@ -5,7 +5,7 @@
has 'updates' => ( isa => 'HashRef', is => 'rw', default => sub { {} } );
has 'author' => ( isa => 'Str', is => 'rw' );
-has 'date' => ( isa => 'Str', is => 'rw' );
+has 'date' => ( isa => 'DateTime', is => 'rw' );
has 'content' => ( isa => 'Str', is => 'rw' );
has 'sequence' => ( isa => 'Int', is => 'rw' );
has 'attachments' => (
@@ -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( $element->look_down( class => 'date' )->attr('title') );
+ $self->date(Net::Google::Code->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/;
Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Role/Fetchable.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Role/Fetchable.pm (original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/Fetchable.pm Fri May 15 23:51:03 2009
@@ -31,9 +31,10 @@
}
else {
my $content = $self->mech->content;
-# auto decode the content to erase HTML::Parser's utf8 warning like this:
-# Parsing of undecoded UTF-8 will give garbage when decoding entities
- return decode( 'utf8', $content );
+ # auto decode the content to erase HTML::Parser's utf8 warning like this:
+ # Parsing of undecoded UTF-8 will give garbage when decoding entities
+ eval { $content = decode( 'utf8', $content, Encode::FB_QUIET) };
+ return $content;
}
}
More information about the Bps-public-commit
mailing list