[Bps-public-commit] r19655 - in Net-Google-Code/branches/write/lib/Net/Google/Code: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed May 13 23:40:58 EDT 2009


Author: sunnavy
Date: Wed May 13 23:40:57 2009
New Revision: 19655

Modified:
   Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm
   Net-Google-Code/branches/write/lib/Net/Google/Code/Role/HTMLTree.pm

Log:
refactor HTMLTree role: no fetchable role for it, no html attribute either

Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm	(original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm	Wed May 13 23:40:57 2009
@@ -39,15 +39,16 @@
     my $self = shift;
     my ($id) = validate_pos( @_, { type => SCALAR } );
     $self->state->{id} = $id;
-    $self->html( $self->fetch( $self->base_url . "issues/detail?id=" . $id ) );
-    $self->parse;
+    my $content = $self->fetch( $self->base_url . "issues/detail?id=" . $id );
+    $self->parse( $content );
     return $id;
 }
 
 sub parse {
     my $self    = shift;
+    my $content = shift;
 
-    my $tree = $self->html_tree( content => $self->html );
+    my $tree = $self->html_tree( content => $content );
 
     # extract summary
     my ($summary) = $tree->look_down( class => 'h3' );
@@ -173,7 +174,8 @@
         }
     );
 
-    my ( $contains, $id ) = $self->html_contains(
+    my ( $contains, $id ) = $self->html_tree_contains(
+        html      => $self->mech->content,
         look_down => [ class => 'notice' ],
         as_text   => qr/Issue\s+(\d+)/i,
     );
@@ -232,7 +234,8 @@
     );
 
     if (
-        $self->html_contains(
+        $self->html_tree_contains(
+            html      => $self->mech->content,
             look_down => [ class => 'notice' ],
             as_text   => qr/has been updated/,
         )

Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/Role/HTMLTree.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Role/HTMLTree.pm	(original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Role/HTMLTree.pm	Wed May 13 23:40:57 2009
@@ -1,29 +1,25 @@
 package Net::Google::Code::Role::HTMLTree;
 use Moose::Role;
-with 'Net::Google::Code::Role::Fetchable';
 
 use HTML::TreeBuilder;
 use Params::Validate qw(:all);
-
-has 'html' => (
-    isa => 'Str',
-    is  => 'rw',
-);
+use Scalar::Util qw/blessed/;
 
 sub html_tree {
     my $self = shift;
-    my %args = validate( @_, { content => { type => SCALAR, optional => 1 } } );
+    my %args = validate( @_, { content => { type => SCALAR } } );
     my $tree = HTML::TreeBuilder->new;
-    $tree->parse_content($args{content} || $self->mech->content);
+    $tree->parse_content($args{content});
     $tree->elementify;
     return $tree;
 }
 
-sub html_contains {
+sub html_tree_contains {
     my $self = shift;
     my %args = validate(
         @_,
         {
+            html => { type => SCALAR },
             look_down => { type => ARRAYREF, optional => 1 },
 
             # SCALARREF is for the regex
@@ -31,7 +27,17 @@
         }
     );
 
-    my $tree = $self->html_tree;
+    my $tree;
+
+    if ( blessed $args{html} ) {
+        $tree = $args{html};
+    }
+    else {
+        $tree = HTML::TreeBuilder->new;
+        $tree->parse_content( $args{html} );
+        $tree->elementify;
+    }
+
     my $part = $tree;
     if ( $args{look_down} ) {
         ($part) = $tree->look_down( @{ $args{look_down} } );



More information about the Bps-public-commit mailing list