[Bps-public-commit] r19651 - in Net-Google-Code/trunk/lib/Net/Google/Code: Issue
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Wed May 13 04:29:09 EDT 2009
Author: sunnavy
Date: Wed May 13 04:29:09 2009
New Revision: 19651
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
Log:
encapsulate attachments parse stuff to Attachment::parse_attachments; also Comment and Attachment does *not* have Net::Google::Code::Role any more
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 Wed May 13 04:29:09 2009
@@ -3,6 +3,7 @@
use Params::Validate qw(:all);
with 'Net::Google::Code::Role';
use Net::Google::Code::Issue::Comment;
+use Net::Google::Code::Issue::Attachment;
has 'state' => (
isa => 'HashRef',
@@ -69,23 +70,9 @@
$text =~ s/\r\n/\n/g;
$self->state->{description} = $text;
- my $att_tags = $tree->look_down( class => 'attachments' );
- my @attachments;
- for my $tag ($att_tags) {
- my @items = $att_tags->find_by_tag_name('tr');
- require Net::Google::Code::Issue::Attachment;
- while ( scalar @items ) {
- my $tr1 = shift @items;
- my $tr2 = shift @items;
- my $a =
- Net::Google::Code::Issue::Attachment->new(
- project => $self->project );
-
- if ( $a->parse( [ $tr1, $tr2 ] ) ) {
- push @attachments, $a;
- }
- }
- }
+ my $att_tag = $tree->look_down( class => 'attachments' );
+ my @attachments =
+ Net::Google::Code::Issue::Attachment::parse_attachments($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 Wed May 13 04:29:09 2009
@@ -1,6 +1,6 @@
package Net::Google::Code::Issue::Attachment;
use Moose;
-with 'Net::Google::Code::Role';
+with 'Net::Google::Code::Role::Fetchable';
use Scalar::Util qw/blessed/;
has 'name' => ( isa => 'Str', is => 'rw' );
@@ -48,6 +48,34 @@
return 1;
}
+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 @attachments;
+
+ my @items = $element->find_by_tag_name('tr');
+ while ( scalar @items ) {
+ my $tr1 = shift @items;
+ my $tr2 = shift @items;
+ my $a = Net::Google::Code::Issue::Attachment->new;
+
+ if ( $a->parse( [ $tr1, $tr2 ] ) ) {
+ push @attachments, $a;
+ }
+ }
+ return @attachments;
+}
+
sub content {
my $self = shift;
return $self->fetch( $self->url );
@@ -66,7 +94,7 @@
=head1 DESCRIPTION
-This class represents a single attachment for an issue.
+This class represents a single attachment for an issue or an issue's comment.
=head1 INTERFACE
@@ -84,6 +112,11 @@
=cut
+=item parse_attachments( HTML::Element or html segment string )
+
+given the <div class="attachments">...</div> or its equivalent HTML::Element
+object, return a list of Net::Google::Code::Attachment objects.
+
=item name
=item content
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 Wed May 13 04:29:09 2009
@@ -1,6 +1,6 @@
package Net::Google::Code::Issue::Comment;
use Moose;
-with 'Net::Google::Code::Role';
+use Net::Google::Code::Issue::Attachment;
has 'updates' => ( isa => 'HashRef', is => 'rw', default => sub { {} } );
has 'author' => ( isa => 'Str', is => 'rw' );
@@ -67,23 +67,10 @@
}
}
- my @att_tags = $element->look_down( class => 'attachments' );
- my @attachments;
- for my $tag (@att_tags) {
- my @items = $tag->find_by_tag_name('tr');
- require Net::Google::Code::Issue::Attachment;
- while ( scalar @items ) {
- my $tr1 = shift @items;
- my $tr2 = shift @items;
- my $a =
- Net::Google::Code::Issue::Attachment->new(
- project => $self->project );
- if ( $a->parse( [ $tr1, $tr2 ] ) ) {
- push @attachments, $a;
- }
- }
- }
+ my $att_tag = $element->look_down( class => 'attachments' );
+ my @attachments =
+ Net::Google::Code::Issue::Attachment::parse_attachments($att_tag);
$self->attachments( \@attachments );
return 1;
More information about the Bps-public-commit
mailing list