Feed/Entry/Format/Atom.pm

filter: Statementstmt 94.4% 120 / 127 Branchbran 73.0% 57 / 78 Conditioncond 53.3% 16 / 30 MC/DCmcdc 20.0% 4 / 20 Subroutinesub 89.2% 25 / 28 Podpod 52.6% 10 / 19 totaltotal 76.8% 232 / 302 CC 51 SCAR 17.0
CC
51
Cov
82%
summary
10.4
get_content
9.3
set_content
8.1
CRAP 5.5
« Feed/Util.pm ↑ Summary Feed/Format/RSS.pm »
1 package XML::Feed::Entry::Format::Atom;
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::Entry );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶use XML::Feed::Content;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 35 ▶use XML::Feed::Util qw( format_w3cdtf parse_datetime );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 35 ▶use XML::Atom::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 35 ▶use List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶sub init_empty {
Subroutine init_empty: called CC=1 SCAR=0.0
Pod undocumented
15 8 my $entry = shift;
16 8 $entry->{entry} = XML::Atom::Entry->new(Version => 1.0);
17 8 1;
18 }
19  
20 0 ▶sub format { 'Atom' }
Subroutine format: not called CC=1 SCAR=6.9
Pod undocumented
21  
22 13 ▶sub title { shift->{entry}->title(@_) }
Subroutine title: called CC=1 SCAR=0.0
Pod documented
23 0 ▶sub source { shift->{entry}->source(@_) }
Subroutine source: not called CC=1 SCAR=6.9
Pod undocumented
24 0 ▶sub updated { shift->modified(@_) }
Subroutine updated: not called CC=1 SCAR=6.9
Pod undocumented
25 4 ▶sub base { shift->{entry}->base(@_) }
Subroutine base: called CC=1 SCAR=0.0
Pod documented
26  
27 15 ▶sub link {
Subroutine link: called CC=3 SCAR=11.0
Pod documented
28 15 my $entry = shift;
29 15 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 6 9 15
30 6 $entry->{entry}->add_link({ rel => 'alternate', href => $_[0],
31 type => 'text/html', });
32 } else {
33 9 ▶ my $l = first { !defined $_->rel || $_->rel eq 'alternate' } $entry->{entry}->link;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not defined $_->rel or $_->rel eq "alternate" 2 7 9
34 9 ▶ $l ? $l->href : undef;
Branch: 1 branch
BranchTrueFalseTotal
$l ? : 9 0 9
35 }
36 }
37  
38 9 ▶sub summary {
Subroutine summary: called CC=9 SCAR=23.4
Pod documented
39 9 my $entry = shift;
40  
41 9 my %type_correction = (
42 html => 'text/html',
43 text => 'text/plain',
44 xhtml => 'text/html',
45 );
46  
47 9 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 3 6 9
48 3 my %param;
49 3 ▶ if (ref($_[0]) eq 'XML::Feed::Content') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'XML::Feed::Content') { } 2 1 3
50 2 %param = (Body => $_[0]->body);
51 } else {
52 1 %param = (Body => $_[0]);
53 }
54 3 $entry->{entry}->summary(XML::Atom::Content->new(%param, Version => 1.0));
55 } else {
56 6 my $s = $entry->{entry}->summary;
57 # map Atom types to MIME types
58 6 ▶ my $type = ($s && ref($s) eq 'XML::Feed::Content') ? $s->type : undef;
Branch: 1 branch
BranchTrueFalseTotal
$s && ref $s eq 'XML::Feed::Content' ? : 0 6 6
Condition66%2/3
$s and ref $s eq "XML::Feed::Content"
!ll&&!rl&&r
150
MC/DC0%0/2
$s and ref $s eq "XML::Feed::Content"
$s ref $s eq "XML::Feed::Content"
Truth table66%2/3
A and B
A= $sB= ref $s eq "XML::Feed::Content"
ABresult
0X0
100
111
59 6 ▶ if ($type and exists $type_correction{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and exists $type_correction{$type}) 0 6 6
Condition33%1/3
$type and exists $type_correction{$type}
!ll&&!rl&&r
600
MC/DC0%0/2
$type and exists $type_correction{$type}
$type exists $type_correction{$type}
Truth table33%1/3
A and B
A= $typeB= exists $type_correction{$type}
ABresult
0X0
100
111
60 0 $type = $type_correction{$type};
61 }
62 6 my $body = $s;
63 6 ▶ if (defined $s && ref($s) eq 'XML::Feed::Content') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and ref $s eq "XML::Feed::Content") 0 6 6
Condition66%2/3
defined $s and ref $s eq "XML::Feed::Content"
!ll&&!rl&&r
150
MC/DC0%0/2
defined $s and ref $s eq "XML::Feed::Content"
defined $s ref $s eq "XML::Feed::Content"
Truth table66%2/3
A and B
A= defined $sB= ref $s eq "XML::Feed::Content"
ABresult
0X0
100
111
64 0 $body = $s->body;
65 }
66 6 XML::Feed::Content->wrap({ type => $type,
67 body => $body });
68 }
69 }
70  
71 35 my %types = (
72 'text/xhtml' => 'xhtml',
73 'text/html' => 'html',
74 'text/plain' => 'text',
75 );
76  
77 23 ▶sub content {
Subroutine content: called CC=2 SCAR=6.9
Pod documented
78 23 my $entry = shift;
79 23 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 7 16 23
80 7 return $entry->set_content(@_);
81 } else {
82 16 return $entry->get_content;
83 }
84 }
85  
86 7 ▶sub set_content {
Subroutine set_content: called CC=8 SCAR=20.9
Pod undocumented
87 7 my $entry = shift;
88  
89 7 my %param;
90 my $base;
91 7 my $orig_body;
92 7 ▶ if (ref($_[0]) eq 'XML::Feed::Content') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'XML::Feed::Content') { } 4 3 7
93 4 $orig_body = $_[0]->body;
94 4 ▶ if (defined $_[0]->type && defined $types{$_[0]->type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]->type and defined $types{$_[0]->type}) { } 4 0 4
Condition33%1/3
defined $_[0]->type and defined $types{$_[0]->type}
!ll&&!rl&&r
004
MC/DC0%0/2
defined $_[0]->type and defined $types{$_[0]->type}
defined $_[0]->type defined $types{$_[0]->type}
Truth table33%1/3
A and B
A= defined $_[0]->typeB= defined $types{$_[0]->type}
ABresult
0X0
100
111
95 4 %param = (Body => $orig_body, Type => $types{$_[0]->type});
96  
97 4 ▶ if ($param{'Type'} eq "html") {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{"Type"} eq "html") 3 1 4
98 3 $param{'Body'} = HTML::Entities::encode_entities($param{'Body'});
99 }
100 } else {
101 }
102 4 ▶ $base = $_[0]->base if defined $_[0]->base;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0]->base 2 2 4
103 } else {
104 3 $orig_body = $_[0];
105 }
106 7 ▶ if (!exists($param{Body}))
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $param{"Body"}) 3 4 7
107 {
108 3 $param{Body} = $orig_body;
109 }
110 7 $entry->{entry}->content(XML::Atom::Content->new(%param, Version => 1.0));
111 # Assigning again so the type will be normalized. This seems to be
112 # an XML-Atom do-what-I-don't-meannery.
113 7 $entry->{entry}->content->body($orig_body);
114 7 ▶ $entry->{entry}->content->base($base) if defined $base;
Branch: 1 branch
BranchTrueFalseTotal
if defined $base 2 5 7
115 }
116  
117 16 ▶sub get_content {
Subroutine get_content: called CC=8 SCAR=22.3
Pod undocumented
118 16 my $entry = shift;
119  
120 16 my $c = $entry->{entry}->content;
121  
122 # map Atom types to MIME types
123 16 ▶ my $type = $c ? $c->type : undef;
Branch: 1 branch
BranchTrueFalseTotal
$c ? : 16 0 16
124 16 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 16 0 16
125 16 ▶ $type = 'text/html' if $type eq 'xhtml' || $type eq 'html';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "xhtml" or $type eq "html" 11 5 16
Condition66%2/3
$type eq "xhtml" or $type eq "html"
l!l&&r!l&&!r
1105
MC/DC50%1/2
$type eq "xhtml" or $type eq "html"
$type eq "xhtml" $type eq "html"
Truth table66%2/3
A or B
A= $type eq "xhtml"B= $type eq "html"
ABresult
1X1
011
000
126 16 ▶ $type = 'text/plain' if $type eq 'text';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "text" 0 16 16
127 }
128  
129 16 ▶ XML::Feed::Content->wrap({ type => $type,
Branch: 2 branches
BranchTrueFalseTotal
$c ? : 16 0 16
$c ? : 16 0 16
130 base => $c ? $c->base : undef,
131 body => $c ? $c->body : undef });
132 }
133  
134 16 ▶sub category {
Subroutine category: called CC=7 SCAR=19.7
Pod documented
135 16 my $entry = shift;
136 16 my $ns = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/');
137 16 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 5 11 16
138 5 $entry->{entry}->add_category({ term => $_ }) for @_;
139 5 return 1;
140 } else {
141  
142  
143 11 ▶ my @category = ($entry->{entry}->can('categories')) ? $entry->{entry}->categories : $entry->{entry}->category;
Branch: 1 branch
BranchTrueFalseTotal
$entry->{'entry'}->can('categories') ? : 11 0 11
144 my @return = @category
145 16 ▶ ? (map { $_->label // $_->term } @category)
Condition33%1/3
$_->label // $_->term
l!l&&r!l&&!r
0160
MC/DC0%0/2
$_->label // $_->term
$_->label $_->term
Truth table33%1/3
A // B
A= $_->labelB= $_->term
ABresult
1X1
011
000
146 11 ▶ : $entry->{entry}->getlist($ns, 'subject');
Branch: 1 branch
BranchTrueFalseTotal
@category ? : 6 5 11
147  
148 11 ▶ return wantarray? @return : $return[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 4 11
149 }
150 }
151  
152 10 ▶sub author {
Subroutine author: called CC=4 SCAR=14.0
Pod documented
153 10 my $entry = shift;
154 10 ▶ if (@_ && $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $_[0]) { } 5 5 10
Condition66%2/3
@_ and $_[0]
!ll&&!rl&&r
505
MC/DC50%1/2
@_ and $_[0]
@_ $_[0]
Truth table66%2/3
A and B
A= @_B= $_[0]
ABresult
0X0
100
111
155 5 my $person = XML::Atom::Person->new(Version => 1.0);
156 5 $person->name($_[0]);
157 5 $entry->{entry}->author($person);
158 } else {
159 5 ▶ $entry->{entry}->author ? $entry->{entry}->author->name : undef;
Branch: 1 branch
BranchTrueFalseTotal
$entry->{'entry'}->author ? : 5 0 5
160 }
161 }
162  
163 16 ▶sub id { shift->{entry}->id(@_) }
Subroutine id: called CC=1 SCAR=0.0
Pod documented
164  
165 9 ▶sub issued {
Subroutine issued: called CC=4 SCAR=14.1
Pod documented
166 9 my $entry = shift;
167 9 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 3 6 9
168 3 ▶ $entry->{entry}->issued(format_w3cdtf($_[0])) if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 3 0 3
169 } else {
170 6 ▶ parse_datetime($entry->{entry}->issued || $entry->{entry}->published);
Condition66%2/3
$entry->{'entry'}->issued || $entry->{'entry'}->published
l!l&&r!l&&!r
501
MC/DC50%1/2
$entry->{'entry'}->issued || $entry->{'entry'}->published
$entry->{'entry'}->issued $entry->{'entry'}->published
Truth table66%2/3
A || B
A= $entry->{'entry'}->issuedB= $entry->{'entry'}->published
ABresult
1X1
011
000
171 }
172 }
173  
174 11 ▶sub modified {
Subroutine modified: called CC=4 SCAR=14.1
Pod documented
175 11 my $entry = shift;
176 11 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 4 7 11
177 4 ▶ $entry->{entry}->modified(format_w3cdtf($_[0])) if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 4 0 4
178 } else {
179 7 ▶ parse_datetime($entry->{entry}->modified || $entry->{entry}->updated);
Condition66%2/3
$entry->{'entry'}->modified || $entry->{'entry'}->updated
l!l&&r!l&&!r
601
MC/DC50%1/2
$entry->{'entry'}->modified || $entry->{'entry'}->updated
$entry->{'entry'}->modified $entry->{'entry'}->updated
Truth table66%2/3
A || B
A= $entry->{'entry'}->modifiedB= $entry->{'entry'}->updated
ABresult
1X1
011
000
180 }
181 }
182  
183 3 ▶sub lat {
Subroutine lat: called CC=3 SCAR=14.2
Pod undocumented
184 3 my $entry = shift;
185 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 3 3
186 0 ▶ $entry->{entry}->lat($_[0]) if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
187 } else {
188 3 $entry->{entry}->lat;
189 }
190 }
191  
192 3 ▶sub long {
Subroutine long: called CC=3 SCAR=14.2
Pod undocumented
193 3 my $entry = shift;
194 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 3 3
195 0 ▶ $entry->{entry}->long($_[0]) if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 0 0
196 } else {
197 3 $entry->{entry}->long;
198 }
199 }
200  
201  
202 8 ▶sub enclosure {
Subroutine enclosure: called CC=6 SCAR=18.0
Pod undocumented
203 8 my $entry = shift;
204  
205 8 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 6 8
206 2 my $enclosure = shift;
207 2 ▶ my $method = ($XML::Feed::MULTIPLE_ENCLOSURES)? 'add_link' : 'link';
Branch: 1 branch
BranchTrueFalseTotal
$XML::Feed::MULTIPLE_ENCLOSURES ? : 1 1 2
208 $entry->{entry}->$method({ rel => 'enclosure', href => $enclosure->{url},
209 length => $enclosure->{length},
210 2 type => $enclosure->{type} });
211 2 return 1;
212 } else {
213 6 ▶ my @links = grep { defined $_->rel && $_->rel eq 'enclosure' } $entry->{entry}->link;
Condition33%1/3
defined $_->rel && $_->rel eq 'enclosure'
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $_->rel && $_->rel eq 'enclosure'
defined $_->rel $_->rel eq 'enclosure'
Truth table33%1/3
A && B
A= defined $_->relB= $_->rel eq 'enclosure'
ABresult
0X0
100
111
214 6 ▶ return unless @links;
Branch: 1 branch
BranchTrueFalseTotal
unless @links 0 6 6
215 my @encs = map {
216 6 XML::Feed::Enclosure->new({
217 url => $_->href, length => $_->length, type => $_->type
218 })
219 } @links ;
220 6 ▶ return ($XML::Feed::MULTIPLE_ENCLOSURES)? @encs : $encs[-1];
Branch: 1 branch
BranchTrueFalseTotal
$XML::Feed::MULTIPLE_ENCLOSURES ? : 3 3 6
221 }
222 }
223  
224  
225 35 1;
226  
« Feed/Util.pm ↑ Summary Feed/Format/RSS.pm »