[Bps-public-commit] r18293 - in Net-Google-Code/branches/write: . lib/Net/Google/Code
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Mon Feb 9 06:56:16 EST 2009
Author: sunnavy
Date: Mon Feb 9 06:56:07 2009
New Revision: 18293
Modified:
Net-Google-Code/branches/write/ (props changed)
Net-Google-Code/branches/write/lib/Net/Google/Code/Downloads.pm
Net-Google-Code/branches/write/lib/Net/Google/Code/Home.pm
Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm
Net-Google-Code/branches/write/lib/Net/Google/Code/Role/HTMLTree.pm
Net-Google-Code/branches/write/lib/Net/Google/Code/WikiEntry.pm
Log:
r19707 at sunnavys-mb: sunnavy | 2009-02-09 17:43:23 +0800
it is better to let html_tree parse content
Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/Downloads.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Downloads.pm (original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Downloads.pm Mon Feb 9 06:56:07 2009
@@ -44,9 +44,7 @@
my $content =
$self->fetch( $self->base_url . "downloads/detail?name=$filename" );
- my $tree = $self->html_tree;
- $tree->parse_content($content);
- $tree->elementify;
+ my $tree = $self->html_tree( content => $content );
my $entry;
($entry->{upload_time}) = $tree->look_down(class => 'date')->attr('title');
Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/Home.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Home.pm (original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Home.pm Mon Feb 9 06:56:07 2009
@@ -26,9 +26,7 @@
my $html = $self->__html;
- my $tree = $self->html_tree;
- $tree->parse_content($html);
- $tree->elementify;
+ my $tree = $self->html_tree( content => $html );
return $tree;
},
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 Mon Feb 9 06:56:07 2009
@@ -48,9 +48,7 @@
my $self = shift;
my $content = shift;
- my $tree = $self->html_tree;
- $tree->parse_content($content);
- $tree->elementify;
+ my $tree = $self->html_tree( content => $content );
# extract summary
my ($summary) = $tree->look_down( class => 'h3' );
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 Mon Feb 9 06:56:07 2009
@@ -1,19 +1,18 @@
package Net::Google::Code::Role::HTMLTree;
use Moose::Role;
-use HTML::TreeBuilder;
-
with 'Net::Google::Code::Role::Connectable';
use HTML::TreeBuilder;
use Params::Validate qw(:all);
-has 'html_tree' => (
- isa => 'HTML::TreeBuilder',
- is => 'rw',
- default => sub {
- return HTML::TreeBuilder->new;
- },
-);
+sub html_tree {
+ my $self = shift;
+ my %args = validate( @_, { content => { type => SCALAR, optional => 1 } } );
+ my $tree = HTML::TreeBuilder->new;
+ $tree->parse_content($args{content} || $self->mech->content);
+ $tree->elementify;
+ return $tree;
+}
sub html_contains {
my $self = shift;
@@ -28,8 +27,6 @@
);
my $tree = $self->html_tree;
- $tree = $tree->parse( $self->mech->content );
- $tree->elementify;
my $part = $tree;
if ( $args{look_down} ) {
($part) = $tree->look_down( @{ $args{look_down} } );
@@ -60,6 +57,9 @@
=head1 INTERFACE
+=head2 html_tree
+
+return a new HTML::TreeBuilder object, with current content parsed
=head2 html_contains
Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/WikiEntry.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/WikiEntry.pm (original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/WikiEntry.pm Mon Feb 9 06:56:07 2009
@@ -39,9 +39,7 @@
my $html = $self->__html;
- my $tree = $self->html_tree;
- $tree->parse_content($html);
- $tree->elementify;
+ my $tree = $self->html_tree( content => $html );
return $tree;
},
More information about the Bps-public-commit
mailing list