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

fayland at bestpractical.com fayland at bestpractical.com
Wed Jan 7 00:12:44 EST 2009


Author: fayland
Date: Wed Jan  7 00:12:42 2009
New Revision: 17603

Added:
   Net-Google-Code/trunk/lib/Net/Google/Code/Downloads.pm
   Net-Google-Code/trunk/t/10.downloads.t
Modified:
   Net-Google-Code/trunk/Changes
   Net-Google-Code/trunk/Makefile.PL

Log:
new Net::Google::Code::Downloads

Modified: Net-Google-Code/trunk/Changes
==============================================================================
--- Net-Google-Code/trunk/Changes	(original)
+++ Net-Google-Code/trunk/Changes	Wed Jan  7 00:12:42 2009
@@ -1,5 +1,8 @@
 Revision history for Net-Google-Code
 
+0.02
+       new Net::Google::Code::Downloads
+
 0.01 Tue Jan  6 10:17:56 CST 2009
        Initial release.
 

Modified: Net-Google-Code/trunk/Makefile.PL
==============================================================================
--- Net-Google-Code/trunk/Makefile.PL	(original)
+++ Net-Google-Code/trunk/Makefile.PL	Wed Jan  7 00:12:42 2009
@@ -11,6 +11,7 @@
 requires 'WWW::Mechanize';
 requires 'HTML::TreeBuilder';
 requires 'Params::Validate';
+requires 'XML::Atom';
 
 auto_install;
 

Added: Net-Google-Code/trunk/lib/Net/Google/Code/Downloads.pm
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Downloads.pm	Wed Jan  7 00:12:42 2009
@@ -0,0 +1,84 @@
+package Net::Google::Code::Downloads;
+
+use Moose;
+use XML::Atom::Feed;
+use URI;
+use Params::Validate qw(:all);
+
+has connection => (
+    isa => 'Net::Google::Code::Connection',
+    is  => 'ro',
+    required => 1,
+);
+
+sub all_entries {
+	my $self = shift;
+	
+	my $connection = $self->connection;
+	my $project    = $connection->project;
+	my $feed_url   = "http://code.google.com//feeds/p/$project/downloads/basic";
+	
+	my $content = $connection->_fetch( $feed_url );
+	my $feed = XML::Atom::Feed->new( \$content );
+	my @fentries = $feed->entries;
+	
+	my @dentries;
+	foreach my $entry (@fentries) {
+		my $link   = $entry->link;
+		my $title  = $entry->title;
+		my $author = $entry->author;
+		my ($dtitle, $dsize) = ( $title =~ /^\s*(.*?)\s+\((.*?)\)/ );
+		
+		push @dentries, {
+			filename => $dtitle,
+			author   => $author->name,
+			size     => $dsize,
+			link     => $link->href,
+		}
+	}
+	
+	return wantarray ? @dentries : \@dentries;
+}
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
+
+1;
+__END__
+
+=head1 NAME
+
+Net::Google::Code::Downloads - Google Code Downloads
+
+=head1 SYNOPSIS
+
+    use Net::Google::Code::Connection;
+    my $connection = Net::Google::Code::Connection( project => 'net-google-code' );
+
+    use Net::Google::Code::Downloads;
+    my $download = Net::Google::Code::Downloads->new( connection => $connection );
+    
+    my @entries = $download->all_entries;
+
+
+=head1 DESCRIPTION
+
+get Downloads details from Google Code Project
+
+=head1 METHODS
+
+=head2 all_entries
+
+Get all download entries from the Atom feed
+
+=head1 AUTHOR
+
+Fayland Lam, C<< <fayland at gmail.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/t/10.downloads.t
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/t/10.downloads.t	Wed Jan  7 00:12:42 2009
@@ -0,0 +1,65 @@
+use strict;
+use warnings;
+
+use Test::More tests => 6;
+use Test::MockModule;
+
+# $content is a real page: http://code.google.com/feeds/p/net-google-code/downloads/basic
+# we faked something to meet some situations, which are commented below
+
+my $content;
+{
+        local $/;
+        $content = <DATA>;
+}
+
+
+my $mock_connection = Test::MockModule->new('Net::Google::Code::Connection');
+$mock_connection->mock(
+    '_fetch',
+    sub { $content }
+);
+
+use_ok('Net::Google::Code::Connection');
+use_ok('Net::Google::Code::Downloads');
+my $connection = Net::Google::Code::Connection->new( project => 'test' );
+my $downloads = Net::Google::Code::Downloads->new( connection => $connection );
+isa_ok( $downloads, 'Net::Google::Code::Downloads' );
+isa_ok( $downloads->connection, 'Net::Google::Code::Connection', '$ticket->connection' );
+
+my @entries = $downloads->all_entries;
+is( scalar @entries, 1 );
+is $entries[0]->{filename}, 'Net-Google-Code-0.01.tar.gz';
+
+__DATA__
+<?xml version="1.0"?>
+
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <updated>2009-01-06T08:16:06Z</updated>
+ <id>http://code.google.com/feeds/p/net-google-code/downloads/basic</id>
+ <title>Downloads for project net-google-code on Google Code</title>
+ <link rel="self" type="application/atom+xml;type=feed" href="http://code.google.com/feeds/p/net-google-code/downloads/basic"/>
+ <link rel="alternate" type="text/html" href="http://code.google.com/p/net-google-code/downloads/list"/>
+ 
+ <entry>
+ <updated>2009-01-06T08:16:06Z</updated>
+ <id>http://code.google.com/feeds/p/net-google-code/downloads/basic/Net-Google-Code-0.01.tar.gz</id>
+ <link rel="alternate" type="text/html" href="http://code.google.com/p/net-google-code/downloads/detail?name=Net-Google-Code-0.01.tar.gz" />
+ <title>
+ Net-Google-Code-0.01.tar.gz (37.4 KB)
+ </title>
+ <author>
+ <name>sunnavy</name>
+ </author>
+ <content type="html">
+
+<pre>
+Net-Google-Code-0.01
+
+<a href="http://net-google-code.googlecode.com/files/Net-Google-Code-0.01.tar.gz">Download</a>
+</pre>
+ </content>
+</entry>
+
+ 
+</feed>



More information about the Bps-public-commit mailing list