File Coverage

blib/lib/XML/RSS/FromAtom.pm
Criterion Covered Total %
statement 18 43 41.8
branch 0 12 0.0
condition 0 3 0.0
subroutine 6 8 75.0
pod 2 2 100.0
total 26 68 38.2


line stmt bran cond sub pod time code
1             ########################################################################
2             #
3             # XML::RSS::FromAtom
4             #
5             # Copyright 2005, Marcus Thiesen (marcus@thiesen.org) All rights reserved.
6             #
7             # This program is free software; you can redistribute it and/or modify
8             # it under the terms of either:
9             #
10             # a) the GNU General Public License as published by the Free Software
11             # Foundation; either version 1, or (at your option) any later
12             # version, or
13             #
14             # b) the "Artistic License" which comes with Perl.
15             #
16             # On Debian GNU/Linux systems, the complete text of the GNU General
17             # Public License can be found in `/usr/share/common-licenses/GPL' and
18             # the Artistic Licence in `/usr/share/common-licenses/Artistic'.
19             #
20             # This program is distributed in the hope that it will be useful,
21             # but WITHOUT ANY WARRANTY; without even the implied warranty of
22             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23             #
24             ########################################################################
25              
26             package XML::RSS::FromAtom;
27              
28 1     1   20892 use strict;
  1         3  
  1         40  
29 1     1   5 use warnings;
  1         3  
  1         28  
30              
31 1     1   6 use base 'Class::Accessor';
  1         7  
  1         843  
32 1     1   3302 use DateTime;
  1         196971  
  1         45  
33 1     1   1351 use DateTime::Format::ISO8601;
  1         54411  
  1         88  
34 1     1   1290 use DateTime::Format::Mail;
  1         2566  
  1         478  
35              
36             our $VERSION = '0.02';
37              
38             sub parse {
39 0     0 1   my $self = shift;
40 0           my $text = shift;
41            
42 0           require XML::Atom::Syndication;
43              
44 0           my $atomic = XML::Atom::Syndication->instance;
45              
46 0           return $self->atom_to_rss($atomic->parse($text));
47             }
48              
49             sub atom_to_rss {
50 0     0 1   my $self = shift;
51 0           my $doc = shift;
52              
53 0           require XML::RSS;
54 0           my $retval = new XML::RSS(version => '2.0');
55              
56 0           my ($feed_title) = $doc->query('/feed/title');
57 0 0         $retval->channel(title => $feed_title->text_value) if ($feed_title);
58              
59 0           my ($feed_description) = $doc->query('/feed/tagline');
60 0 0         $retval->channel(description => $feed_description->text_value) if ($feed_description);
61              
62 0           my ($feed_link) = $doc->query('/feed/link/@href');
63 0 0         $retval->channel(link => $feed_link) if ($feed_link);
64              
65 0           foreach ($doc->query('//entry')) {
66 0           my $desc = '';
67 0 0         $desc = $_->query('summary')->text_value if defined $_->query('summary');
68 0 0 0       if (defined $_->query('content') &&
69             length $_->query('content')->text_value > length $desc) {
70 0           $desc = $_->query('content')->text_value;
71             }
72              
73 0           my $dt = DateTime::Format::ISO8601->parse_datetime( $_->query('modified')->text_value );
74              
75 0           my ($link) = $_->query('link/@href');
76 0           my ($author) = $_->query('author/name');
77              
78 0 0         $retval->add_item(
79             title => $_->query('title')->text_value,
80             link => $link,
81             description => $desc,
82             pubDate => DateTime::Format::Mail->format_datetime($dt),
83             author => $author ? $author->text_value : undef,
84             );
85             }
86              
87 0           return $retval;
88             }
89              
90             1;
91              
92             =pod
93              
94             =head1 NAME
95              
96             XML::RSS::FromAtom - create a XML::RSS object out of an Atom feed
97              
98             =head1 SYNOPSIS
99              
100             require XML::RSS::FromAtom;
101             use LWP::Simple;
102            
103             my $atom2rss = new XML::RSS::FromAtom;
104             my $data = get 'http://ntess.blogspot.com/atom.xml';
105              
106             my $rss = $atom2rss->parse($data);
107             #$rss->isa('XML::RSS');
108              
109             # - OR -
110             require XML::Atom::Syndication;
111             my $atomic = XML::Atom::Syndication->instance;
112             my $doc = $atomic->get('http://www.timaoutloud.org/xml/atom.xml');
113              
114             my $rss2 = $atom2rss->atom_to_rss($doc);
115             #$rss2->isa('XML::RSS');
116              
117              
118             =head1 DESCRIPTION
119              
120             XML::RSS::FromAtom converts a Atom style feed into an XML::RSS object.
121              
122             =head1 METHODS
123              
124             =over
125              
126             =item new( )
127              
128             Instanciates a new XML::RSS::FromAtom object
129              
130             =item parse( $string )
131              
132             Parses contents of $string as an Atom feed (using XML::Atom::Syncdication) and returns
133             it as an XML::RSS object.
134              
135             =item atom_to_rss ( $object )
136              
137             Converts an XML::Atom::Syndication::Element as returned by XML::Atom::Syndication get into
138             an XML::RSS object.
139              
140             =back
141              
142             =head1 AUTHOR
143              
144             Marcus Thiesen, C<< >>
145              
146             =head1 BUGS
147              
148             Please report any bugs or feature requests to
149             C, or through the web interface at
150             L.
151             I will be notified, and then you'll automatically be notified of progress on
152             your bug as I make changes.
153              
154             =head1 SEE ALSO
155              
156             L L
157              
158             =head1 COPYRIGHT & LICENSE
159              
160             Copyright 2005 Marcus Thiesen, All Rights Reserved.
161              
162             This program is free software; you can redistribute it and/or modify it
163             under the same terms as Perl itself.
164              
165             =head1 CVS
166              
167             $Id: FromAtom.pm,v 1.1 2005/03/18 17:04:44 marcus Exp $
168              
169             =cut