blib/lib/XML/RSS/FromAtom.pm

filter: Statementstmt 44.4% 20 / 45 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 38.8% 28 / 72 CC 9 SCAR 39.3
CC
9
Cov
33%
atom_to_rss
90.0
parse
2.0
BEGIN
1.0
CRAP 51.1
↑ Summary
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 ▶use base 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use DateTime::Format::Mail;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 our $VERSION = '0.02';
37  
38 0 ▶sub parse {
Subroutine parse: not called CC=1 SCAR=6.9
Pod documented
39 0 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 0 ▶sub atom_to_rss {
Subroutine atom_to_rss: not called CC=9 SCAR=45.0
Pod documented
50 0 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 ▶ $retval->channel(title => $feed_title->text_value) if ($feed_title);
Branch: 1 branch
BranchTrueFalseTotal
if $feed_title 0 0 0
58  
59 0 my ($feed_description) = $doc->query('/feed/tagline');
60 0 ▶ $retval->channel(description => $feed_description->text_value) if ($feed_description);
Branch: 1 branch
BranchTrueFalseTotal
if $feed_description 0 0 0
61  
62 0 my ($feed_link) = $doc->query('/feed/link/@href');
63 0 ▶ $retval->channel(link => $feed_link) if ($feed_link);
Branch: 1 branch
BranchTrueFalseTotal
if $feed_link 0 0 0
64  
65 0 foreach ($doc->query('//entry')) {
66 0 my $desc = '';
67 0 ▶ $desc = $_->query('summary')->text_value if defined $_->query('summary');
Branch: 1 branch
BranchTrueFalseTotal
if defined $_->query("summary") 0 0 0
68 0 ▶ if (defined $_->query('content') &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_->query("content") and length $_->query("content")->text_value > length $desc) 0 0 0
Condition0%0/3
defined $_->query("content") and length $_->query("content")->text_value > length $desc
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_->query("content") and length $_->query("content")->text_value > length $desc
defined $_->query("content") length $_->query("content")->text_value > length $desc
Truth table0%0/3
A and B
A= defined $_->query("content")B= length $_->query("content")->text_value > length $desc
ABresult
0X0
100
111
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 ▶ $retval->add_item(
Branch: 1 branch
BranchTrueFalseTotal
$author ? : 0 0 0
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 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<< <marcus@thiesen.org> >>
145  
146 =head1 BUGS
147  
148 Please report any bugs or feature requests to
149 C<bug-xml-rss-fromatom@rt.cpan.org>, or through the web interface at
150 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-RSS-FromAtom>.
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<XML::RSS> L<XML::Atom::Syndication>
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
↑ Summary