[Bps-public-commit] r17690 - in Net-Google-Code/trunk: . lib/Net/Google lib/Net/Google/Code lib/Net/Google/Code/Role

sunnavy at bestpractical.com sunnavy at bestpractical.com
Sun Jan 11 12:34:10 EST 2009


Author: sunnavy
Date: Sun Jan 11 12:34:09 2009
New Revision: 17690

Added:
   Net-Google-Code/trunk/lib/Net/Google/Code/Base.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/Connectable.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/RemoteFile.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/URL.pm
   Net-Google-Code/trunk/t/01.base.t
Removed:
   Net-Google-Code/trunk/lib/Net/Google/Code/Connection.pm
Modified:
   Net-Google-Code/trunk/   (props changed)
   Net-Google-Code/trunk/lib/Net/Google/Code.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Downloads.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Home.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/IssueAttachment.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/IssueComment.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/IssueSearch.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/WikiEntry.pm
   Net-Google-Code/trunk/t/02.issue.t
   Net-Google-Code/trunk/t/03.comment.t
   Net-Google-Code/trunk/t/04.attachment.t
   Net-Google-Code/trunk/t/10.downloads.t
   Net-Google-Code/trunk/t/11.wiki.t
   Net-Google-Code/trunk/t/20.code.t

Log:
 r18706 at sunnavys-mb:  sunnavy | 2009-01-12 01:21:20 +0800
 refactor a lot


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	Sun Jan 11 12:34:09 2009
@@ -1,42 +1,17 @@
 package Net::Google::Code;
 
 use Moose;
-use Net::Google::Code::Connection;
+extends 'Net::Google::Code::Base';
 
 our $VERSION = '0.02';
 
-has 'project' => (
-    isa      => 'Str',
-    is       => 'ro',
-    required => 1,
-);
-
-has 'connection' => (
-    isa  => 'Net::Google::Code::Connection',
-    is   => 'ro',
-    lazy => 1,
-    default =>
-      sub { Net::Google::Code::Connection->new( project => $_[0]->project ) },
-);
-
-has 'url' => (
-    isa     => 'Str',
-    is      => 'ro',
-    default => sub { $_[0]->connection->base_url . $_[0]->project . '/' },
-);
-
-has 'svn_url' => (
-    is => 'ro', isa => 'Str',
-    default => sub { 'http://' . $_[0]->project . '.googlecode.com/svn/' },
-);
-
 has 'home'  => (
     isa     => 'Net::Google::Code::Home',
     is      => 'ro',
     lazy    => 1,
     default => sub {
         require Net::Google::Code::Home;
-        Net::Google::Code::Home->new( parent => $_[0] );
+        Net::Google::Code::Home->new( project => $_[0]->project );
     },
     handles => [ 'owners', 'members', 'summary', 'description', 'labels' ],
 );
@@ -47,7 +22,7 @@
     lazy    => 1,
     default => sub {
         require Net::Google::Code::Issue;
-        Net::Google::Code::Issue->new( connection => $_[0]->connection );
+        Net::Google::Code::Issue->new( project => $_[0]->project );
     }
 );
 
@@ -57,7 +32,7 @@
     lazy    => 1,
     default => sub {
         require Net::Google::Code::Downloads;
-        Net::Google::Code::Downloads->new( parent => $_[0] );
+        Net::Google::Code::Downloads->new( project => $_[0]->project );
     }
 );
 
@@ -67,7 +42,7 @@
     lazy    => 1,
     default => sub {
         require Net::Google::Code::Wiki;
-        Net::Google::Code::Wiki->new( parent => $_[0] );
+        Net::Google::Code::Wiki->new( project => $_[0]->project );
     }
 );
 

Added: Net-Google-Code/trunk/lib/Net/Google/Code/Base.pm
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Base.pm	Sun Jan 11 12:34:09 2009
@@ -0,0 +1,48 @@
+package Net::Google::Code::Base;
+use Moose;
+with 'Net::Google::Code::Role::URL';
+with 'Net::Google::Code::Role::Connectable';
+
+has 'project' => (
+    isa      => 'Str',
+    reader   => '_project',
+    required => 1,
+);
+
+=head2 project
+
+# TODO Role's 'requires' can't work with attributes yet
+# waiting for Moose's update
+
+=cut
+
+sub project { return shift->_project }
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+__END__
+
+=head1 NAME
+
+Net::Google::Code::Connection - 
+
+
+=head1 DESCRIPTION
+
+=head1 INTERFACE
+
+=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/lib/Net/Google/Code/Downloads.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Downloads.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Downloads.pm	Sun Jan 11 12:34:09 2009
@@ -4,23 +4,15 @@
 use XML::Atom::Feed;
 use Params::Validate qw(:all);
 
+extends 'Net::Google::Code::Base';
+
 our $VERSION = '0.02';
 our $AUTHORITY = 'cpan:FAYLAND';
 
-has parent => (
-    isa => 'Net::Google::Code',
-    is  => 'ro',
-    required => 1,
-);
-
 sub all_entries {
 	my $self = shift;
 	
-	my $connection = $self->parent->connection;
-	my $project    = $self->parent->project;
-	my $feed_url   = "http://code.google.com/feeds/p/$project/downloads/basic";
-	
-	my $content = $connection->fetch( $feed_url );
+	my $content = $self->fetch( $self->base_feeds_url . 'downloads/basic' );
 	my $feed = XML::Atom::Feed->new( \$content );
 	my @fentries = $feed->entries;
 	
@@ -49,11 +41,8 @@
 	
 	# http://code.google.com/p/net-google-code/downloads/detail?name=Net-Google-Code-0.01.tar.gz
 	
-	my $connection = $self->parent->connection;
-	my $project    = $self->parent->project;
-	
-	my $url = "http://code.google.com/p/$project/downloads/detail?name=$filename";
-	my $content = $connection->fetch( $url );
+    my $content =
+      $self->fetch( $self->base_url . "downloads/detail?name=$filename" );
 	
 	require HTML::TreeBuilder;
     my $tree = HTML::TreeBuilder->new;

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Home.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Home.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Home.pm	Sun Jan 11 12:34:09 2009
@@ -5,11 +5,8 @@
 our $VERSION = '0.02';
 our $AUTHORITY = 'cpan:FAYLAND';
 
-has parent => (
-    isa => 'Net::Google::Code',
-    is  => 'ro',
-    required => 1,
-);
+extends 'Net::Google::Code::Base';
+
 
 has '__html' => (
     isa => 'Str',
@@ -17,11 +14,7 @@
     lazy => 1,
     default => sub {
         my $self = shift;
-        
-        my $connection = $self->parent->connection;
-        
-        my $content = $connection->fetch( $self->parent->url );
-        return $content;
+        return $self->fetch( $self->base_url );
     }
 );
 

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	Sun Jan 11 12:34:09 2009
@@ -1,29 +1,24 @@
 package Net::Google::Code::Issue;
 use Moose;
 use Params::Validate qw(:all);
+extends 'Net::Google::Code::Base';
 use Net::Google::Code::IssueComment;
 
-has connection => (
-    isa => 'Net::Google::Code::Connection',
-    is  => 'ro',
-    required => 1,
-);
-
 has state => (
-    isa => 'HashRef',
-    is  => 'rw',
+    isa     => 'HashRef',
+    is      => 'rw',
     default => sub { {} },
 );
 
 has labels => (
-    isa => 'HashRef',
-    is  => 'rw',
+    isa     => 'HashRef',
+    is      => 'rw',
     default => sub { {} },
 );
 
 has comments => (
-    isa => 'ArrayRef[Net::Google::Code::Comment]',
-    is => 'rw',
+    isa     => 'ArrayRef[Net::Google::Code::Comment]',
+    is      => 'rw',
     default => sub { [] },
 );
 
@@ -36,7 +31,7 @@
 our @PROPS = qw(id status owner closed cc summary reporter description);
 
 for my $prop (@PROPS) {
-    no strict 'refs'; ## no critic
+    no strict 'refs';    ## no critic
     *{ "Net::Google::Code::Issue::" . $prop } = sub { shift->state->{$prop} };
 }
 
@@ -44,27 +39,26 @@
     my $self = shift;
     my ($id) = validate_pos( @_, { type => SCALAR } );
     $self->state->{id} = $id;
-    my $content = $self->connection->fetch( "/issues/detail?id=" . $id );
-    $self->parse( $content );
+    my $content = $self->fetch( "/issues/detail?id=" . $id );
+    $self->parse($content);
     return $id;
 }
 
-
 sub parse {
-    my $self = shift;
+    my $self    = shift;
     my $content = shift;
 
     require HTML::TreeBuilder;
-    my $tree    = HTML::TreeBuilder->new;
+    my $tree = HTML::TreeBuilder->new;
     $tree->parse_content($content);
     $tree->elementify;
 
     # extract summary
-    my ($summary) = $tree->look_down(class => 'h3' );
+    my ($summary) = $tree->look_down( class => 'h3' );
     $self->state->{summary} = $summary->content_array_ref->[0];
 
     # extract reporter and description
-    my $description = $tree->look_down(class => 'vt issuedescription' );
+    my $description = $tree->look_down( class => 'vt issuedescription' );
     $self->state->{reporter} =
       $description->look_down( class => "author" )->content_array_ref->[1]
       ->content_array_ref->[0];
@@ -74,19 +68,19 @@
     $text =~ s/\r\n/\n/g;
     $self->state->{description} = $text;
 
-    my $attachments = $description->look_down(class => 'attachments');
-    if ( $attachments ) {
-        my @items = $attachments->find_by_tag_name( 'tr' );
+    my $attachments = $description->look_down( class => 'attachments' );
+    if ($attachments) {
+        my @items = $attachments->find_by_tag_name('tr');
         require Net::Google::Code::IssueAttachment;
         while ( scalar @items ) {
             my $tr1 = shift @items;
             my $tr2 = shift @items;
             my $a =
               Net::Google::Code::IssueAttachment->new(
-                connection => $self->connection );
+                project => $self->project );
 
             if ( $a->parse( $tr1, $tr2 ) ) {
-                push @{$self->attachments}, $a;
+                push @{ $self->attachments }, $a;
             }
         }
     }
@@ -114,7 +108,7 @@
                 $value =~ s/^\s+//;
                 $value =~ s/\s+$//;
             }
-            $self->state->{lc $key} = $value;
+            $self->state->{ lc $key } = $value;
         }
         else {
             my $href = $meta->find_by_tag_name('a')->attr_get_i('href');
@@ -138,10 +132,9 @@
     pop @comments;    # last one is for adding comment
     for my $comment (@comments) {
         my $object =
-          Net::Google::Code::IssueComment->new(
-            connection => $self->connection );
+          Net::Google::Code::IssueComment->new( project => $self->project );
         $object->parse($comment);
-        push @{$self->comments}, $object;
+        push @{ $self->comments }, $object;
     }
 
 }

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/IssueAttachment.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/IssueAttachment.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/IssueAttachment.pm	Sun Jan 11 12:34:09 2009
@@ -1,15 +1,7 @@
 package Net::Google::Code::IssueAttachment;
 use Moose;
-
-has connection => (
-    isa => 'Net::Google::Code::Connection',
-    is  => 'ro',
-    required => 1,
-);
-
-has filename => ( isa => 'Str', is => 'rw' );
-has url      => ( isa => 'Str', is => 'rw' );
-has size     => ( isa => 'Str', is => 'rw' );
+extends 'Net::Google::Code::Base';
+with 'Net::Google::Code::Role::RemoteFile';
 
 =head2 parse
 there're 2 trs that represent an attachment like the following:
@@ -24,24 +16,24 @@
 
 sub parse {
     my $self = shift;
-    my $tr1 = shift;
-    my $tr2 = shift;
-    my $b = $tr1->find_by_tag_name('b'); # filename lives here
-    if ( $b ) {
+    my $tr1  = shift;
+    my $tr2  = shift;
+    my $b    = $tr1->find_by_tag_name('b');    # name lives here
+    if ($b) {
         my $name = $b->content_array_ref->[0];
         $name =~ s/^\s+//;
         $name =~ s/\s+$//;
-        $self->filename( $name );
+        $self->name($name);
     }
 
     my $td = $tr2->find_by_tag_name('td');
-    if ( $td ) {
+    if ($td) {
         my $size = $td->content_array_ref->[0];
         $size =~ s/^\s+//;
         $size =~ s/\s+$//;
-        $self->size( $size );
+        $self->size($size);
 
-        $self->url($td->find_by_tag_name('a')->attr_get_i('href'));
+        $self->url( $td->find_by_tag_name('a')->attr_get_i('href') );
     }
 
     return 1;
@@ -49,10 +41,9 @@
 
 sub content {
     my $self = shift;
-    return $self->connection->fetch( $self->url );
+    return $self->fetch( $self->url );
 }
 
-
 no Moose;
 __PACKAGE__->meta->make_immutable;
 
@@ -66,11 +57,11 @@
 
 =head1 DESCRIPTION
 
-This class represents a single attachment for a trac ticket.
+This class represents a single attachment for an issue.
 
 =head1 INTERFACE
 
-=head2 filename
+=head2 name
 
 =head2 content
 

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/IssueComment.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/IssueComment.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/IssueComment.pm	Sun Jan 11 12:34:09 2009
@@ -1,17 +1,12 @@
 package Net::Google::Code::IssueComment;
 use Moose;
+extends 'Net::Google::Code::Base';
 
-has connection => (
-    isa => 'Net::Google::Code::Connection',
-    is  => 'ro',
-    required => 1,
-);
-
-has updates   => ( isa => 'HashRef', is => 'rw', default => sub { {} } );
-has author    => ( isa => 'Str',     is => 'rw' );
-has date      => ( isa => 'Str',     is => 'rw' );
-has content   => ( isa => 'Str',     is => 'rw' );
-has sequence  => ( isa => 'Int',     is => 'rw' );
+has updates => ( isa => 'HashRef', is => 'rw', default => sub { {} } );
+has author  => ( isa => 'Str',     is => 'rw' );
+has date    => ( isa => 'Str',     is => 'rw' );
+has content => ( isa => 'Str',     is => 'rw' );
+has sequence => ( isa => 'Int', is => 'rw' );
 has attachments => (
     isa     => 'ArrayRef[Net::Google::Code::IssueAttachment]',
     is      => 'rw',
@@ -33,7 +28,7 @@
  <span class="date" title="Wed Sep  3 04:44:39 2008">Sep 03, 2008</span>
 <pre>
 <b>haha</b>
-
+
 </pre>
  
  <div class="attachments">
@@ -65,10 +60,10 @@
 =cut
 
 sub parse {
-    my $self = shift;
+    my $self    = shift;
     my $element = shift;
-    my $author = $element->look_down( class => 'author' );
-    my @a = $author->find_by_tag_name('a');
+    my $author  = $element->look_down( class => 'author' );
+    my @a       = $author->find_by_tag_name('a');
     $self->sequence( $a[0]->content_array_ref->[0] );
     $self->author( $a[1]->content_array_ref->[0] );
     $self->date( $element->look_down( class => 'date' )->attr_get_i('title') );
@@ -76,24 +71,25 @@
     $content =~ s/^\s+//;
     $content =~ s/\s+$/\n/;
     $content =~ s/\r\n/\n/g;
-    $self->content( $content );
+    $self->content($content);
 
     my $updates = $element->look_down( class => 'updates' );
-    if ( $updates ) {
+    if ($updates) {
         my $box_inner = $element->look_down( class => 'box-inner' );
         my $content = $box_inner->content_array_ref;
-        while ( @$content ) {
-            my $tag = shift @$content;
+        while (@$content) {
+            my $tag   = shift @$content;
             my $value = shift @$content;
-            shift @$content; # this is for the <br>
+            shift @$content;    # this is for the <br>
 
             my $key = $tag->content_array_ref->[0];
-            $key =~ s/:$//;
+            $key   =~ s/:$//;
             $value =~ s/^\s+//;
             $value =~ s/\s+$//;
 
             if ( $key eq 'Labels' ) {
-# $value here is like "-Pri-2 -Area-Unknown Pri-3 Area-BrowserUI"
+
+               # $value here is like "-Pri-2 -Area-Unknown Pri-3 Area-BrowserUI"
                 my @items = split /\s+/, $value;
 
                 for my $value (@items) {
@@ -123,24 +119,24 @@
                 }
             }
             else {
-                $self->updates->{lc $key} = $value;
+                $self->updates->{ lc $key } = $value;
             }
         }
 
     }
     my $attachments = $element->look_down( class => 'attachments' );
-    if ( $attachments ) {
-        my @items = $attachments->find_by_tag_name( 'tr' );
+    if ($attachments) {
+        my @items = $attachments->find_by_tag_name('tr');
         require Net::Google::Code::IssueAttachment;
         while ( scalar @items ) {
             my $tr1 = shift @items;
             my $tr2 = shift @items;
             my $a =
               Net::Google::Code::IssueAttachment->new(
-                connection => $self->connection );
+                project => $self->project );
 
             if ( $a->parse( $tr1, $tr2 ) ) {
-                push @{$self->attachments}, $a;
+                push @{ $self->attachments }, $a;
             }
         }
     }
@@ -148,7 +144,7 @@
     return 1;
 }
 
-no Moose;
+no Moose;
 __PACKAGE__->meta->make_immutable;
 1;
 

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/IssueSearch.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/IssueSearch.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/IssueSearch.pm	Sun Jan 11 12:34:09 2009
@@ -2,12 +2,7 @@
 use Moose;
 use Params::Validate qw(:all);
 use Moose::Util::TypeConstraints;
-
-has connection => (
-    isa => 'Net::Google::Code::Connection',
-    is  => 'ro',
-    required => 1,
-);
+extends 'Net::Google::Code::Base';
 
 our %CAN = (
     'all'    => 1,
@@ -49,8 +44,8 @@
         $self->_q( $args{_q} ) if defined $args{_q};
     }
 
-    my $mech = $self->connection->mech;
-    $self->connection->fetch('/issues/list');
+    $self->fetch('issues/list');
+    my $mech = $self->mech;
     $mech->submit_form(
         form_number => 2,
         fields      => {

Added: Net-Google-Code/trunk/lib/Net/Google/Code/Role/Connectable.pm
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/Connectable.pm	Sun Jan 11 12:34:09 2009
@@ -0,0 +1,74 @@
+package Net::Google::Code::Role::Connectable;
+use Moose::Role;
+use Params::Validate;
+use Net::Google::Code::Mechanize;
+
+with 'Net::Google::Code::Role::URL';
+
+has mech => (
+    isa     => 'Net::Google::Code::Mechanize',
+    is      => 'ro',
+    lazy    => 1,
+    default => sub {
+        my $self = shift;
+        my $m    = Net::Google::Code::Mechanize->new(
+			agent       => 'Net-Google-Code',
+            cookie_jar  => {},
+            stack_depth => 1,
+            timeout     => 60,
+        );
+        return $m;
+    }
+);
+
+sub fetch {
+    my $self    = shift;
+    my $query   = shift;
+    my $abs_url;
+    if ( $query =~ /^http(s)?:/ ) {
+        $abs_url = $query;
+    }
+    else {
+        $abs_url = $self->base_url . $query;
+    }
+
+    $self->mech->get($abs_url);
+    if ( !$self->mech->response->is_success ) {
+        die "Server threw an error "
+          . $self->mech->response->status_line . " for "
+          . $abs_url;
+    }
+    else {
+        return $self->mech->content;
+    }
+}
+
+no Moose::Role;
+
+1;
+
+__END__
+
+=head1 NAME
+
+Net::Google::Code::Role::Connectable - 
+
+
+=head1 DESCRIPTION
+
+=head1 INTERFACE
+
+=head2 fetch
+
+=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/Role/RemoteFile.pm
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/RemoteFile.pm	Sun Jan 11 12:34:09 2009
@@ -0,0 +1,35 @@
+package Net::Google::Code::Role::RemoteFile;
+use Moose::Role;
+
+has name    => ( isa => 'Str', is => 'rw' );
+has url     => ( isa => 'Str', is => 'rw' );
+has size    => ( isa => 'Str', is => 'rw' );
+has content => ( isa => 'Str', is => 'rw' );
+
+no Moose::Role;
+
+1;
+
+__END__
+
+=head1 NAME
+
+Net::Google::Code::Role::RemoteFile - 
+
+
+=head1 DESCRIPTION
+
+=head1 INTERFACE
+
+=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/Role/URL.pm
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/URL.pm	Sun Jan 11 12:34:09 2009
@@ -0,0 +1,57 @@
+package Net::Google::Code::Role::URL;
+use Moose::Role;
+
+requires 'project'; 
+
+has 'base_url' => (
+    isa     => 'Str',
+    is      => 'ro',
+    lazy    => 1,
+    default => sub { 'http://code.google.com/p/' . $_[0]->project . '/' },
+);
+
+has 'base_svn_url' => (
+    is      => 'ro',
+    isa     => 'Str',
+    lazy    => 1,
+    default => sub { 'http://' . $_[0]->project . '.googlecode.com/svn/' },
+);
+
+has 'base_feeds_url' => (
+    is      => 'ro',
+    isa     => 'Str',
+    lazy    => 1,
+    default => sub {
+        'http://code.google.com/feeds/p/' . $_[0]->project . '/'
+    },
+);
+
+no Moose::Role;
+
+1;
+
+__END__
+
+=head1 NAME
+
+Net::Google::Code::Role::URL - 
+
+
+=head1 DESCRIPTION
+
+=head1 INTERFACE
+
+=head2 fetch
+
+=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/lib/Net/Google/Code/Wiki.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Wiki.pm	Sun Jan 11 12:34:09 2009
@@ -4,24 +4,16 @@
 use Params::Validate qw(:all);
 
 use Net::Google::Code::WikiEntry;
+extends 'Net::Google::Code::Base';
 
 our $VERSION = '0.02';
 our $AUTHORITY = 'cpan:FAYLAND';
 
-has parent => (
-    isa => 'Net::Google::Code',
-    is  => 'ro',
-    required => 1,
-);
-
 sub all_entries {
 	my $self = shift;
 	
-	my $connection = $self->parent->connection;
-	my $project    = $self->parent->project;
-	
-	my $wiki_svn = "http://$project.googlecode.com/svn/wiki/";
-	my $content = $connection->fetch( $wiki_svn );
+	my $wiki_svn = $self->base_svn_url . 'wiki/';
+	my $content = $self->fetch( $wiki_svn );
 	
 	# regex would be OK
 	my @lines = split("\n", $content);
@@ -41,7 +33,7 @@
     
     my ($wiki_item) = validate_pos( @_, { type => SCALAR } );
     
-    return Net::Google::Code::WikiEntry->new( parent => $self->parent, name => $wiki_item );
+    return Net::Google::Code::WikiEntry->new( project => $self->project, name => $wiki_item );
 }
 
 no Moose;

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/WikiEntry.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/WikiEntry.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/WikiEntry.pm	Sun Jan 11 12:34:09 2009
@@ -2,16 +2,11 @@
 
 use Moose;
 use Params::Validate qw(:all);
+extends 'Net::Google::Code::Base';
 
 our $VERSION = '0.02';
 our $AUTHORITY = 'cpan:FAYLAND';
 
-has parent => (
-    isa => 'Net::Google::Code',
-    is  => 'ro',
-    required => 1,
-);
-
 has name => ( is => 'ro', isa => 'Str', required => 1 );
 
 has 'source' => (
@@ -20,15 +15,7 @@
     lazy => 1,
     default => sub {
         my $self = shift;
-        
-        my $name       = $self->name;
-        my $connection = $self->parent->connection;
-	    my $project    = $self->parent->project;
-        
-        my $wiki_url = "http://$project.googlecode.com/svn/wiki/$name.wiki";
-        my $content = $connection->fetch( $wiki_url );
-        
-        return $content;
+        return $self->fetch( $self->base_svn_url . 'wiki/' . $self->name . '.wiki' );
     }
 );
 
@@ -38,16 +25,8 @@
     lazy => 1,
     default => sub {
         my $self = shift;
-        
-        my $name       = $self->name;
-        my $connection = $self->parent->connection;
-	    my $project    = $self->parent->project;
-        
         # http://code.google.com/p/net-google-code/wiki/TestPage
-        my $wiki_url = "http://code.google.com/p/$project/wiki/$name";
-        my $content = $connection->fetch( $wiki_url );
-        
-        return $content;
+        return $self->fetch( $self->base_url . 'wiki/' .  $self->name );
     }
 );
 

Added: Net-Google-Code/trunk/t/01.base.t
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/t/01.base.t	Sun Jan 11 12:34:09 2009
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+use Net::Google::Code::Base;
+my $base = Net::Google::Code::Base->new( project => 'test' );
+is( $base->base_url, 'http://code.google.com/p/test/', 'base svn url' );
+is( $base->base_svn_url, 'http://test.googlecode.com/svn/', 'base svn url' );
+isa_ok( $base->mech, 'Net::Google::Code::Mechanize' );
+
+use Test::MockModule;
+
+my $mech = Test::MockModule->new('Net::Google::Code::Mechanize');
+my $resp = Test::MockModule->new('HTTP::Response');
+
+$mech->mock( 'content',    sub { 'content' } );
+$mech->mock( 'get',        sub {} );
+$mech->mock( 'response',   sub { HTTP::Response->new } );
+$resp->mock( 'is_success', sub { 1 } );
+
+is( $base->fetch('blabla'), 'content', 'fetch' );

Modified: Net-Google-Code/trunk/t/02.issue.t
==============================================================================
--- Net-Google-Code/trunk/t/02.issue.t	(original)
+++ Net-Google-Code/trunk/t/02.issue.t	Sun Jan 11 12:34:09 2009
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 18;
+use Test::More tests => 15;
 use Test::MockModule;
 
 # $content is a real page: http://code.google.com/p/chromium/issues/detail?id=14
@@ -12,18 +12,15 @@
 
 my $content = read_file( "$Bin/sample/02.issue.html" );
 
-my $mock_connection = Test::MockModule->new('Net::Google::Code::Connection');
-$mock_connection->mock(
+my $mock = Test::MockModule->new('Net::Google::Code::Issue');
+$mock->mock(
     'fetch',
     sub { $content }
 );
 
-use_ok('Net::Google::Code::Connection');
-use_ok('Net::Google::Code::Issue');
-my $connection = Net::Google::Code::Connection->new( project => 'test' );
-my $ticket = Net::Google::Code::Issue->new( connection => $connection );
+use Net::Google::Code::Issue;
+my $ticket = Net::Google::Code::Issue->new( project => 'test' );
 isa_ok( $ticket, 'Net::Google::Code::Issue', '$ticket' );
-isa_ok( $ticket->connection, 'Net::Google::Code::Connection', '$ticket->connection' );
 $ticket->load(14);
 
 my $description = <<"EOF";

Modified: Net-Google-Code/trunk/t/03.comment.t
==============================================================================
--- Net-Google-Code/trunk/t/03.comment.t	(original)
+++ Net-Google-Code/trunk/t/03.comment.t	Sun Jan 11 12:34:09 2009
@@ -1,13 +1,12 @@
 use strict;
 use warnings;
 
-use Test::More tests => 11;
+use Test::More tests => 9;
 
-use_ok( 'Net::Google::Code::IssueComment' );
-use_ok( 'Net::Google::Code::Connection' );
-my $connection = Net::Google::Code::Connection->new( project => 'haha' );
+use Net::Google::Code::IssueComment;
+use Net::Google::Code::Connection;
 my $comment =
-  Net::Google::Code::IssueComment->new( connection => $connection );
+  Net::Google::Code::IssueComment->new( project => 'test' );
 isa_ok( $comment, 'Net::Google::Code::IssueComment', '$comment' );
 
 my $content;
@@ -51,8 +50,8 @@
 is_deeply( $updates, $comment->updates, 'updates are extracted' );
 
 is( scalar @{$comment->attachments}, 2, 'attachments are extracted' );
-is( $comment->attachments->[0]->filename, 'proxy_settings.png', '1st attachment' );
-is( $comment->attachments->[1]->filename, 'haha.png', '2nd attachment' );
+is( $comment->attachments->[0]->name, 'proxy_settings.png', '1st attachment' );
+is( $comment->attachments->[1]->name, 'haha.png', '2nd attachment' );
 
 __DATA__
  <td class="vt issuecomment">

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	Sun Jan 11 12:34:09 2009
@@ -1,16 +1,10 @@
 use strict;
 use warnings;
 
-use Test::More tests => 7;
-
-
-
-use_ok( 'Net::Google::Code::IssueAttachment' );
-use_ok( 'Net::Google::Code::Connection' );
-my $connection = Net::Google::Code::Connection->new( project => 'haha' );
-my $attachment =
-  Net::Google::Code::IssueAttachment->new( connection => $connection );
+use Test::More tests => 5;
 
+use Net::Google::Code::IssueAttachment;
+my $attachment = Net::Google::Code::IssueAttachment->new( project => 'test' );
 isa_ok( $attachment, 'Net::Google::Code::IssueAttachment', '$attachment' );
 
 
@@ -32,7 +26,7 @@
 my %info = (
     url =>
 'http://chromium.googlecode.com/issues/attachment?aid=-1323983749556004507&name=proxy_settings.png',
-    filename => 'proxy_settings.png',
+    name => 'proxy_settings.png',
     size     => '14.3 KB',
 );
 

Modified: Net-Google-Code/trunk/t/10.downloads.t
==============================================================================
--- Net-Google-Code/trunk/t/10.downloads.t	(original)
+++ Net-Google-Code/trunk/t/10.downloads.t	Sun Jan 11 12:34:09 2009
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 13;
+use Test::More tests => 12;
 use Test::MockModule;
 use FindBin qw/$Bin/;
 use File::Slurp;
@@ -15,8 +15,8 @@
 my $feed_content = read_file($feed_file);
 my $download_content = read_file($down_file);
 
-my $mock_connection = Test::MockModule->new('Net::Google::Code::Connection');
-$mock_connection->mock(
+my $mock_downloads = Test::MockModule->new('Net::Google::Code::Downloads');
+$mock_downloads->mock(
     'fetch',
     sub {
     	( undef, my $uri ) = @_;
@@ -28,10 +28,8 @@
     }
 );
 
-my $project = Net::Google::Code->new( project => 'net-google-code' );
-my $downloads = $project->downloads;
+my $downloads = Net::Google::Code::Downloads->new( project => 'net-google-code' );
 isa_ok( $downloads, 'Net::Google::Code::Downloads' );
-isa_ok( $downloads->parent, 'Net::Google::Code' );
 
 my @entries = $downloads->all_entries;
 is( scalar @entries, 1 );
@@ -49,3 +47,4 @@
 is $entry->{file_SHA1}, '5073de2276f916cf5d74d7abfd78a463e15674a1';
 
 1;
+

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	Sun Jan 11 12:34:09 2009
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 9;
 use Test::MockModule;
 use FindBin qw/$Bin/;
 use File::Slurp;
@@ -16,10 +16,9 @@
 my $wiki_content  = read_file($wiki_file);
 my $entry_content = read_file($entry_file);
 
-my $mock_connection = Test::MockModule->new('Net::Google::Code::Connection');
-$mock_connection->mock(
-    'fetch',
-    sub {
+use Net::Google::Code::Wiki;
+
+my $mock_sub = sub {
     	( undef, my $uri ) = @_;
     	if ( $uri eq 'http://foorum.googlecode.com/svn/wiki/' ) {
     		return $svn_content;
@@ -28,13 +27,17 @@
     	} elsif ( $uri eq 'http://code.google.com/p/foorum/wiki/TODO' ) {
     	    return $entry_content;
         }
-    }
-);
 
-my $project = Net::Google::Code->new( project => 'foorum' );
-my $wiki = $project->wiki;
+};
+
+my $mock_wiki = Test::MockModule->new('Net::Google::Code::Wiki');
+$mock_wiki->mock( 'fetch', $mock_sub );
+
+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 => 'foorum' );
 isa_ok( $wiki, 'Net::Google::Code::Wiki' );
-isa_ok( $wiki->parent, 'Net::Google::Code' );
 
 my @entries = $wiki->all_entries;
 is( scalar @entries, 16 );

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	Sun Jan 11 12:34:09 2009
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 13;
+use Test::More tests => 12;
 use Test::MockModule;
 use FindBin qw/$Bin/;
 use File::Slurp;
@@ -12,8 +12,8 @@
 my $homepage_file = "$Bin/sample/20.code.html";
 my $homepage_content = read_file($homepage_file);
 
-my $mock_connection = Test::MockModule->new('Net::Google::Code::Connection');
-$mock_connection->mock(
+my $mock = Test::MockModule->new('Net::Google::Code::Home');
+$mock->mock(
     'fetch',
     sub {
     	( undef, my $uri ) = @_;
@@ -26,8 +26,8 @@
 my $name = 'net-google-code';
 my $project = Net::Google::Code->new( project => $name );
 
-is( $project->url, "http://code.google.com/p/$name/", 'default url' );
-is( $project->svn_url, "http://$name.googlecode.com/svn/", 'svn url' );
+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' );
 is_deeply( $project->owners, [ 'sunnavy' ] );
 is_deeply( $project->members, [ 'jessev', 'fayland' ] );
@@ -35,7 +35,6 @@
 is_deeply( $project->labels, [ 'perl', 'Google' ] );
 is $project->summary, 'a simple client library for google code';
 
-isa_ok( $project->connection, 'Net::Google::Code::Connection' );
 isa_ok( $project->issue,      'Net::Google::Code::Issue' );
 isa_ok( $project->downloads,  'Net::Google::Code::Downloads' );
 isa_ok( $project->wiki,       'Net::Google::Code::Wiki' );



More information about the Bps-public-commit mailing list