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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Fri Jun 19 20:58:30 EDT 2009


Author: sunnavy
Date: Fri Jun 19 20:58:30 2009
New Revision: 20036

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

Log:
Atom role => AtomParser class

Added: Net-Google-Code/trunk/lib/Net/Google/Code/AtomParser.pm
==============================================================================
--- (empty file)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/AtomParser.pm	Fri Jun 19 20:58:30 2009
@@ -0,0 +1,100 @@
+package Net::Google::Code::AtomParser;
+use strict;
+use warnings;
+
+use Params::Validate ':all';
+use HTML::Entities;
+
+sub new {
+    my $class = shift;
+    bless \(my $a), $class;
+}
+
+sub parse {
+    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 );
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Net::Google::Code::AtomParser - AtomParser with a parsing method for gcode
+
+=head1 DESCRIPTION
+
+=head1 INTERFACE
+
+=head2 new
+
+=head2 parse( $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'
+    },
+]
+
+=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/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	Fri Jun 19 20:58:30 2009
@@ -6,7 +6,6 @@
 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;
 
@@ -36,7 +35,9 @@
     my @results;
 
     my $content = $self->fetch( $self->base_feeds_url . 'issueupdates/basic' );
-    my ( $feed, $entries ) = $self->parse_atom( $content );
+    require Net::Google::Code::AtomParser;
+    my $atom_parser = Net::Google::Code::AtomParser->new;
+    my ( $feed, $entries ) = $atom_parser->parse( $content );
     if (@$entries) {
         my $min_updated =
           Net::Google::Code::DateTime->new_from_string( $entries->[-1]->{updated} );



More information about the Bps-public-commit mailing list