[Bps-public-commit] r19627 - in Net-Google-Code/trunk: lib/Net/Google/Code lib/Net/Google/Code/Issue lib/Net/Google/Code/Wiki
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Tue May 12 03:15:30 EDT 2009
Author: sunnavy
Date: Tue May 12 03:15:29 2009
New Revision: 19627
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/lib/Net/Google/Code/Wiki/Comment.pm
Net-Google-Code/trunk/t/04.attachment.t
Log:
refactor parse method of comment and attachment: make it accept html segment
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 May 12 03:15:29 2009
@@ -79,7 +79,7 @@
Net::Google::Code::Issue::Attachment->new(
project => $self->project );
- if ( $a->parse( $tr1, $tr2 ) ) {
+ if ( $a->parse( [$tr1, $tr2] ) ) {
push @{ $self->attachments }, $a;
}
}
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 May 12 03:15:29 2009
@@ -1,6 +1,7 @@
package Net::Google::Code::Issue::Attachment;
use Moose;
with 'Net::Google::Code::Role';
+use Scalar::Util qw/blessed/;
has name => ( isa => 'Str', is => 'rw' );
has url => ( isa => 'Str', is => 'rw' );
@@ -8,8 +9,23 @@
sub parse {
my $self = shift;
- my $tr1 = shift;
- my $tr2 = shift;
+ my $html = shift;
+
+ my ( $tr1, $tr2 );
+
+ if ( blessed $html ) {
+ ( $tr1, $tr2 ) = $html->find_by_tag_name( 'tr' );
+ }
+ elsif ( ref $html eq 'ARRAY' ) {
+ ( $tr1, $tr2 ) = @$html;
+ }
+ else {
+ require HTML::TreeBuilder;
+ my $tree = HTML::TreeBuilder->new;
+ $tree->parse_content( $html );
+ $tree->elementify;
+ ( $tr1, $tr2 ) = $tree->find_by_tag_name( 'tr' );
+ }
my $b = $tr1->find_by_tag_name('b'); # name lives here
if ($b) {
@@ -56,7 +72,7 @@
=over 4
-=item parse( tr1, tr2 )
+=item parse( HTML::Element or [ HTML::Element, HTML::Element ] or html segment string )
there're 2 trs that represent an attachment like the following:
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 May 12 03:15:29 2009
@@ -15,7 +15,19 @@
sub parse {
my $self = shift;
- my $element = 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 $author = $element->look_down( class => 'author' );
my @a = $author->find_by_tag_name('a');
$self->sequence( $a[0]->content_array_ref->[0] );
@@ -89,7 +101,7 @@
Net::Google::Code::Issue::Attachment->new(
project => $self->project );
- if ( $a->parse( $tr1, $tr2 ) ) {
+ if ( $a->parse( [ $tr1, $tr2 ] ) ) {
push @{ $self->attachments }, $a;
}
}
@@ -114,7 +126,7 @@
=over 4
-=item parse( element )
+=item parse( HTML::Element or html segment string )
parse format like the following:
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 Tue May 12 03:15:29 2009
@@ -20,7 +20,18 @@
sub parse {
my $self = shift;
- my $element = 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 $author =
$element->look_down( class => 'author' )->find_by_tag_name('a')->as_text;
@@ -31,6 +42,7 @@
$self->author( $author ) if $author;
$self->date( $date ) if $date;
$self->content( $content ) if $content;
+ return 1;
}
@@ -48,7 +60,7 @@
=over 4
-=item parse( element )
+=item parse( HTML::Element or html segment string )
=back
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 May 12 03:15:29 2009
@@ -21,7 +21,7 @@
my @tr = $tree->find_by_tag_name('tr');
is( scalar @tr, 2, '@tr has 2 elements' );
-$attachment->parse( @tr );
+$attachment->parse( $content );
my %info = (
url =>
More information about the Bps-public-commit
mailing list