[Bps-public-commit] r19625 - in Net-Google-Code/trunk: . lib/Net/Google lib/Net/Google/Code lib/Net/Google/Code/Wiki t/sample
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Tue May 12 01:24:03 EDT 2009
Author: sunnavy
Date: Tue May 12 01:24:03 2009
New Revision: 19625
Added:
Net-Google-Code/trunk/lib/Net/Google/Code/Wiki/
Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm
Net-Google-Code/trunk/lib/Net/Google/Code/Wiki/Comment.pm
Net-Google-Code/trunk/t/sample/11.TestPage.html
- copied unchanged from r17804, /Net-Google-Code/trunk/t/sample/11.wiki.TestPage.html
Net-Google-Code/trunk/t/sample/11.wikis.html
Removed:
Net-Google-Code/trunk/t/sample/11.TODO.wiki
Net-Google-Code/trunk/t/sample/11.wiki.TestPage.html
Net-Google-Code/trunk/t/sample/11.wiki.html
Modified:
Net-Google-Code/trunk/MANIFEST
Net-Google-Code/trunk/lib/Net/Google/Code.pm
Net-Google-Code/trunk/t/11.wiki.t
Net-Google-Code/trunk/t/20.code.t
Log:
refactor Wiki part:
Wiki.pm now represents a wiki page
use Net::Google::Code::load_wikis to load all the wikis
added Wiki/Comment.pm to represent a wiki comment
Modified: Net-Google-Code/trunk/MANIFEST
==============================================================================
--- Net-Google-Code/trunk/MANIFEST (original)
+++ Net-Google-Code/trunk/MANIFEST Tue May 12 01:24:03 2009
@@ -23,7 +23,7 @@
lib/Net/Google/Code/Role/Fetchable.pm
lib/Net/Google/Code/Role/URL.pm
lib/Net/Google/Code/Wiki.pm
-lib/Net/Google/Code/WikiEntry.pm
+lib/Net/Google/Code/Wiki/Comment.pm
Makefile.PL
MANIFEST This list of files
META.yml
@@ -38,10 +38,9 @@
t/sample/02.issue.html
t/sample/10.download.html
t/sample/10.downloads.xml
+t/sample/11.TestPage.html
t/sample/11.TestPage.wiki
-t/sample/11.TODO.wiki
-t/sample/11.wiki.html
-t/sample/11.wiki.TestPage.html
+t/sample/11.wikis.html
t/sample/20.code.html
xt/kwalitee.t
xt/perlcritic.t
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 Tue May 12 01:24:03 2009
@@ -40,6 +40,11 @@
is => 'rw',
);
+has 'wikis' => (
+ isa => 'ArrayRef[Net::Google::Code::Wiki]',
+ is => 'rw',
+);
+
=head2 load
load project's home page, and parse its metadata
@@ -157,6 +162,41 @@
);
}
+=head2 load_wikis
+
+load all the wikis
+
+=cut
+
+sub load_wikis {
+ my $self = shift;
+
+ my $wiki_svn = $self->base_svn_url . 'wiki/';
+ my $content = $self->fetch( $wiki_svn );
+
+ require HTML::TreeBuilder;
+ my $tree = HTML::TreeBuilder->new;
+ $tree->parse_content($content);
+ $tree->elementify;
+
+ my @wikis;
+ my @li = $tree->find_by_tag_name('li');
+ for my $li ( @li ) {
+ my $name = $li->as_text;
+ if ( $name =~ /(\S+)\.wiki$/ ) {
+ $name = $1;
+ require Net::Google::Code::Wiki;
+ my $wiki = Net::Google::Code::Wiki->new(
+ project => $self->project,
+ name => $name,
+ );
+ $wiki->load;
+ push @wikis, $wiki;
+ }
+ }
+ $self->wikis( \@wikis );
+}
+
no Moose;
__PACKAGE__->meta->make_immutable;
Added: Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm Tue May 12 01:24:03 2009
@@ -0,0 +1,163 @@
+package Net::Google::Code::Wiki;
+
+use Moose;
+use Params::Validate qw(:all);
+with 'Net::Google::Code::Role';
+
+has 'name' => (
+ isa => 'Str',
+ is => 'rw',
+);
+
+has 'source' => (
+ isa => 'Str',
+ is => 'rw',
+);
+
+has 'content' => (
+ isa => 'Str',
+ is => 'rw',
+);
+
+has 'updated' => (
+ isa => 'Str',
+ is => 'rw',
+);
+has 'updated_by' => (
+ isa => 'Str',
+ is => 'rw',
+);
+has 'labels' => (
+ isa => 'ArrayRef[Str]',
+ is => 'rw',
+);
+has 'summary' => (
+ isa => 'Str',
+ is => 'rw',
+);
+has 'comments' => (
+ isa => 'ArrayRef[Net::Google::Code::Wiki::Comment]',
+ is => 'rw',
+);
+
+sub load_source {
+ my $self = shift;
+ my $source =
+ $self->fetch( $self->base_svn_url . 'wiki/' . $self->name . '.wiki' );
+ $self->source($source);
+ return $self->parse_source;
+}
+
+sub parse_source {
+ my $self = shift;
+ my @meta = grep { /^#/ } split /\n/, $self->source;
+ for my $meta (@meta) {
+ chomp $meta;
+ if ( $meta =~ /summary\s+(.*)/ ) {
+ $self->summary($1);
+ }
+ elsif ( $meta =~ /labels\s+(.*)/ ) {
+ my @labels = split /,\s*/, $1;
+ $self->labels( \@labels );
+ }
+ }
+}
+
+sub load {
+ my $self = shift;
+ my $name = shift || $self->name;
+
+ # http://code.google.com/p/net-google-code/wiki/TestPage
+ my $content = $self->fetch( $self->base_url . 'wiki/' . $name );
+
+ $self->name($name) unless $self->name && $self->name eq $name;
+ $self->load_source;
+ return $self->parse($content);
+}
+
+sub parse {
+ my $self = shift;
+ my $content = shift;
+ require HTML::TreeBuilder;
+ my $tree = HTML::TreeBuilder->new;
+ $tree->parse_content($content);
+ $tree->elementify;
+ my $wiki = $tree->look_down( id => 'wikimaincol' );
+ my $updated =
+ $wiki->find_by_tag_name('td')->find_by_tag_name('span')->attr('title');
+ my $updated_by =
+ $wiki->find_by_tag_name('td')->find_by_tag_name('a')->as_text;
+ $self->updated($updated) if $updated;
+ $self->updated_by($updated_by) if $updated_by;
+
+ $self->content( $tree->content_array_ref->[-1]->as_HTML );
+
+ my @comments = ();
+ my @comments_element = $tree->look_down( class => 'artifactcomment' );
+ for my $element (@comments_element) {
+ require Net::Google::Code::Wiki::Comment;
+ my $comment = Net::Google::Code::Wiki::Comment->new;
+ $comment->parse($element);
+ push @comments, $comment;
+ }
+ $self->comments( \@comments );
+}
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
+
+1;
+__END__
+
+=head1 NAME
+
+Net::Google::Code::Wiki - Google Code Wiki
+
+=head1 SYNOPSIS
+
+ use Net::Google::Code::Wiki;
+
+ my $wiki = Net::Google::Code::Wiki->new(
+ project => 'net-google-code',
+ name => 'TestPage',
+ );
+
+ $wiki_entry->source;
+
+=head1 INTERFACE
+
+=head2 load
+
+=head2 parse
+
+=head2 load_source
+
+=head2 parse_source
+
+=head2 name
+
+=head2 source
+
+=head2 summary
+
+=head2 labels
+
+=head2 content
+
+=head2 updated_by
+
+=head2 updated
+
+=head2 comments
+
+=head1 AUTHOR
+
+sunnavy C<< <sunnavy at bestpractical.com> >>
+
+=head1 LICENCE AND COPYRIGHT
+
+Copyright 2008-2009 Best Practical Solutions.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
Added: Net-Google-Code/trunk/lib/Net/Google/Code/Wiki/Comment.pm
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Wiki/Comment.pm Tue May 12 01:24:03 2009
@@ -0,0 +1,61 @@
+package Net::Google::Code::Wiki::Comment;
+
+use Moose;
+use Params::Validate qw(:all);
+
+has 'content' => (
+ isa => 'Str',
+ is => 'rw',
+);
+
+has 'author' => (
+ isa => 'Str',
+ is => 'rw',
+);
+
+has 'date' => (
+ isa => 'Str',
+ is => 'rw',
+);
+
+sub parse {
+ my $self = shift;
+ my $element = shift;
+
+ my $author =
+ $element->look_down( class => 'author' )->find_by_tag_name('a')->as_text;
+ my $date = $element->look_down( class => 'date' )->attr('title');
+ my $content = $element->look_down( class => 'commentcontent' )->as_text;
+ $content =~ s/\s+$//; # remove trailing spaces
+
+ $self->author( $author ) if $author;
+ $self->date( $date ) if $date;
+ $self->content( $content ) if $content;
+}
+
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
+
+1;
+__END__
+
+=head1 NAME
+
+Net::Google::Code::Wiki::Comment - Google Code Wiki Comment
+
+=head1 INTERFACE
+
+=head2 parse
+
+=head1 AUTHOR
+
+sunnavy C<< <sunnavy at bestpractical.com> >>
+
+=head1 LICENCE AND COPYRIGHT
+
+Copyright 2008-2009 Best Practical Solutions.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
Modified: Net-Google-Code/trunk/t/11.wiki.t
==============================================================================
--- Net-Google-Code/trunk/t/11.wiki.t (original)
+++ Net-Google-Code/trunk/t/11.wiki.t Tue May 12 01:24:03 2009
@@ -3,82 +3,66 @@
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 15;
use Test::MockModule;
use FindBin qw/$Bin/;
use File::Slurp;
use Net::Google::Code;
-my $svn_file = "$Bin/sample/11.wiki.html";
-my $wiki_file = "$Bin/sample/11.TODO.wiki";
-my $wiki_file2 = "$Bin/sample/11.TestPage.wiki";
-my $entry_file = "$Bin/sample/11.wiki.TestPage.html";
-my $svn_content = read_file($svn_file);
-my $wiki_content = read_file($wiki_file);
-my $wiki_content2 = read_file($wiki_file2);
-my $entry_content = read_file($entry_file);
+my $svn_file = "$Bin/sample/11.TestPage.wiki";
+my $svn_content = read_file( $svn_file );
+my $wiki_file = "$Bin/sample/11.TestPage.html";
use Net::Google::Code::Wiki;
-my $mock_sub = sub {
- ( undef, my $uri ) = @_;
- if ( $uri eq 'http://foorum.googlecode.com/svn/wiki/' ) {
- return $svn_content;
- } elsif ( $uri eq 'http://foorum.googlecode.com/svn/wiki/TODO.wiki' ) {
- return $wiki_content;
- } elsif ( $uri eq 'http://code.google.com/p/foorum/wiki/TestPage' ) {
- return $entry_content;
- } elsif ( $uri eq 'http://foorum.googlecode.com/svn/wiki/TestPage.wiki' ) {
- return $wiki_content2;
- }
-};
-
my $mock_wiki = Test::MockModule->new('Net::Google::Code::Wiki');
-$mock_wiki->mock( 'fetch', $mock_sub );
+$mock_wiki->mock(
+ 'fetch',
+ sub {
+ shift;
+ my $url = shift;
+ if ( $url =~ /svn/ ) {
+ $svn_content;
+ }
+ else {
+ read_file($wiki_file);
+ }
+ }
+);
-my $mock_wiki_entry = Test::MockModule->new('Net::Google::Code::WikiEntry');
-$mock_wiki_entry->mock( 'fetch', $mock_sub );
+my $wiki = Net::Google::Code::Wiki->new(
+ project => 'net-google-code',
+ name => 'TestPage',
+);
-my $wiki = Net::Google::Code::Wiki->new( project => 'foorum' );
isa_ok( $wiki, 'Net::Google::Code::Wiki' );
-
-my @entries = $wiki->all_entries;
-is( scalar @entries, 16 );
-is $entries[0], 'AUTHORS';
-is_deeply(\@entries, ['AUTHORS', 'Configure', 'HowRSS', 'I18N', 'INSTALL', 'PreRelease',
- 'README', 'RULES', 'TODO', 'TroubleShooting', 'Tutorial1', 'Tutorial2', 'Tutorial3',
- 'Tutorial4', 'Tutorial5', 'Upgrade' ]);
-
-my $entry = $wiki->entry('TODO');
-isa_ok( $entry, 'Net::Google::Code::WikiEntry' );
+is( $wiki->name, 'TestPage', 'name' );
+$wiki->load;
# test source
-is $entry->source, $wiki_content;
-is $entry->summary, 'TODO list';
-is_deeply $entry->labels, ['Featured', 'Phase-Support'];
-
-# test HTML
-$entry = $wiki->entry('TestPage');
-like $entry->html, qr/Add your content here/;
-is $entry->updated_time, 'Sat Jan 17 15:21:27 2009';
-is $entry->updated_by, 'fayland';
-is $entry->summary, 'One-sentence summary of this page.';
-is_deeply $entry->labels, ['Phase-QA', 'Phase-Support'];
-
-is_deeply $entry->comments, [
-
-{
- author => 'fayland',
- date => 'Wed Jan 7 22:37:57 2009',
- content => '<p>comment1 </p>',
-},
-{
- author => 'fayland',
- date => 'Wed Jan 7 22:38:07 2009',
- content => '<p>two line comment 2. </p>',
-}
-
-];
+is( $wiki->source, $svn_content, 'source' );
+is(
+ $wiki->summary,
+ 'One-sentence summary of this page.',
+ 'summary is parsed'
+);
+is_deeply( $wiki->labels, [ 'Phase-QA', 'Phase-Support' ], 'labels are parsed' );
+
+is( $wiki->updated, 'Sat Jan 17 15:21:27 2009', 'updated is parsed' );
+is( $wiki->updated_by, 'fayland', 'updated_by is parsed' );
+like( $wiki->content, qr/<p>Add your content here/, 'content is parsed' );
+is( scalar @{$wiki->comments}, 2, '2 comments' );
+my $comments = $wiki->comments;
+
+is( $comments->[0]->author, 'fayland', '1st comment author is parsed' );
+is( $comments->[0]->date, 'Wed Jan 7 22:37:57 2009',
+ '1st comment date is parsed' );
+is( $comments->[0]->content, 'comment1', '1st comment content is parsed' );
+
+is( $comments->[1]->author, 'fayland', '2nd comment author is parsed' );
+is( $comments->[1]->date, 'Wed Jan 7 22:38:07 2009',
+ '2nd comment date is parsed' );
+is( $comments->[1]->content, 'two line comment 2.', '2nd comment content is parsed' );
1;
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 Tue May 12 01:24:03 2009
@@ -3,18 +3,19 @@
use strict;
use warnings;
-use Test::More tests => 16;
+use Test::More tests => 19;
use Test::MockModule;
use FindBin qw/$Bin/;
use File::Slurp;
use_ok('Net::Google::Code');
my $homepage_file = "$Bin/sample/20.code.html";
-my $homepage_content = read_file($homepage_file);
my $downloads_file = "$Bin/sample/10.downloads.xml";
-my $downloads_content = read_file($downloads_file);
my $download_file = "$Bin/sample/10.download.html";
-my $download_content = read_file($download_file);
+
+my $wikis_file = "$Bin/sample/11.wikis.html";
+my $svn_file = "$Bin/sample/11.TestPage.wiki";
+my $wiki_file = "$Bin/sample/11.TestPage.html";
my $mock = Test::MockModule->new('Net::Google::Code');
$mock->mock(
@@ -23,15 +24,19 @@
shift;
my $url = shift;
if ( $url =~ /downloads/ ) {
- return $downloads_content;
+ read_file( $downloads_file );
+ }
+ elsif ( $url =~ /wiki/ ) {
+ read_file( $wikis_file );
}
else {
- return $homepage_content;
+ read_file( $homepage_file );
}
}
);
+
my $mock_downloads = Test::MockModule->new('Net::Google::Code::Download');
-$mock_downloads->mock( 'fetch', sub { $download_content } );
+$mock_downloads->mock( 'fetch', sub { read_file($download_file) } );
my $name = 'net-google-code';
my $project = Net::Google::Code->new( project => $name );
@@ -51,9 +56,33 @@
isa_ok( $project->download, 'Net::Google::Code::Download' );
isa_ok( $project->wiki, 'Net::Google::Code::Wiki' );
+
+# test downloads
$project->load_downloads;
-is( scalar @{ $project->load_downloads }, 1, 'have 1 download' );
-my $download = $project->load_downloads->[0];
+is( scalar @{ $project->downloads }, 1, 'have 1 download' );
+my $download = $project->downloads->[0];
isa_ok( $download, 'Net::Google::Code::Download' );
is( $download->name, 'Net-Google-Code-0.01.tar.gz', 'download name' );
is( $download->size, '37.4 KB', 'download size' );
+
+
+# test wikis
+my $mock_wiki = Test::MockModule->new('Net::Google::Code::Wiki');
+$mock_wiki->mock(
+ 'fetch',
+ sub {
+ shift;
+ my $url = shift;
+ if ( $url =~ /svn/ ) {
+ read_file($svn_file);
+ }
+ else {
+ read_file($wiki_file);
+ }
+ }
+);
+$project->load_wikis;
+is( scalar @{ $project->wikis }, 1, 'have 1 wiki' );
+my $wiki = $project->wikis->[0];
+is( $wiki->name, 'TestPage', 'wiki name' );
+is( $wiki->summary, 'One-sentence summary of this page.', 'wiki summary' );
Added: Net-Google-Code/trunk/t/sample/11.wikis.html
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/t/sample/11.wikis.html Tue May 12 01:24:03 2009
@@ -0,0 +1,9 @@
+<html><head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>net-google-code - Revision 6: /wiki</title></head><body>
+ <h2>net-google-code - Revision 6: /wiki</h2>
+ <ul>
+ <li><a href="http://net-google-code.googlecode.com/svn/">..</a></li>
+ <li><a href="http://net-google-code.googlecode.com/svn/wiki/TestPage.wiki">TestPage.wiki</a></li>
+ </ul>
+ <hr noshade="noshade"><em><a href="http://code.google.com/">Google Code</a> powered by <a href="http://subversion.tigris.org/">Subversion</a> </em>
+</body></html>
\ No newline at end of file
More information about the Bps-public-commit
mailing list