Feed/Format/RSS.pm

filter: Statementstmt 38.3% 41 / 107 Branchbran 5.0% 1 / 20 Conditioncond 15.7% 3 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 35.1% 13 / 37 Podpod 77.7% 21 / 27 totaltotal 35.5% 79 / 222 CC 19 SCAR 16.1
CC
19
Cov
31%
language
12.0
generator
12.0
author
12.0
CRAP 5.0
« Feed/Entry/Format/Atom.pm ↑ Summary Feed/Entry.pm »
1 package XML::Feed::Format::RSS;
2 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 35 our $VERSION = '1.0.1';
7  
8 35 ▶use base qw( XML::Feed );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶use DateTime::Format::Mail;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 35 ▶use DateTime::Format::W3CDTF;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 35 ▶use XML::Feed::Enclosure;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 35 ▶use XML::Feed::Entry::Format::RSS;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 35 ▶use XML::Feed::Util qw( parse_mail_date parse_w3cdtf_date );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 35 our $PREFERRED_PARSER = "XML::RSS";
16  
17 18 ▶sub identify {
Subroutine identify: called CC=2 SCAR=7.0
Pod undocumented
18 18 my $class = shift;
19 18 my $xml = shift;
20 18 my $tag = $class->_get_first_tag($xml);
21 18 ▶ return ($tag eq 'rss' || $tag eq 'RDF');
Condition66%2/3
$tag eq 'rss' || $tag eq 'RDF'
l!l&&r!l&&!r
1350
MC/DC0%0/2
$tag eq 'rss' || $tag eq 'RDF'
$tag eq 'rss' $tag eq 'RDF'
Truth table66%2/3
A || B
A= $tag eq 'rss'B= $tag eq 'RDF'
ABresult
1X1
011
000
22 }
23  
24 24 ▶sub init_empty {
Subroutine init_empty: called CC=3 SCAR=15.8
Pod undocumented
25 24 my ($feed, %args) = @_;
26 24 ▶ $args{'version'} //= '2.0';
Condition50%1/2
$args{"version"} //= "2.0"
l!l
024
MC/DC0%0/1
$args{"version"} //= "2.0"
$args{"version"}
Truth table50%1/2
A
A= $args{"version"}
Aresult
11
00
27 0 ▶ eval "use $PREFERRED_PARSER"; die $@ if $@;
Subroutine BEGIN: called CC=1 SCAR=0.8
Branch: 1 branch
BranchTrueFalseTotal
if $@ 24 0 24
28 0 $feed->{rss} = $PREFERRED_PARSER->new(%args);
29 0 $feed->{rss}->add_module(prefix => "content", uri => 'http://purl.org/rss/1.0/modules/content/');
30 0 $feed->{rss}->add_module(prefix => "dcterms", uri => 'http://purl.org/dc/terms/');
31 0 $feed->{rss}->add_module(prefix => "atom", uri => 'http://www.w3.org/2005/Atom');
32 0 $feed->{rss}->add_module(prefix => "geo", uri => 'http://www.w3.org/2003/01/geo/wgs84_pos#');
33 0 $feed;
34 }
35  
36 18 ▶sub init_string {
Subroutine init_string: called CC=3 SCAR=19.2
Pod undocumented
37 18 my $feed = shift;
38 18 my($str) = @_;
39 18 $feed->init_empty;
40 0 my $opts = {
41 hashrefs_instead_of_strings => 1,
42 };
43 0 ▶ $opts->{allow_multiple} = [ 'enclosure' ] if $XML::Feed::MULTIPLE_ENCLOSURES;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Feed::MULTIPLE_ENCLOSURES 0 0 0
44 0 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 0 0 0
45 0 $feed->{rss}->parse($$str, $opts );
46 }
47 0 $feed;
48 }
49  
50 0 ▶sub format { 'RSS ' . $_[0]->{rss}->{'version'} }
Subroutine format: not called CC=1 SCAR=6.9
Pod documented
51  
52 ## The following elements are the same in all versions of RSS.
53 0 ▶sub title { shift->{rss}->channel('title', @_) }
Subroutine title: not called CC=1 SCAR=6.9
Pod documented
54 0 ▶sub link {
Subroutine link: not called CC=1 SCAR=6.9
Pod documented
55 0 my $link = shift->{rss}->channel('link', @_);
56 0 $link =~ s/^\s+//;
57 0 $link =~ s/\s+$//;
58 0 return $link;
59 }
60 0 ▶sub description { shift->{rss}->channel('description', @_) }
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
61 0 ▶sub updated { shift->modified(@_) }
Subroutine updated: not called CC=1 SCAR=6.9
Pod undocumented
62  
63 # This doesn't exist in RSS
64 0 ▶sub id { }
Subroutine id: not called CC=1 SCAR=0.0
Pod undocumented
65  
66 ## This is RSS 2.0 only--what's the equivalent in RSS 1.0?
67 0 ▶sub copyright { shift->{rss}->channel('copyright', @_) }
Subroutine copyright: not called CC=1 SCAR=6.9
Pod documented
68  
69 0 ▶sub base {
Subroutine base: not called CC=2 SCAR=17.9
Pod documented
70 0 my $feed = shift;
71 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
72 0 $feed->{rss}->{'xml:base'} = $_[0];
73 } else {
74 0 $feed->{rss}->{'xml:base'};
75 }
76 }
77  
78 ## The following all work transparently in any RSS version.
79 0 ▶sub language {
Subroutine language: not called CC=3 SCAR=24.8
Pod documented
80 0 my $feed = shift;
81 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
82 0 $feed->{rss}->channel('language', $_[0]);
83 0 $feed->{rss}->channel->{dc}{language} = $_[0];
84 } else {
85 $feed->{rss}->channel('language') //
86 0 ▶ $feed->{rss}->channel->{dc}{language};
Condition0%0/3
$feed->{"rss"}->channel("language") // $feed->{"rss"}->channel->{"dc"}{"language"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$feed->{"rss"}->channel("language") // $feed->{"rss"}->channel->{"dc"}{"language"}
$feed->{"rss"}->channel("language") $feed->{"rss"}->channel->{"dc"}{"language"}
Truth table0%0/3
A // B
A= $feed->{"rss"}->channel("language")B= $feed->{"rss"}->channel->{"dc"}{"language"}
ABresult
1X1
011
000
87 }
88 }
89  
90 0 ▶sub self_link {
Subroutine self_link: not called CC=2 SCAR=17.9
Pod documented
91 0 my $feed = shift;
92  
93 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
94 0 my $uri = shift;
95  
96 0 $feed->{rss}->channel->{'atom'}{'link'} =
97 {
98 rel => "self",
99 href => $uri,
100 type => "application/rss+xml",
101 };
102 }
103  
104 0 return $feed->{rss}->channel->{'atom'}{'link'};
105 }
106  
107 # This doesn't exist in RSS
108 0 ▶sub first_link { }
Subroutine first_link: not called CC=1 SCAR=0.0
Pod documented
109 0 ▶sub last_link { }
Subroutine last_link: not called CC=1 SCAR=0.0
Pod documented
110 0 ▶sub previous_link { }
Subroutine previous_link: not called CC=1 SCAR=0.0
Pod documented
111 0 ▶sub next_link { }
Subroutine next_link: not called CC=1 SCAR=0.0
Pod documented
112 0 ▶sub current_link { }
Subroutine current_link: not called CC=1 SCAR=0.0
Pod documented
113 0 ▶sub prev_archive_link { }
Subroutine prev_archive_link: not called CC=1 SCAR=0.0
Pod documented
114 0 ▶sub next_archive_link { }
Subroutine next_archive_link: not called CC=1 SCAR=0.0
Pod documented
115  
116 0 ▶sub generator {
Subroutine generator: not called CC=3 SCAR=24.8
Pod documented
117 0 my $feed = shift;
118 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
119 0 $feed->{rss}->channel('generator', $_[0]);
120 $feed->{rss}->channel->{'http://webns.net/mvcb/'}{generatorAgent} =
121 0 $_[0];
122 } else {
123 $feed->{rss}->channel('generator') //
124 0 ▶ $feed->{rss}->channel->{'http://webns.net/mvcb/'}{generatorAgent};
Condition0%0/3
$feed->{"rss"}->channel("generator") // $feed->{"rss"}->channel->{"http://webns.net/mvcb/"}{"generatorAgent"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$feed->{"rss"}->channel("generator") // $feed->{"rss"}->channel->{"http://webns.net/mvcb/"}{"generatorAgent"}
$feed->{"rss"}->channel("generator") $feed->{"rss"}->channel->{"http://webns.net/mvcb/"}{"generatorAgent"}
Truth table0%0/3
A // B
A= $feed->{"rss"}->channel("generator")B= $feed->{"rss"}->channel->{"http://webns.net/mvcb/"}{"generatorAgent"}
ABresult
1X1
011
000
125 }
126 }
127  
128 0 ▶sub author {
Subroutine author: not called CC=3 SCAR=24.8
Pod documented
129 0 my $feed = shift;
130 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
131 0 $feed->{rss}->channel('webMaster', $_[0]);
132 0 $feed->{rss}->channel->{dc}{creator} = $_[0];
133 } else {
134 $feed->{rss}->channel('webMaster') //
135 0 ▶ $feed->{rss}->channel->{dc}{creator};
Condition0%0/3
$feed->{"rss"}->channel("webMaster") // $feed->{"rss"}->channel->{"dc"}{"creator"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$feed->{"rss"}->channel("webMaster") // $feed->{"rss"}->channel->{"dc"}{"creator"}
$feed->{"rss"}->channel("webMaster") $feed->{"rss"}->channel->{"dc"}{"creator"}
Truth table0%0/3
A // B
A= $feed->{"rss"}->channel("webMaster")B= $feed->{"rss"}->channel->{"dc"}{"creator"}
ABresult
1X1
011
000
136 }
137 }
138  
139 0 ▶sub modified {
Subroutine modified: not called CC=3 SCAR=24.8
Pod documented
140 0 my $rss = shift->{rss};
141 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
142 0 $rss->channel('pubDate',
143 DateTime::Format::Mail->format_datetime($_[0]));
144 ## XML::RSS is so weird... if I set this, it will try to use
145 ## the value for the lastBuildDate, which I don't want--because
146 ## this date is formatted for an RSS 1.0 feed. So it's commented out.
147 #$rss->channel->{dc}{date} =
148 # DateTime::Format::W3CDTF->format_datetime($_[0]);
149 } else {
150 return parse_mail_date($rss->channel('pubDate'))
151 0 ▶ || parse_w3cdtf_date($rss->channel->{dc}{date});
Condition0%0/3
parse_mail_date($rss->channel('pubDate')) || parse_w3cdtf_date($rss->channel->{'dc'}{'date'})
l!l&&r!l&&!r
000
MC/DC0%0/2
parse_mail_date($rss->channel('pubDate')) || parse_w3cdtf_date($rss->channel->{'dc'}{'date'})
parse_mail_date($rss->channel('pubDate')) parse_w3cdtf_date($rss->channel->{'dc'}{'date'})
Truth table0%0/3
A || B
A= parse_mail_date($rss->channel('pubDate'))B= parse_w3cdtf_date($rss->channel->{'dc'}{'date'})
ABresult
1X1
011
000
152 }
153 }
154  
155 0 ▶sub image {
Subroutine image: not called CC=2 SCAR=17.9
Pod undocumented
156 0 my $self = shift;
157 0 my $rss = $self->{rss};
158  
159 0 ▶ return @_ ? $rss->image(@_) : $rss->image('url');
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
160 }
161  
162 0 ▶sub entries {
Subroutine entries: not called CC=2 SCAR=17.9
Pod documented
163 0 my $rss = $_[0]->{rss};
164 0 my @entries;
165 0 for my $item (@{ $rss->{items} }) {
166 0 push @entries, XML::Feed::Entry::Format::RSS->wrap($item);
167 0 $entries[-1]->{_version} = $rss->{'version'};
168 }
169 0 @entries;
170 }
171  
172 0 ▶sub add_entry {
Subroutine add_entry: not called CC=2 SCAR=17.9
Pod documented
173 0 my $feed = shift;
174 0 ▶ my $entry = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
175 0 $entry = $feed->_convert_entry($entry);
176 0 $feed->{rss}->add_item(%{ $entry->unwrap });
177 }
178  
179 0 ▶sub as_xml { $_[0]->{rss}->as_string }
Subroutine as_xml: not called CC=1 SCAR=6.9
Pod documented
180  
181 35 1;
182  
« Feed/Entry/Format/Atom.pm ↑ Summary Feed/Entry.pm »