Feed/Format/Atom.pm

filter: Statementstmt 90.4% 95 / 105 Branchbran 53.8% 14 / 26 Conditioncond 60.0% 6 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 88.3% 38 / 43 Podpod 75.0% 21 / 28 totaltotal 80.7% 176 / 218 CC 19 SCAR 9.4
CC
19
Cov
82%
_rel_link
9.4
__ANON__
6.0
__ANON__
6.0
CRAP 2.6
« Feed/Entry.pm ↑ Summary Feed/Content.pm »
1 package XML::Feed::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 );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶use XML::Atom::Feed;
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 List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 35 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 35 ▶use XML::Atom::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 35 XML::Atom::Entry->mk_elem_accessors(qw( lat long ), ['http://www.w3.org/2003/01/geo/wgs84_pos#']);
16  
17 35 ▶use XML::Atom::Content;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 35 ▶use XML::Feed::Entry::Format::Atom;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 36 ▶sub identify {
Subroutine identify: called CC=1 SCAR=0.0
Pod undocumented
21 36 my $class = shift;
22 36 my $xml = shift;
23 36 my $tag = $class->_get_first_tag($xml);
24 36 return ($tag eq 'feed');
25 }
26  
27  
28 7 ▶sub init_empty {
Subroutine init_empty: called CC=2 SCAR=7.0
Pod undocumented
29 7 my ($feed, %args) = @_;
30 7 ▶ $args{'Version'} //= '1.0';
Condition50%1/2
$args{"Version"} //= "1.0"
l!l
07
MC/DC0%0/1
$args{"Version"} //= "1.0"
$args{"Version"}
Truth table50%1/2
A
A= $args{"Version"}
Aresult
11
00
31  
32 7 $feed->{atom} = XML::Atom::Feed->new(%args);
33 7 $feed;
34 }
35  
36 18 ▶sub init_string {
Subroutine init_string: called CC=3 SCAR=11.3
Pod undocumented
37 18 my $feed = shift;
38 18 my($str) = @_;
39 18 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 18 0 18
40 18 ▶ $feed->{atom} = XML::Atom::Feed->new(Stream => $str)
Branch: 1 branch
BranchTrueFalseTotal
$feed->{"atom"} = "XML::Atom::Feed"->new("Stream", $str) or return $feed->error("XML::Atom::Feed"->errstr) 18 0 18
41 or return $feed->error(XML::Atom::Feed->errstr);
42 }
43 18 $feed;
44 }
45  
46 3 ▶sub format { 'Atom' }
Subroutine format: called CC=1 SCAR=0.0
Pod documented
47  
48 16 ▶sub title { shift->{atom}->title(@_) }
Subroutine title: called CC=1 SCAR=0.0
Pod documented
49 12 ▶sub link {
Subroutine link: called CC=3 SCAR=11.0
Pod documented
50 12 my $feed = shift;
51 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 5 7 12
52 5 $feed->{atom}->add_link({ rel => 'alternate', href => $_[0],
53 type => 'text/html', });
54 } else {
55 7 ▶ my $l = first { !defined $_->rel || $_->rel eq 'alternate' } $feed->{atom}->link;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not defined $_->rel or $_->rel eq "alternate" 2 6 8
56 7 ▶ $l ? $l->href : undef;
Branch: 1 branch
BranchTrueFalseTotal
$l ? : 7 0 7
57 }
58 }
59  
60 8 ▶sub _rel_link {
Subroutine _rel_link: called CC=4 SCAR=22.4
61 8 my $feed = shift;
62 8 my $rel = shift;
63 8 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 8 0 8
64 8 my $uri = shift;
65 8 $feed->{atom}->add_link({type => "application/atom+xml", rel => $rel, href => $uri});
66 8 return $uri;
67 }
68 else
69 {
70 0 my $l;
71  
72 0 ▶ if ($rel eq 'self') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel eq 'self') { } 0 0 0
73 $l = first
74 0 ▶ { !defined $_->rel || $_->rel eq 'self' }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
not defined $_->rel or $_->rel eq "self" 0 0 0
75 0 $feed->{atom}->link;
76 } else {
77 $l = first
78 0 ▶ { !defined $_->rel || $_->rel eq $rel }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
not defined $_->rel or $_->rel eq $rel 0 0 0
79 0 $feed->{atom}->link;
80 }
81  
82 0 ▶ return $l ? $l->href : undef;
Branch: 1 branch
BranchTrueFalseTotal
$l ? : 0 0 0
83 }
84 }
85  
86 1 ▶sub self_link { shift->_rel_link( 'self', @_ ) }
Subroutine self_link: called CC=1 SCAR=0.0
Pod documented
87 1 ▶sub first_link { shift->_rel_link( 'first', @_ ) }
Subroutine first_link: called CC=1 SCAR=0.0
Pod documented
88 1 ▶sub last_link { shift->_rel_link( 'last', @_ ) }
Subroutine last_link: called CC=1 SCAR=0.0
Pod documented
89 1 ▶sub next_link { shift->_rel_link( 'next', @_ ) }
Subroutine next_link: called CC=1 SCAR=0.0
Pod documented
90 1 ▶sub previous_link { shift->_rel_link( 'previous', @_ ) }
Subroutine previous_link: called CC=1 SCAR=0.0
Pod documented
91 1 ▶sub current_link { shift->_rel_link( 'current', @_ ) }
Subroutine current_link: called CC=1 SCAR=0.0
Pod documented
92 1 ▶sub prev_archive_link { shift->_rel_link( 'prev-archive', @_ ) }
Subroutine prev_archive_link: called CC=1 SCAR=0.0
Pod documented
93 1 ▶sub next_archive_link { shift->_rel_link( 'next-archive', @_ ) }
Subroutine next_archive_link: called CC=1 SCAR=0.0
Pod documented
94  
95 14 ▶sub description { shift->{atom}->tagline(@_) }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
96 5 ▶sub copyright { shift->{atom}->copyright(@_) }
Subroutine copyright: called CC=1 SCAR=0.0
Pod documented
97 6 ▶sub language { shift->{atom}->language(@_) }
Subroutine language: called CC=1 SCAR=0.0
Pod documented
98 5 ▶sub generator { shift->{atom}->generator(@_) }
Subroutine generator: called CC=1 SCAR=0.0
Pod documented
99 2 ▶sub id { shift->{atom}->id(@_) }
Subroutine id: called CC=1 SCAR=0.0
Pod undocumented
100 0 ▶sub updated { shift->modified(@_) }
Subroutine updated: not called CC=1 SCAR=6.9
Pod undocumented
101 0 ▶sub add_link { shift->{atom}->add_link(@_) }
Subroutine add_link: not called CC=1 SCAR=6.9
Pod undocumented
102 4 ▶sub base { shift->{atom}->base(@_) }
Subroutine base: called CC=1 SCAR=0.0
Pod documented
103  
104 6 ▶sub author {
Subroutine author: called CC=4 SCAR=13.9
Pod documented
105 6 my $feed = shift;
106 6 ▶ if (@_ && $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $_[0]) { } 2 4 6
Condition66%2/3
@_ and $_[0]
!ll&&!rl&&r
402
MC/DC50%1/2
@_ and $_[0]
@_ $_[0]
Truth table66%2/3
A and B
A= @_B= $_[0]
ABresult
0X0
100
111
107 2 my $person = XML::Atom::Person->new(Version => 1.0);
108 2 $person->name($_[0]);
109 2 $feed->{atom}->author($person);
110 } else {
111 4 ▶ $feed->{atom}->author ? $feed->{atom}->author->name : undef;
Branch: 1 branch
BranchTrueFalseTotal
$feed->{'atom'}->author ? : 3 1 4
112 }
113 }
114  
115 0 ▶sub image {
Subroutine image: not called CC=1 SCAR=6.9
Pod undocumented
116 0 return;
117 }
118  
119 9 ▶sub modified {
Subroutine modified: called CC=3 SCAR=11.0
Pod documented
120 9 my $feed = shift;
121 9 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 3 6 9
122 3 $feed->{atom}->modified(format_w3cdtf($_[0]));
123 } else {
124 6 ▶ parse_datetime($feed->{atom}->modified || $feed->{atom}->updated);
Condition66%2/3
$feed->{'atom'}->modified || $feed->{'atom'}->updated
l!l&&r!l&&!r
501
MC/DC50%1/2
$feed->{'atom'}->modified || $feed->{'atom'}->updated
$feed->{'atom'}->modified $feed->{'atom'}->updated
Truth table66%2/3
A || B
A= $feed->{'atom'}->modifiedB= $feed->{'atom'}->updated
ABresult
1X1
011
000
125 }
126 }
127  
128 19 ▶sub entries {
Subroutine entries: called CC=2 SCAR=6.9
Pod documented
129 19 my @entries;
130 19 for my $entry ($_[0]->{atom}->entries) {
131 26 push @entries, XML::Feed::Entry::Format::Atom->wrap($entry);
132 }
133  
134 19 @entries;
135 }
136  
137 8 ▶sub add_entry {
Subroutine add_entry: called CC=2 SCAR=7.0
Pod documented
138 8 my $feed = shift;
139 8 ▶ my $entry = shift || return;
Condition50%1/2
shift() || (return)
l!l
80
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
140 8 $entry = $feed->_convert_entry($entry);
141 8 $feed->{atom}->add_entry($entry->unwrap);
142 }
143  
144 16 ▶sub as_xml { $_[0]->{atom}->as_xml }
Subroutine as_xml: called CC=1 SCAR=0.0
Pod documented
145  
146 35 1;
« Feed/Entry.pm ↑ Summary Feed/Content.pm »