[Bps-public-commit] r18295 - in Net-Google-Code/branches/write: .
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Mon Feb 9 06:57:14 EST 2009
Author: sunnavy
Date: Mon Feb 9 06:56:55 2009
New Revision: 18295
Modified:
Net-Google-Code/branches/write/ (props changed)
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/WikiEntry.pm
Log:
r19709 at sunnavys-mb: sunnavy | 2009-02-09 19:51:12 +0800
refactor code to use more htmltree role
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:55 2009
@@ -7,39 +7,13 @@
with 'Net::Google::Code::Role';
-
-has '__html' => (
- isa => 'Str',
- is => 'ro',
- lazy => 1,
- default => sub {
- my $self = shift;
- return $self->fetch( $self->base_url );
- }
-);
-
-has '__html_tree' => (
- is => 'ro',
- lazy => 1,
- default => sub {
- my $self = shift;
-
- my $html = $self->__html;
-
- my $tree = $self->html_tree( content => $html );
-
- return $tree;
- },
-);
-
has 'owners' => (
isa => 'ArrayRef',
is => 'ro',
lazy => 1,
default => sub {
my $self = shift;
-
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
my @tags = $tree->look_down(id => 'owners')->find_by_tag_name('a');
my @owners;
foreach my $tag ( @tags ) {
@@ -55,7 +29,7 @@
default => sub {
my $self = shift;
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
my @tags = $tree->look_down(id => 'members')->find_by_tag_name('a');
my @members;
foreach my $tag ( @tags ) {
@@ -72,7 +46,7 @@
default => sub {
my $self = shift;
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
return $tree->look_down(id => 'psum')->find_by_tag_name('a')->content_array_ref->[0];
},
);
@@ -83,8 +57,7 @@
lazy => 1,
default => sub {
my $self = shift;
-
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
return $tree->look_down(id => 'wikicontent')->content_array_ref->[0]->as_HTML;
},
);
@@ -96,7 +69,7 @@
default => sub {
my $self = shift;
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
my @tags = $tree->look_down( href => qr/q\=label\:/);
my @labels;
foreach my $tag ( @tags ) {
@@ -106,6 +79,11 @@
},
);
+sub BUILD {
+ my $self = shift;
+ $self->html( $self->fetch( $self->base_url ) );
+}
+
no Moose;
__PACKAGE__->meta->make_immutable;
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:55 2009
@@ -39,16 +39,15 @@
my $self = shift;
my ($id) = validate_pos( @_, { type => SCALAR } );
$self->state->{id} = $id;
- my $content = $self->fetch( "issues/detail?id=" . $id );
- $self->parse($content);
+ $self->html( $self->fetch( "issues/detail?id=" . $id ) );
+ $self->parse;
return $id;
}
sub parse {
my $self = shift;
- my $content = shift;
- my $tree = $self->html_tree( content => $content );
+ my $tree = $self->html_tree( content => $self->html );
# extract summary
my ($summary) = $tree->look_down( class => 'h3' );
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:55 2009
@@ -20,39 +20,13 @@
}
);
-has '__html' => (
+has 'wiki_html' => (
isa => 'Str',
is => 'ro',
lazy => 1,
default => sub {
my $self = shift;
- # http://code.google.com/p/net-google-code/wiki/TestPage
- return $self->fetch( $self->base_url . 'wiki/' . $self->name );
- }
-);
-
-has '__html_tree' => (
- is => 'ro',
- lazy => 1,
- default => sub {
- my $self = shift;
-
- my $html = $self->__html;
-
- my $tree = $self->html_tree( content => $html );
-
- return $tree;
- },
-);
-
-has 'html' => (
- isa => 'Str',
- is => 'ro',
- lazy => 1,
- default => sub {
- my $self = shift;
-
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
my $meta = $tree->look_down(id => 'wikimaincol');
return $tree->content_array_ref->[-1]->as_HTML;
@@ -65,8 +39,7 @@
lazy => 1,
default => sub {
my $self = shift;
-
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
return $tree->look_down(id => 'wikimaincol')->find_by_tag_name('td')
->find_by_tag_name('span')->attr('title');
},
@@ -77,8 +50,7 @@
lazy => 1,
default => sub {
my $self = shift;
-
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
my $href = $tree->look_down(id => 'wikimaincol')->find_by_tag_name('td')
->find_by_tag_name('a')->attr('href');
my ( $author ) = ( $href =~ /u\/(.*?)\// );
@@ -104,7 +76,8 @@
return;
}
# get from the html tree
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
+
my $title = $tree->find_by_tag_name('title')->content_array_ref->[0];
my @parts = split(/\s+\-\s+/, $title, 4);
return $parts[2] if ( scalar @parts == 4 );
@@ -121,7 +94,7 @@
my @rets;
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
my @comments = $tree->look_down( class => 'artifactcomment' );
foreach my $comment ( @comments ) {
my $href = $comment->look_down( class => 'author' )->find_by_tag_name('a')->attr('href');
@@ -162,7 +135,7 @@
return [];
}
# get from the html tree
- my $tree = $self->__html_tree;
+ my $tree = $self->html_tree( content => $self->html );
my @tags = $tree->look_down( href => qr/q\=label\:/);
my @labels;
foreach my $tag ( @tags ) {
@@ -172,6 +145,13 @@
},
);
+sub BUILD {
+ my ( $self, $params ) = @_;
+
+ # http://code.google.com/p/net-google-code/wiki/TestPage
+ $self->html( $self->fetch( $self->base_url . 'wiki/' . $params->{name} ) );
+}
+
no Moose;
__PACKAGE__->meta->make_immutable;
@@ -227,6 +207,7 @@
wiki entry comments
+
=back
=head1 AUTHOR
More information about the Bps-public-commit
mailing list