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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu May 14 23:35:53 EDT 2009


Author: sunnavy
Date: Thu May 14 23:35:53 2009
New Revision: 19676

Modified:
   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/Attachment.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Comment.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/Fetchable.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/HTMLTree.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Wiki/Comment.pm

Log:
use ->html_tree to get html tree object since we have HTMLTree role

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	Thu May 14 23:35:53 2009
@@ -3,6 +3,7 @@
 use Moose;
 with 'Net::Google::Code::Role::Fetchable', 'Net::Google::Code::Role::URL',
   'Net::Google::Code::Role::Pageable', 'Net::Google::Code::Role::HTMLTree';
+use Scalar::Util qw/blessed/;
 
 our $VERSION = '0.05';
 
@@ -59,11 +60,8 @@
 
 sub parse {
     my $self    = shift;
-    my $content = shift;
-    require HTML::TreeBuilder;
-    my $tree = HTML::TreeBuilder->new;
-    $tree->parse_content($content);
-    $tree->elementify;
+    my $tree    = shift;
+    $tree = $self->html_tree( html => $tree ) unless blessed $tree;
 
     my $summary =
       $tree->look_down( id => 'psum' )->find_by_tag_name('a')->content_array_ref->[0];
@@ -148,13 +146,9 @@
 	my $self = shift;
 	
 	my $wiki_svn = $self->base_svn_url . 'wiki/';
-	my $content = $self->fetch( $wiki_svn );
+    my $content  = $self->fetch( $wiki_svn );
+    my $tree = $self->html_tree( html => $content );
 
-    require HTML::TreeBuilder;
-    my $tree = HTML::TreeBuilder->new;
-    $tree->parse_content($content);
-    $tree->elementify;
-	
     my @wikis;
     my @li = $tree->find_by_tag_name('li');
     for my $li ( @li ) {

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	Thu May 14 23:35:53 2009
@@ -2,6 +2,7 @@
 
 use Moose;
 use Params::Validate qw(:all);
+use Scalar::Util qw/blessed/;
 
 with 'Net::Google::Code::Role::Fetchable', 'Net::Google::Code::Role::URL',
   'Net::Google::Code::Role::HTMLTree';
@@ -68,12 +69,9 @@
 
 sub parse {
     my $self = shift;
-    my $content = shift;
-	require HTML::TreeBuilder;
-    my $tree = HTML::TreeBuilder->new;
-    $tree->parse_content($content);
-    $tree->elementify;
-    
+    my $tree = shift;
+    $tree = $self->html_tree( html => $tree ) unless blessed $tree;
+
     my $entry;
     my $uploaded = $tree->look_down(class => 'date')->attr('title');
     $self->uploaded( $uploaded ) if $uploaded;

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	Thu May 14 23:35:53 2009
@@ -5,6 +5,7 @@
      'Net::Google::Code::Role::HTMLTree';
 use Net::Google::Code::Issue::Comment;
 use Net::Google::Code::Issue::Attachment;
+use Scalar::Util qw/blessed/;
 
 has 'project' => (
     isa      => 'Str',
@@ -54,9 +55,9 @@
 
 sub parse {
     my $self    = shift;
-    my $content = shift;
+    my $tree    = shift;
 
-    my $tree = $self->html_tree( content => $content );
+    $tree = $self->html_tree( html => $tree ) unless blessed $tree;
 
     # extract summary
     my ($summary) = $tree->look_down( class => 'h3' );
@@ -74,8 +75,10 @@
     $self->state->{description} = $text;
 
     my $att_tag = $tree->look_down( class => 'attachments' );
-    my @attachments =
-      Net::Google::Code::Issue::Attachment::parse_attachments($att_tag);
+    my @attachments;
+    @attachments =
+      Net::Google::Code::Issue::Attachment->parse_attachments($att_tag)
+      if $att_tag;
     $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	Thu May 14 23:35:53 2009
@@ -20,10 +20,7 @@
         ( $tr1, $tr2 ) = @$html;
     }
     else {
-        require HTML::TreeBuilder;
-        my $tree = HTML::TreeBuilder->new;
-        $tree->parse_content( $html );
-        $tree->elementify;
+        my $tree = $self->html_tree( html => $html );
         ( $tr1, $tr2 ) = $tree->find_by_tag_name( 'tr' );
     }
 
@@ -49,17 +46,9 @@
 }
 
 sub parse_attachments {
-    my $html = $_[-1]; # in case object call ->
-    my $element;
-    if ( blessed $html ) {
-        $element = $html;
-    }
-    else {
-        require HTML::TreeBuilder;
-        $element = HTML::TreeBuilder->new;
-        $element->parse_content( $html );
-        $element->elementify;
-    }
+    my $self    = shift;
+    my $element = shift;
+    $element = $self->html_tree( html => $element ) unless blessed $element;
 
     my @attachments;
 

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	Thu May 14 23:35:53 2009
@@ -16,18 +16,8 @@
 
 sub parse {
     my $self    = shift;
-    my $html = shift;
-
-    my $element;
-    if ( blessed $html ) {
-        $element = $html;
-    }
-    else {
-        require HTML::TreeBuilder;
-        my $element = HTML::TreeBuilder->new;
-        $element->parse_content( $html );
-        $element->elementify;
-    }
+    my $element = shift;
+    $element = $self->html_tree( html => $element ) unless blessed $element;
 
     my $author  = $element->look_down( class => 'author' );
     my @a       = $author->find_by_tag_name('a');
@@ -70,8 +60,11 @@
     }
 
     my $att_tag = $element->look_down( class => 'attachments' );
-    my @attachments =
-      Net::Google::Code::Issue::Attachment::parse_attachments($att_tag);
+    my @attachments;
+
+    @attachments =
+      Net::Google::Code::Issue::Attachment->parse_attachments($att_tag)
+      if $att_tag;
     $self->attachments( \@attachments );
 
     return 1;

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	Thu May 14 23:35:53 2009
@@ -29,6 +29,7 @@
           . $url;
     }
     else {
+        die 'ok';
         return $self->mech->content;
     }
 }

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Role/HTMLTree.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Role/HTMLTree.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/HTMLTree.pm	Thu May 14 23:35:53 2009
@@ -7,9 +7,9 @@
 
 sub html_tree {
     my $self = shift;
-    my %args = validate( @_, { content => { type => SCALAR } } );
+    my %args = validate( @_, { html => { type => SCALAR } } );
     my $tree = HTML::TreeBuilder->new;
-    $tree->parse_content($args{content});
+    $tree->parse_content($args{html});
     $tree->elementify;
     return $tree;
 }
@@ -19,7 +19,7 @@
     my %args = validate(
         @_,
         {
-            html => { type => SCALAR },
+            html      => { type => SCALAR },
             look_down => { type => ARRAYREF, optional => 1 },
 
             # SCALARREF is for the regex
@@ -33,9 +33,7 @@
         $tree = $args{html};
     }
     else {
-        $tree = HTML::TreeBuilder->new;
-        $tree->parse_content( $args{html} );
-        $tree->elementify;
+        $tree = $self->html_tree( html => $args{html} );
     }
 
     my $part = $tree;

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm	Thu May 14 23:35:53 2009
@@ -2,23 +2,14 @@
 use Moose::Role;
 use Params::Validate ':all';
 use WWW::Mechanize;
-with 'Net::Google::Code::Role::Fetchable';
+with 'Net::Google::Code::Role::Fetchable', 'Net::Google::Code::Role::HTMLTree';
 use Scalar::Util qw/blessed/;
 no Moose::Role;
 
 sub first_columns {
     my $self = shift;
-    my $html = shift;
-    my $tree;
-    if ( blessed $html ) {
-        $tree = $html;
-    }
-    else {
-        require HTML::TreeBuilder;
-        $tree = HTML::TreeBuilder->new;
-        $tree->parse_content($html);
-        $tree->elementify;
-    }
+    my $tree = shift;
+    $tree = $self->html_tree( html => $tree ) unless blessed $tree;
 
     my @columns;
 
@@ -49,17 +40,8 @@
 
 sub _first_columns {
     my $self = shift;
-    my $html = shift;
-    my $tree;
-    if ( blessed $html ) {
-        $tree = $html;
-    }
-    else {
-        require HTML::TreeBuilder;
-        $tree = HTML::TreeBuilder->new;
-        $tree->parse_content($html);
-        $tree->elementify;
-    }
+    my $tree = shift;
+    $tree = $self->html_tree( html => $tree ) unless blessed $tree;
 
     my @columns;
     my @tags = $tree->look_down( class => 'vt id col_0' );

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	Thu May 14 23:35:53 2009
@@ -90,11 +90,9 @@
 
 sub parse {
     my $self    = shift;
-    my $content = shift;
-    require HTML::TreeBuilder;
-    my $tree = HTML::TreeBuilder->new;
-    $tree->parse_content($content);
-    $tree->elementify;
+    my $tree    = shift;
+    $tree = $self->html_tree( html => $tree ) unless blessed $tree;
+
     my $wiki = $tree->look_down( id => 'wikimaincol' );
     my $updated =
       $wiki->find_by_tag_name('td')->find_by_tag_name('span')->attr('title');

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Wiki/Comment.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Wiki/Comment.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Wiki/Comment.pm	Thu May 14 23:35:53 2009
@@ -20,19 +20,10 @@
 );
 
 sub parse {
-    my $self = shift;
-    my $html = shift;
+    my $self    = shift;
+    my $element = shift;
 
-    my $element;
-    if ( blessed $html ) {
-        $element = $html;
-    }
-    else {
-        require HTML::TreeBuilder;
-        my $element = HTML::TreeBuilder->new;
-        $element->parse_content( $html );
-        $element->elementify;
-    }
+    $element = $self->html_tree( html => $element ) unless blessed $element;
 
     my $author =
       $element->look_down( class => 'author' )->find_by_tag_name('a')->as_text;



More information about the Bps-public-commit mailing list