[Bps-public-commit] r19620 - in Net-Google-Code/trunk: . lib/Net/Google lib/Net/Google/Code
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Mon May 11 10:36:28 EDT 2009
Author: sunnavy
Date: Mon May 11 10:36:26 2009
New Revision: 19620
Removed:
Net-Google-Code/trunk/lib/Net/Google/Code/Home.pm
Modified:
Net-Google-Code/trunk/MANIFEST
Net-Google-Code/trunk/lib/Net/Google/Code.pm
Net-Google-Code/trunk/t/20.code.t
Log:
move Home part to Code
Modified: Net-Google-Code/trunk/MANIFEST
==============================================================================
--- Net-Google-Code/trunk/MANIFEST (original)
+++ Net-Google-Code/trunk/MANIFEST Mon May 11 10:36:26 2009
@@ -14,7 +14,6 @@
inc/Module/Install/WriteAll.pm
lib/Net/Google/Code.pm
lib/Net/Google/Code/Downloads.pm
-lib/Net/Google/Code/Home.pm
lib/Net/Google/Code/Issue.pm
lib/Net/Google/Code/Issue/Attachment.pm
lib/Net/Google/Code/Issue/Comment.pm
Modified: Net-Google-Code/trunk/lib/Net/Google/Code.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code.pm (original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code.pm Mon May 11 10:36:26 2009
@@ -5,47 +5,118 @@
our $VERSION = '0.03';
-has 'home' => (
- isa => 'Net::Google::Code::Home',
- is => 'ro',
- lazy => 1,
- default => sub {
- require Net::Google::Code::Home;
- Net::Google::Code::Home->new( project => $_[0]->project );
- },
- handles => [ 'owners', 'members', 'summary', 'description', 'labels' ],
+has 'labels' => (
+ isa => 'ArrayRef',
+ is => 'rw',
);
-has 'issue' => (
- isa => 'Net::Google::Code::Issue',
- is => 'ro',
- lazy => 1,
- default => sub {
- require Net::Google::Code::Issue;
- Net::Google::Code::Issue->new( project => $_[0]->project );
- }
+has 'owners' => (
+ isa => 'ArrayRef',
+ is => 'rw',
);
-has 'downloads' => (
- isa => 'Net::Google::Code::Downloads',
- is => 'ro',
- lazy => 1,
- default => sub {
- require Net::Google::Code::Downloads;
- Net::Google::Code::Downloads->new( project => $_[0]->project );
- }
+has 'members' => (
+ isa => 'ArrayRef',
+ is => 'rw',
);
-has 'wiki' => (
- isa => 'Net::Google::Code::Wiki',
- is => 'ro',
- lazy => 1,
- default => sub {
- require Net::Google::Code::Wiki;
- Net::Google::Code::Wiki->new( project => $_[0]->project );
- }
+has 'summary' => (
+ isa => 'Str',
+ is => 'rw',
);
+has 'description' => (
+ isa => 'Str',
+ is => 'rw',
+);
+
+=head2 load
+
+load project's home page, and parse its metadata
+
+=cut
+
+sub load {
+ my $self = shift;
+ my $content = $self->fetch( $self->base_url );
+ return $self->parse( $content );
+}
+
+=head2 parse
+
+acturally do the parse job, for load();
+
+=cut
+
+sub parse {
+ my $self = shift;
+ my $content = shift;
+ require HTML::TreeBuilder;
+ my $tree = HTML::TreeBuilder->new;
+ $tree->parse_content($content);
+ $tree->elementify;
+
+ my $summary =
+ $tree->look_down( id => 'psum' )->find_by_tag_name('a')->content_array_ref->[0];
+ $self->summary($summary) if $summary;
+
+ my $description =
+ $tree->look_down( id => 'wikicontent' )->content_array_ref->[0]->as_text;
+ $self->description($description) if $description;
+
+ my @members;
+ my @members_tags =
+ $tree->look_down( id => 'members' )->find_by_tag_name('a');
+ for my $tag (@members_tags) {
+ push @members, $tag->content_array_ref->[0];
+ }
+ $self->members( \@members ) if @members;
+
+ my @owners;
+ my @owners_tags = $tree->look_down( id => 'owners' )->find_by_tag_name('a');
+ for my $tag (@owners_tags) {
+ push @owners, $tag->content_array_ref->[0];
+ }
+ $self->owners( \@owners ) if @owners;
+
+ my @labels;
+ my @labels_tags = $tree->look_down( href => qr/q\=label\:/ );
+ for my $tag (@labels_tags) {
+ push @labels, $tag->content_array_ref->[0];
+ }
+ $self->labels( \@labels ) if @labels;
+
+}
+
+sub issue {
+ my $self = shift;
+ require Net::Google::Code::Issue;
+ return Net::Google::Code::Issue->new(
+ project => $self->project,
+ @_
+ );
+}
+
+sub downloads {
+
+ my $self = shift;
+ require Net::Google::Code::Downloads;
+ return Net::Google::Code::Downloads->new(
+ project => $self->project,
+ @_
+ );
+}
+
+sub wiki {
+
+ my $self = shift;
+ require Net::Google::Code::Wiki;
+ return Net::Google::Code::Wiki->new(
+ project => $self->project,
+ @_
+ );
+}
+
no Moose;
__PACKAGE__->meta->make_immutable;
@@ -61,6 +132,7 @@
use Net::Google::Code;
my $project = Net::Google::Code->new( project => 'net-google-code' );
+ $project->load; # load its metadata, e.g. summary, owners, members, etc.
print join(', ', @{ $project->owners } );
Modified: Net-Google-Code/trunk/t/20.code.t
==============================================================================
--- Net-Google-Code/trunk/t/20.code.t (original)
+++ Net-Google-Code/trunk/t/20.code.t Mon May 11 10:36:26 2009
@@ -12,7 +12,7 @@
my $homepage_file = "$Bin/sample/20.code.html";
my $homepage_content = read_file($homepage_file);
-my $mock = Test::MockModule->new('Net::Google::Code::Home');
+my $mock = Test::MockModule->new('Net::Google::Code');
$mock->mock(
'fetch',
sub {
@@ -29,6 +29,8 @@
is( $project->base_url, "http://code.google.com/p/$name/", 'default url' );
is( $project->base_svn_url, "http://$name.googlecode.com/svn/", 'svn url' );
is( $project->project, $name, 'project name' );
+
+$project->load;
is_deeply( $project->owners, [ 'sunnavy' ] );
is_deeply( $project->members, [ 'jessev', 'fayland' ] );
like $project->description, qr/Net\:\:Google\:\:Code/;
More information about the Bps-public-commit
mailing list