[Bps-public-commit] r20013 - in Net-Google-Code/trunk: lib/Net/Google/Code/Issue lib/Net/Google/Code/Role

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Jun 18 00:04:43 EDT 2009


Author: sunnavy
Date: Thu Jun 18 00:04:42 2009
New Revision: 20013

Added:
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/Atom.pm
Modified:
   Net-Google-Code/trunk/Makefile.PL
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm

Log:
added Atom role, now we parse atom by ourselves

Modified: Net-Google-Code/trunk/Makefile.PL
==============================================================================
--- Net-Google-Code/trunk/Makefile.PL	(original)
+++ Net-Google-Code/trunk/Makefile.PL	Thu Jun 18 00:04:42 2009
@@ -16,7 +16,6 @@
 requires 'MIME::Types';
 requires 'File::MMagic';
 requires 'JSON';
-requires 'XML::Atom';
 
 recursive_author_tests('xt/');
 

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm	Thu Jun 18 00:04:42 2009
@@ -6,6 +6,7 @@
 with 'Net::Google::Code::Role::Fetchable';
 with 'Net::Google::Code::Role::Pageable';
 with  'Net::Google::Code::Role::HTMLTree';
+with  'Net::Google::Code::Role::Atom';
 use Net::Google::Code::Issue;
 use Encode;
 
@@ -34,22 +35,20 @@
     
     my @results;
 
-    require XML::Atom::Feed;
     my $content = $self->fetch( $self->base_feeds_url . 'issueupdates/basic' );
-    my $feed    = XML::Atom::Feed->new( \$content ) or die 'parse feeds failed';
-    my @entries = $feed->entries;
-    if (@entries) {
+    my ( $feed, $entries ) = $self->parse_atom( $content );
+    if (@$entries) {
         my $min_updated =
-          Net::Google::Code::DateTime->new_from_string( $entries[-1]->updated );
+          Net::Google::Code::DateTime->new_from_string( $entries->[-1]->{updated} );
         if ( $min_updated < $after ) {
 
             # yeah! we can get all the results by parsing the feed
             my %seen;
-            for my $entry (@entries) {
+            for my $entry (@$entries) {
                 my $updated = Net::Google::Code::DateTime->new_from_string(
-                    $entry->updated );
+                    $entry->{updated} );
                 next unless $updated >= $after;
-                if ( $entry->title =~ /issue\s+(\d+)/i ) {
+                if ( $entry->{title} =~ /issue\s+(\d+)/i ) {
                     next if $seen{$1}++;
                     push @results,
                       Net::Google::Code::Issue->new(

Added: Net-Google-Code/trunk/lib/Net/Google/Code/Role/Atom.pm
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/Atom.pm	Thu Jun 18 00:04:42 2009
@@ -0,0 +1,96 @@
+package Net::Google::Code::Role::Atom;
+use Any::Moose 'Role';
+use Params::Validate ':all';
+use HTML::Entities;
+
+sub parse_atom {
+    my $self = shift;
+    my ($content) = validate_pos( @_, 1 );
+
+    my $feed    = {};
+    my $entries = [];
+
+    if ( $content =~ /<feed .*?>(.*?)<entry>/s ) {
+        my $feed_info = $1;
+        while ( $feed_info =~ m{<(?!link)(\w+).*?>(.*)</\1>}sg ) {
+            $feed->{$1} = decode_entities($2);
+        }
+    }
+
+    while ( $content =~ m{<entry>(.*?)</entry>}sg ) {
+        my $entry_info = $1;
+        my $entry      = {};
+        while ( $entry_info =~ m{<(?!link)(\w+).*?>(.*)</\1>}sg ) {
+            my $value = $2;
+            $value =~ s!\s*<(\w+)>(.*?)</\1>\s*!$2!g;
+            $entry->{$1} = decode_entities($value);
+        }
+        push @$entries, $entry;
+    }
+    return ( $feed, $entries );
+}
+
+no Any::Moose;
+1;
+
+__END__
+
+=head1 NAME
+
+Net::Google::Code::Role::Atom - Atom Role
+
+
+=head1 DESCRIPTION
+
+=head1 INTERFACE
+
+=over 4
+
+=item parse_atom( $xml_content )
+
+return( $feed, $entries ),
+$feed is a hashref like
+{
+    'title' => 'Issue updates for project net-google-code on Google Code',
+    'id' => 'http://code.google.com/feeds/p/net-google-code/issueupdates/basic',
+    'updated' => '2009-06-12T05:55:48Z'
+}
+
+$entries is an arrayref like
+[
+    {
+        'content' => '<pre>second comment
+ </pre>
+ ',
+        'name'  => 'sunnavy',
+        'title' => 'Update 2 to issue 22 ("for sd test")',
+        'id' =>
+'http://code.google.com/feeds/p/net-google-code/issueupdates/basic/22/2',
+        'updated' => '2009-06-12T05:55:48Z'
+    },
+    {
+        'content' => '<pre>first comment
+ </pre>
+ ',
+        'name'  => 'sunnavy',
+        'title' => 'Update 1 to issue 22 ("for sd test")',
+        'id' =>
+'http://code.google.com/feeds/p/net-google-code/issueupdates/basic/22/1',
+        'updated' => '2009-06-12T05:55:22Z'
+    },
+]
+
+=back
+
+=head1 AUTHOR
+
+sunnavy  C<< <sunnavy at bestpractical.com> >>
+
+=head1 LICENCE AND COPYRIGHT
+
+Copyright 2009 Best Practical Solutions.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+


More information about the Bps-public-commit mailing list