Feed/Entry/Format/RSS.pm

filter: Statementstmt 17.8% 20 / 112 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 31.8% 7 / 22 Podpod 66.6% 10 / 15 totaltotal 13.6% 37 / 272 CC 44 SCAR 34.8
CC
44
Cov
9%
summary
72.0
content
72.0
category
42.0
CRAP 32.4
↑ Summary Feed.pm »
1 package XML::Feed::Entry::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 0 ▶sub format { 'RSS ' . $_[0]->{'_version'} }
Subroutine format: not called CC=1 SCAR=6.9
Pod undocumented
9  
10 35 ▶use XML::Feed::Content;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 35 ▶use XML::Feed::Util qw( format_w3cdtf parse_mail_date parse_w3cdtf_date );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 35 ▶use base qw( XML::Feed::Entry );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶sub init_empty { $_[0]->{entry} = { } }
Subroutine init_empty: called CC=1 SCAR=0.0
Pod undocumented
16  
17 0 ▶sub base {
Subroutine base: not called CC=2 SCAR=17.9
Pod documented
18 0 my $entry = shift;
19 0 ▶ @_ ? $entry->{entry}->{'xml:base'} = $_[0] : $entry->{entry}->{'xml:base'};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
20 }
21  
22 0 ▶sub title {
Subroutine title: not called CC=2 SCAR=17.9
Pod documented
23 0 my $entry = shift;
24 0 ▶ @_ ? $entry->{entry}{title} = $_[0] : $entry->{entry}{title};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
25 }
26  
27 0 ▶sub link {
Subroutine link: not called CC=5 SCAR=34.0
Pod documented
28 0 my $entry = shift;
29 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
30 0 $entry->{entry}{link} = $_[0];
31 ## For RSS 2.0 output from XML::RSS. Sigh.
32 0 $entry->{entry}{permaLink} = $_[0];
33 } else {
34 my $link = $entry->{entry}{link} //
35 $entry->{entry}{permaLink} //
36 0 ▶ $entry->{entry}{guid};
Condition0%0/6
($entry->{"entry"}{"link"} // $entry->{"entry"}{"permaLink"}) // $entry->{"entry"}{"guid"}
l!l&&r!l&&!r
000
$entry->{"entry"}{"link"} // $entry->{"entry"}{"permaLink"}
l!l&&r!l&&!r
000
MC/DC0%0/3
($entry->{"entry"}{"link"} // $entry->{"entry"}{"permaLink"}) // $entry->{"entry"}{"guid"}
$entry->{"entry"}{"link"} $entry->{"entry"}{"permaLink"} $entry->{"entry"}{"guid"}
Truth table0%0/4
A // B // C
A= $entry->{"entry"}{"link"}B= $entry->{"entry"}{"permaLink"}C= $entry->{"entry"}{"guid"}
ABCresult
1XX1
01X1
0011
0000
37 0 ▶ if (defined $link) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $link) 0 0 0
38 0 $link =~ s/^\s+//;
39 0 $link =~ s/\s+$//;
40 }
41 0 return $link;
42 }
43 }
44  
45 0 ▶sub summary {
Subroutine summary: not called CC=8 SCAR=42.8
Pod documented
46 0 my $entry = shift;
47 0 my $item = $entry->{entry};
48 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
49 0 ▶ $item->{description} = ref($_[0]) eq 'XML::Feed::Content' ?
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'XML::Feed::Content' ? : 0 0 0
50 $_[0]->body : $_[0];
51 0 $entry->{description_is_summary} = 1;
52 } else {
53 ## Some RSS feeds use <description> for a summary, and some use it
54 ## for the full content. Pretty gross. We don't want to return the
55 ## full content if the caller expects a summary, so the heuristic is:
56 ## if the <entry> contains both a <description> and one of the elements
57 ## typically used for the full content, use <description> as summary.
58 0 my $txt;
59 0 ▶ if ($item->{description} &&
Branch: 2 branches
BranchTrueFalseTotal
if ($item->{'description'} and ($entry->{'description_is_summary'} || $entry->_content) // $item->{'http://www.w3.org/1999/xhtml'}{'body'}) { } 0 0 0
elsif ($item->{'http://www.w3.org/2005/Atom'}{'summary'}) { } 0 0 0
Condition0%0/9
$item->{"description"} and ($entry->{"description_is_summary"} || $entry->_content) // $item->{"http://www.w3.org/1999/xhtml"}{"body"}
!ll&&!rl&&r
000
($entry->{"description_is_summary"} || $entry->_content) // $item->{"http://www.w3.org/1999/xhtml"}{"body"}
l!l&&r!l&&!r
000
$entry->{"description_is_summary"} or $entry->_content
l!l&&r!l&&!r
000
MC/DC0%0/4
$item->{"description"} and ($entry->{"description_is_summary"} || $entry->_content) // $item->{"http://www.w3.org/1999/xhtml"}{"body"}
$item->{"description"} $entry->{"description_is_summary"} $entry->_content $item->{"http://www.w3.org/1999/xhtml"}{"body"}
Truth table0%0/5
A and B or C // D
A= $item->{"description"}B= $entry->{"description_is_summary"}C= $entry->_contentD= $item->{"http://www.w3.org/1999/xhtml"}{"body"}
ABCDresult
0XXX0
10000
11XX1
101X1
10011
60 ($entry->{description_is_summary} ||
61 $entry->_content //
62 $item->{'http://www.w3.org/1999/xhtml'}{body})) {
63 0 $txt = $item->{description};
64 ## Blogspot's 'short' RSS feeds do this in the Atom namespace
65 ## for no obviously good reason.
66 } elsif ($item->{'http://www.w3.org/2005/Atom'}{summary}) {
67 0 $txt = $item->{'http://www.w3.org/2005/Atom'}{summary};
68 }
69 0 XML::Feed::Content->wrap({ type => 'text/plain', body => $txt });
70 }
71 }
72  
73 # Get contentfrom HASH ref or scalar.
74 0 ▶sub _content {
Subroutine _content: not called CC=2 SCAR=17.9
75 0 my $entry = shift;
76 0 my $content = $entry->{entry}{content};
77 0 ▶ return ref $content ? $content->{encoded} : $content;
Branch: 1 branch
BranchTrueFalseTotal
ref $content ? : 0 0 0
78 }
79  
80 0 ▶sub content {
Subroutine content: not called CC=8 SCAR=42.8
Pod documented
81 0 my $entry = shift;
82 0 my $item = $entry->{entry};
83 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
84 0 my $c;
85 0 ▶ if (ref($_[0]) eq 'XML::Feed::Content') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'XML::Feed::Content') { } 0 0 0
86 0 ▶ if (defined $_[0]->base) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]->base) { } 0 0 0
87 0 $c = { 'content' => $_[0]->body, 'xml:base' => $_[0]->base };
88 } else {
89 0 $c = $_[0]->body;
90 }
91 } else {
92 0 $c = $_[0];
93 }
94 0 ▶ $item->{content} = {} unless ref $item->{content};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item->{"content"} 0 0 0
95 0 $item->{content}{encoded} = $c;
96 } else {
97 0 my $base;
98 my $body =
99 $entry->_content //
100 $item->{'http://www.w3.org/1999/xhtml'}{body} //
101 0 ▶ $item->{description};
Condition0%0/6
($entry->_content // $item->{"http://www.w3.org/1999/xhtml"}{"body"}) // $item->{"description"}
l!l&&r!l&&!r
000
$entry->_content // $item->{"http://www.w3.org/1999/xhtml"}{"body"}
l!l&&r!l&&!r
000
MC/DC0%0/3
($entry->_content // $item->{"http://www.w3.org/1999/xhtml"}{"body"}) // $item->{"description"}
$entry->_content $item->{"http://www.w3.org/1999/xhtml"}{"body"} $item->{"description"}
Truth table0%0/4
A // B // C
A= $entry->_contentB= $item->{"http://www.w3.org/1999/xhtml"}{"body"}C= $item->{"description"}
ABCresult
1XX1
01X1
0011
0000
102 0 ▶ if ('HASH' eq ref($body)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("HASH" eq ref $body) 0 0 0
103 0 $base = $body->{'xml:base'};
104 0 $body = $body->{content};
105 }
106 0 XML::Feed::Content->wrap({ type => 'text/html', body => $body, base => $base });
107 }
108 }
109  
110 0 ▶sub category {
Subroutine category: not called CC=6 SCAR=37.4
Pod documented
111 0 my $entry = shift;
112 0 my $item = $entry->{entry};
113 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
114 0 my @tmp = ($entry->category, @_);
115 0 $item->{category} = [@tmp];
116 0 $item->{dc}{subject} = [@tmp];
117 } else {
118 0 ▶ my $r = $item->{category} // $item->{dc}{subject};
Condition0%0/3
$item->{"category"} // $item->{"dc"}{"subject"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$item->{"category"} // $item->{"dc"}{"subject"}
$item->{"category"} $item->{"dc"}{"subject"}
Truth table0%0/3
A // B
A= $item->{"category"}B= $item->{"dc"}{"subject"}
ABresult
1X1
011
000
119 0 ▶ my @r = ref($r) eq 'ARRAY' ? @$r : defined $r? ($r) : ();
Branch: 2 branches
BranchTrueFalseTotal
ref $r eq 'ARRAY' ? : 0 0 0
defined $r ? : 0 0 0
120 0 ▶ return wantarray? @r : $r[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
121 }
122 }
123  
124 0 ▶sub author {
Subroutine author: not called CC=3 SCAR=24.8
Pod documented
125 0 my $item = shift->{entry};
126 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
127 0 $item->{author} = $item->{dc}{creator} = $_[0];
128 } else {
129 0 ▶ $item->{author} // $item->{dc}{creator};
Condition0%0/3
$item->{"author"} // $item->{"dc"}{"creator"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$item->{"author"} // $item->{"dc"}{"creator"}
$item->{"author"} $item->{"dc"}{"creator"}
Truth table0%0/3
A // B
A= $item->{"author"}B= $item->{"dc"}{"creator"}
ABresult
1X1
011
000
130 }
131 }
132  
133 ## XML::RSS doesn't give us access to the rdf:about for the <item>,
134 ## so we have to fall back to the <link> element in RSS 1.0 feeds.
135 0 ▶sub id {
Subroutine id: not called CC=4 SCAR=30.0
Pod documented
136 0 my $item = shift->{entry};
137 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
138 0 $item->{guid} = $_[0];
139 } else {
140 0 ▶ $item->{guid} // $item->{permaLink} // $item->{link};
Condition0%0/6
($item->{"guid"} // $item->{"permaLink"}) // $item->{"link"}
l!l&&r!l&&!r
000
$item->{"guid"} // $item->{"permaLink"}
l!l&&r!l&&!r
000
MC/DC0%0/3
($item->{"guid"} // $item->{"permaLink"}) // $item->{"link"}
$item->{"guid"} $item->{"permaLink"} $item->{"link"}
Truth table0%0/4
A // B // C
A= $item->{"guid"}B= $item->{"permaLink"}C= $item->{"link"}
ABCresult
1XX1
01X1
0011
0000
141 }
142 }
143  
144 0 ▶sub issued {
Subroutine issued: not called CC=4 SCAR=30.0
Pod documented
145 0 my $item = shift->{entry};
146 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
147 0 $item->{dc}{date} = format_w3cdtf($_[0]);
148 0 $item->{pubDate} = DateTime::Format::Mail->format_datetime($_[0]);
149 } else {
150 return parse_mail_date($item->{pubDate})
151 0 ▶ || parse_w3cdtf_date($item->{dc}{date} || $item->{dcterms}{date});
Condition0%0/6
parse_mail_date($item->{'pubDate'}) || parse_w3cdtf_date($item->{'dc'}{'date'} || $item->{'dcterms'}{'date'})
l!l&&r!l&&!r
000
$item->{'dc'}{'date'} || $item->{'dcterms'}{'date'}
l!l&&r!l&&!r
000
MC/DC0%0/2
parse_mail_date($item->{'pubDate'}) || parse_w3cdtf_date($item->{'dc'}{'date'} || $item->{'dcterms'}{'date'})
parse_mail_date($item->{'pubDate'}) parse_w3cdtf_date($item->{'dc'}{'date'} || $item->{'dcterms'}{'date'})
MC/DC0%0/2
$item->{'dc'}{'date'} || $item->{'dcterms'}{'date'}
$item->{'dc'}{'date'} $item->{'dcterms'}{'date'}
Truth table0%0/3
A || B
A= parse_mail_date($item->{'pubDate'})B= parse_w3cdtf_date($item->{'dc'}{'date'} || $item->{'dcterms'}{'date'})
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $item->{'dc'}{'date'}B= $item->{'dcterms'}{'date'}
ABresult
1X1
011
000
152 }
153 }
154  
155 0 ▶sub modified {
Subroutine modified: not called CC=3 SCAR=24.8
Pod documented
156 0 my $item = shift->{entry};
157 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
158 0 $item->{dcterms}{modified} = format_w3cdtf($_[0]);
159 } else {
160 return parse_w3cdtf_date(
161 $item->{dcterms}{modified} || $item->{atom}{updated}
162 0 ▶ );
Condition0%0/3
$item->{'dcterms'}{'modified'} || $item->{'atom'}{'updated'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$item->{'dcterms'}{'modified'} || $item->{'atom'}{'updated'}
$item->{'dcterms'}{'modified'} $item->{'atom'}{'updated'}
Truth table0%0/3
A || B
A= $item->{'dcterms'}{'modified'}B= $item->{'atom'}{'updated'}
ABresult
1X1
011
000
163 }
164 }
165  
166 0 ▶sub lat {
Subroutine lat: not called CC=2 SCAR=17.9
Pod undocumented
167 0 my $item = shift->{entry};
168 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
169 0 $item->{geo}{lat} = $_[0];
170 } else {
171 0 return $item->{geo}{lat};
172 }
173 }
174  
175 0 ▶sub long {
Subroutine long: not called CC=2 SCAR=17.9
Pod undocumented
176 0 my $item = shift->{entry};
177 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
178 0 $item->{geo}{long} = $_[0];
179 } else {
180 0 return $item->{geo}{long};
181 }
182 }
183  
184 0 ▶sub enclosure {
Subroutine enclosure: not called CC=6 SCAR=37.4
Pod undocumented
185 0 my $entry = shift;
186  
187 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
188 0 my $enclosure = shift;
189 my $val = {
190 url => $enclosure->{url},
191 type => $enclosure->{type},
192 length => $enclosure->{length}
193 0 };
194 0 ▶ if ($XML::Feed::MULTIPLE_ENCLOSURES) {
Branch: 1 branch
BranchTrueFalseTotal
if ($XML::Feed::MULTIPLE_ENCLOSURES) { } 0 0 0
195 0 push @{$entry->{entry}->{enclosure}}, $val;
196 } else {
197 0 $entry->{entry}->{enclosure} = $val;
198 }
199 } else {
200 0 my $tmp = $entry->{entry}->{enclosure};
201 0 ▶ if (defined $tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp) 0 0 0
202 0 ▶ my @encs = map { XML::Feed::Enclosure->new($_) }
Branch: 1 branch
BranchTrueFalseTotal
ref $tmp eq 'ARRAY' ? : 0 0 0
203 (ref $tmp eq 'ARRAY')? @$tmp : ($tmp);
204 0 ▶ return ($XML::Feed::MULTIPLE_ENCLOSURES)? @encs : $encs[-1];
Branch: 1 branch
BranchTrueFalseTotal
$XML::Feed::MULTIPLE_ENCLOSURES ? : 0 0 0
205 }
206 0 return;
207 }
208 }
209  
210 35 1;
211  
↑ Summary Feed.pm »