[Bps-public-commit] r19656 - in Net-Google-Code/branches/write: . lib/Net/Google/Code lib/Net/Google/Code/Issue
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Thu May 14 00:15:03 EDT 2009
Author: sunnavy
Date: Thu May 14 00:15:03 2009
New Revision: 19656
Modified:
Net-Google-Code/branches/write/ (props changed)
Net-Google-Code/branches/write/lib/Net/Google/Code/Download.pm
Net-Google-Code/branches/write/lib/Net/Google/Code/Issue.pm
Net-Google-Code/branches/write/lib/Net/Google/Code/Issue/Attachment.pm
Net-Google-Code/branches/write/lib/Net/Google/Code/Issue/Comment.pm
Net-Google-Code/branches/write/lib/Net/Google/Code/Role/Fetchable.pm
Net-Google-Code/branches/write/lib/Net/Google/Code/Role/URL.pm
Net-Google-Code/branches/write/lib/Net/Google/Code/Wiki.pm
Log:
r21193 at sunnavys-mb (orig r19637): sunnavy | 2009-05-12 17:10:35 +0800
pod fix
r21206 at sunnavys-mb (orig r19650): sunnavy | 2009-05-13 15:09:21 +0800
before actually load, try to check if id or name is set
r21207 at sunnavys-mb (orig r19651): sunnavy | 2009-05-13 16:29:09 +0800
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/branches/write/lib/Net/Google/Code/Download.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Download.pm (original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Download.pm Thu May 14 00:15:03 2009
@@ -48,6 +48,8 @@
sub load {
my $self = shift;
my $name = shift || $self->name;
+ die "current object doesn't have name and load() is not passed a name either"
+ unless $name;
# http://code.google.com/p/net-google-code/downloads/detail?name=Net-Google-Code-0.01.tar.gz
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 Thu May 14 00:15:03 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',
@@ -37,11 +38,12 @@
sub load {
my $self = shift;
- my ($id) = validate_pos( @_, { type => SCALAR } );
- $self->state->{id} = $id;
+ my $id = shift || $self->id;
+ die "current object doesn't have id and load() is not passed an id either"
+ unless $id;
my $content = $self->fetch( $self->base_url . "issues/detail?id=" . $id );
- $self->parse( $content );
- return $id;
+ $self->state->{id} = $id;
+ return $self->parse($content);
}
sub parse {
@@ -65,23 +67,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/branches/write/lib/Net/Google/Code/Issue/Attachment.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Issue/Attachment.pm (original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Issue/Attachment.pm Thu May 14 00:15:03 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/branches/write/lib/Net/Google/Code/Issue/Comment.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Issue/Comment.pm (original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Issue/Comment.pm Thu May 14 00:15:03 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;
Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/Role/Fetchable.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Role/Fetchable.pm (original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Role/Fetchable.pm Thu May 14 00:15:03 2009
@@ -41,7 +41,7 @@
=head1 NAME
-Net::Google::Code::Role::Fetchable -
+Net::Google::Code::Role::Fetchable - Fetchable Role
=head1 DESCRIPTION
Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/Role/URL.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Role/URL.pm (original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Role/URL.pm Thu May 14 00:15:03 2009
@@ -34,7 +34,7 @@
=head1 NAME
-Net::Google::Code::Role::URL -
+Net::Google::Code::Role::URL - URL Role
=head1 DESCRIPTION
Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/Wiki.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Wiki.pm (original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Wiki.pm Thu May 14 00:15:03 2009
@@ -46,6 +46,7 @@
sub load_source {
my $self = shift;
+ die "current object doesn't have name" unless $self->name;
my $source =
$self->fetch( $self->base_svn_url . 'wiki/' . $self->name . '.wiki' );
$self->source($source);
@@ -70,6 +71,8 @@
sub load {
my $self = shift;
my $name = shift || $self->name;
+ die "current object doesn't have name and load() is not passed a name either"
+ unless $name;
# http://code.google.com/p/net-google-code/wiki/TestPage
my $content = $self->fetch( $self->base_url . 'wiki/' . $name );
More information about the Bps-public-commit
mailing list