[Bps-public-commit] r19848 - in Net-Google-Code/trunk: lib/Net/Google/Code lib/Net/Google/Code/Issue

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Jun 2 22:46:15 EDT 2009


Author: sunnavy
Date: Tue Jun  2 22:46:15 2009
New Revision: 19848

Modified:
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Attachment.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Comment.pm
   Net-Google-Code/trunk/t/04.attachment.t

Log:
no load method for Attachment, the content is deferred

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	Tue Jun  2 22:46:15 2009
@@ -118,7 +118,6 @@
     @attachments =
       Net::Google::Code::Issue::Attachment->parse_attachments($att_tag)
       if $att_tag;
-    $_->load() for @attachments;
     $self->attachments( \@attachments );
 
     my ($meta) = $tree->look_down( id => 'issuemeta' );

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Attachment.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Attachment.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Attachment.pm	Tue Jun  2 22:46:15 2009
@@ -9,8 +9,19 @@
 has 'url'          => ( isa => 'Str', is => 'rw' );
 has 'size'         => ( isa => 'Str', is => 'rw' );
 has 'id'           => ( isa => 'Int', is => 'rw' );
-has 'content'      => ( isa => 'Str', is => 'rw' );
-has 'content_type' => ( isa => 'Str', is => 'rw' );
+has content => (
+    isa     => 'Str',
+    is      => 'rw',
+    lazy    => 1,
+    default => sub { ($_[0]->_load)[0] },
+);
+
+has content_type => (
+    isa     => 'Str',
+    is      => 'rw',
+    lazy    => 1,
+    default => sub { ($_[0]->_load)[1] },
+);
 
 sub parse {
     my $self = shift;
@@ -38,9 +49,9 @@
 
         # google code doesn't parse download's content type at all, we need to
         # figure it out by ourselves
-        my $mime_type = MIME::Types->new->mimeTypeOf( $self->name );
-        if ($mime_type) {
-            $self->content_type( $mime_type->type );
+        my $content_type = $self->_mime_type;
+        if ( $content_type ) {
+            $self->content_type( $content_type );
         }
     }
 
@@ -80,16 +91,24 @@
     return @attachments;
 }
 
-sub load {
+sub _load {
     my $self    = shift;
     my $content = $self->fetch( $self->url );
-    $self->content($content);
-
-    return 1 if $self->content_type;
 
     # in case MIME::Types failed to get, let File::MMagic rescue!
-    my $content_type = File::MMagic->new->checktype_contents($content);
-    $self->content_type( $content_type || 'application/octet-stream' );
+    my $content_type =
+         $self->_mime_type
+      || File::MMagic->new->checktype_contents($content)
+      || 'application/octet-stream';
+    $self->content( $content );
+    $self->content_type( $content_type );
+    return $content, $content_type;
+}
+
+sub _mime_type {
+    my $self      = shift;
+    my $mime_type = MIME::Types->new->mimeTypeOf( $self->name );
+    return $mime_type ? $mime_type->type : undef;
 }
 
 no Any::Moose;
@@ -138,8 +157,6 @@
 
 =item id
 
-=item load
-
 =item content
 
 =item content_type

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	Tue Jun  2 22:46:15 2009
@@ -72,7 +72,6 @@
     @attachments =
       Net::Google::Code::Issue::Attachment->parse_attachments($att_tag)
       if $att_tag;
-    $_->load() for @attachments;
     $self->attachments( \@attachments );
 
     return 1;

Modified: Net-Google-Code/trunk/t/04.attachment.t
==============================================================================
--- Net-Google-Code/trunk/t/04.attachment.t	(original)
+++ Net-Google-Code/trunk/t/04.attachment.t	Tue Jun  2 22:46:15 2009
@@ -29,7 +29,6 @@
 my @tr = $tree->find_by_tag_name('tr');
 is( scalar @tr, 2, '@tr has 2 elements' );
 $attachment->parse( $content );
-$attachment->load;
 
 my %info = (
     url =>



More information about the Bps-public-commit mailing list