Changeset 1846

Show
Ignore:
Timestamp:
11/25/06 11:46:22
Author:
miyagawa
Message:

Namespace::Geo: added Atom support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/feature-geo/plagger/lib/Plagger/Plugin/Namespace/Geo.pm

    r1842 r1846  
    1515    my $geo_ns = "http://www.w3.org/2003/01/geo/wgs84_pos#"; 
    1616 
    17     # XXX for now RSS only, do the same for Atom 
    18     my $geo = $args->{orig_entry}->{entry}->{$geo_ns} || {}; 
    19        $geo = $geo->{Point}->{geo} if $geo->{Point}; 
    20     if (defined($geo->{lat}) && defined($geo->{long})) { 
    21         my $loc = Plagger::Location->new; 
    22         $loc->latitude($geo->{lat}); 
    23         $loc->longitude($geo->{long}); 
    24         $args->{entry}->location($loc); 
     17    my $entry = $args->{orig_entry}->{entry}; 
     18 
     19    if (ref($entry) eq 'XML::Atom::Entry') { 
     20        my($lat, $long) = map $entry->get($geo_ns, $_), qw( lat long ); 
     21        if (defined $lat && defined $long) { 
     22            $args->{entry}->location($lat, $long); 
     23        } 
     24    } 
     25    elsif (ref($entry) eq 'HASH') { 
     26        my $geo = $entry->{$geo_ns} || {}; 
     27        $geo = $geo->{Point}->{geo} if $geo->{Point}; 
     28        if (defined($geo->{lat}) && defined($geo->{long})) { 
     29            $args->{entry}->location($geo->{lat}, $geo->{long}); 
     30        } 
    2531    } 
    2632} 
     
    4551 
    4652Jean-Yves Stervinou 
     53Tatsuhiko Miyagawa 
    4754 
    4855=head1 SEE ALSO 
  • branches/feature-geo/plagger/t/plugins/Namespace-Geo/base.t

    r1842 r1846  
    44 
    55test_plugin_deps; 
    6 plan tests => 4
     6plan 'no_plan'
    77run_eval_expected; 
    88 
     
    2020        - file://$t::TestPlagger::BaseDirURI/t/samples/rss2-geo.xml 
    2121        - file://$t::TestPlagger::BaseDirURI/t/samples/rss2-geo-point.xml 
     22        - file://$t::TestPlagger::BaseDirURI/t/samples/atom-geo.xml 
    2223  - module: Namespace::Geo 
    2324  - module: Aggregator::Simple 
     
    2829is $feeds[1]->entries->[0]->location->latitude, 26.58; 
    2930is $feeds[1]->entries->[0]->location->longitude, -97.83; 
     31 
     32is $feeds[2]->entries->[0]->location->latitude, 26.58; 
     33is $feeds[2]->entries->[0]->location->longitude, -97.83; 
     34is $feeds[2]->entries->[1]->location->latitude, 26.58; 
     35is $feeds[2]->entries->[1]->location->longitude, -97.83;