blib/lib/XML/Feed/Format/hAtom.pm

filter: Statementstmt 83.2% 109 / 131 Branchbran 58.8% 20 / 34 Conditioncond 56.5% 13 / 23 MC/DCmcdc 40.0% 6 / 15 Subroutinesub 80.7% 42 / 52 Podpod 95.4% 21 / 22 totaltotal 76.1% 211 / 277 CC 27 SCAR 15.0
CC
27
Cov
76%
_do_geo
30.0
_do_geo
9.3
_do_text
6.0
CRAP 4.5
↑ Summary
1 package XML::Feed::Format::hAtom;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use base qw( XML::Feed );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Data::Microformat::hFeed;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Data::Microformat::hCard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Data::Microformat::geo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 our $VERSION = "0.5";
10  
11 8 ▶sub identify {
Subroutine identify: called CC=1 SCAR=0.0
Pod documented
12 8 my $class = shift;
13 8 my $xml = shift;
14 8 my $tag = $class->_get_first_tag($xml);
15 8 return ($tag eq 'html');
16 }
17  
18 2 ▶sub init_empty {
Subroutine init_empty: called CC=1 SCAR=0.0
Pod undocumented
19 2 my ($feed, %args) = @_;
20  
21 2 $feed->{hatom} = Data::Microformat::hFeed->new(%args);
22 2 $feed;
23 }
24  
25 8 ▶sub init_string {
Subroutine init_string: called CC=3 SCAR=11.2
Pod documented
26 8 my $feed = shift;
27 8 my ($str) = @_;
28 8 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 8 0 8
29 8 eval { $feed->{hatom} = Data::Microformat::hFeed->parse($str) };
30 8 ▶ return $feed->error($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 8 8
31 }
32 8 $feed;
33 }
34  
35 3 ▶sub format { 'hAtom' }
Subroutine format: called CC=1 SCAR=0.0
Pod documented
36  
37 5 ▶sub tagline { shift->{hatom}->tagline(@_) }
Subroutine tagline: called CC=1 SCAR=0.0
Pod documented
38 5 ▶sub description { shift->{hatom}->tagline(@_) }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
39 9 ▶sub title { shift->{hatom}->title(@_) }
Subroutine title: called CC=1 SCAR=0.0
Pod documented
40 5 ▶sub link { shift->{hatom}->link(@_) }
Subroutine link: called CC=1 SCAR=0.0
Pod documented
41 1 ▶sub self_link { shift->{hatom}->link(@_) }
Subroutine self_link: called CC=1 SCAR=0.0
Pod documented
42 3 ▶sub generator { shift->{hatom}->generator(@_) }
Subroutine generator: called CC=1 SCAR=0.0
Pod documented
43 0 ▶sub id { shift->{hatom}->id(@_) }
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
44 0 ▶sub updated { shift->{hatom}->modified(@_) }
Subroutine updated: not called CC=1 SCAR=6.9
Pod documented
45 6 ▶sub modified { shift->{hatom}->modified(@_) }
Subroutine modified: called CC=1 SCAR=0.0
Pod documented
46 3 ▶sub copyright {
Subroutine copyright: called CC=4 SCAR=14.1
Pod documented
47 3 my $feed = shift;
48 3 ▶ if (@_ && defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and defined $_[0]) { } 1 2 3
Condition66%2/3
@_ and defined $_[0]
!ll&&!rl&&r
201
MC/DC50%1/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table66%2/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
49 1 $feed->{hatom}->copyright({ text => $_[0] });
50 } else {
51 2 ▶ $feed->{hatom}->copyright ? $feed->{hatom}->copyright->{text} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$feed->{'hatom'}->copyright ? : 2 0 2
52 }
53 }
54  
55 0 ▶sub lat { shift->_do_geo('longitude', @_) }
Subroutine lat: not called CC=1 SCAR=6.9
Pod documented
56 0 ▶sub long { shift->_do_geo('longitude', @_) }
Subroutine long: not called CC=1 SCAR=6.9
Pod documented
57  
58 0 ▶sub _do_geo {
Subroutine _do_geo: not called CC=5 SCAR=34.0
59 0 my $thing = shift;
60 0 my $what = shift;
61 0 my $geo = $thing->geo;
62  
63 0 ▶ if (@_ && defined $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ and defined $_[0]) { } 0 0 0
elsif (defined $geo) { } 0 0 0
Condition0%0/3
@_ and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table0%0/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
64 0 ▶ $geo = Data::Microformat::geo->new unless defined $geo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $geo 0 0 0
65 0 $geo->$what($_[0]);
66 0 $thing->geo($geo);
67 } elsif (defined $geo) {
68 0 return $geo->$what;
69 } else {
70 0 return undef;
71 }
72 }
73  
74 0 ▶sub category { shift->{hatom}->categories(@_) }
Subroutine category: not called CC=1 SCAR=6.9
Pod documented
75  
76 5 ▶sub language { shift->{hatom}->language(@_) }
Subroutine language: called CC=1 SCAR=0.0
Pod documented
77  
78 # TODO
79 # add_link
80  
81 5 ▶sub author {
Subroutine author: called CC=4 SCAR=14.0
Pod documented
82 5 my $feed = shift;
83 5 ▶ if (@_ && defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and defined $_[0]) { } 1 4 5
Condition66%2/3
@_ and defined $_[0]
!ll&&!rl&&r
401
MC/DC50%1/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table66%2/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
84 1 my $person = Data::Microformat::hCard->new;
85 1 $person->fn($_[0]);
86 1 $feed->{hatom}->author($person);
87 } else {
88 4 ▶ $feed->{hatom}->author ? $feed->{hatom}->author->fn : undef;
Branch: 1 branch
BranchTrueFalseTotal
$feed->{'hatom'}->author ? : 4 0 4
89 }
90 }
91  
92 6 ▶sub entries {
Subroutine entries: called CC=2 SCAR=6.9
Pod documented
93 6 my @entries;
94 6 for my $entry ($_[0]->{hatom}->entries) {
95 9 push @entries, XML::Feed::Entry::Format::hAtom->wrap($entry);
96 }
97 6 @entries;
98 }
99  
100 3 ▶sub add_entry {
Subroutine add_entry: called CC=2 SCAR=7.0
Pod documented
101 3 my $feed = shift;
102 3 ▶ my $entry = shift || return;
Condition50%1/2
shift() || (return)
l!l
30
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
103 3 $entry = $feed->_convert_entry($entry);
104 3 $feed->{hatom}->entries($entry->{entry});
105 }
106  
107 3 ▶sub as_xml { shift->{hatom}->to_html }
Subroutine as_xml: called CC=1 SCAR=0.0
Pod documented
108  
109 package XML::Feed::Entry::Format::hAtom;
110 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 6 ▶use base qw( XML::Feed::Entry );
Subroutine BEGIN: called CC=1 SCAR=0.0
113 6 ▶use XML::Feed::Content;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 6 ▶use Data::Microformat::hFeed::hEntry;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 6 ▶use Data::Microformat::geo;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 6 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118 3 ▶sub init_empty {
Subroutine init_empty: called CC=1 SCAR=0.0
119 3 my $entry = shift;
120 3 $entry->{entry} = Data::Microformat::hFeed::hEntry->new;
121 3 $entry;
122 }
123  
124 10 ▶sub title { shift->{entry}->title(@_) }
Subroutine title: called CC=1 SCAR=0.0
125 0 ▶sub source { shift->{entry}->source(@_) }
Subroutine source: not called CC=1 SCAR=6.9
126 0 ▶sub updated { shift->{entry}->updated(@_) }
Subroutine updated: not called CC=1 SCAR=6.9
127 0 ▶sub base { shift->{entry}->base(@_) }
Subroutine base: not called CC=1 SCAR=6.9
128 7 ▶sub link { shift->{entry}->link(@_) }
Subroutine link: called CC=1 SCAR=0.0
129 7 ▶sub id { shift->{entry}->id(@_) }
Subroutine id: called CC=1 SCAR=0.0
130 8 ▶sub issued { shift->{entry}->issued(@_) }
Subroutine issued: called CC=1 SCAR=0.0
131 6 ▶sub modified { shift->{entry}->modified(@_) }
Subroutine modified: called CC=1 SCAR=0.0
132  
133 3 ▶sub lat { shift->_do_geo('longitude', @_) }
Subroutine lat: called CC=1 SCAR=0.0
134 3 ▶sub long { shift->_do_geo('longitude', @_) }
Subroutine long: called CC=1 SCAR=0.0
135  
136 6 ▶sub _do_geo {
Subroutine _do_geo: called CC=5 SCAR=22.3
137 6 my $thing = shift;
138 6 my $what = shift;
139 6 my $geo = $thing->{entry}->geo;
140  
141 6 ▶ if (@_ && defined $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ and defined $_[0]) { } 0 6 6
elsif (defined $geo) { } 0 6 6
Condition33%1/3
@_ and defined $_[0]
!ll&&!rl&&r
600
MC/DC0%0/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table33%1/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
142 0 ▶ $geo = Data::Microformat::geo->new unless defined $geo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $geo 0 0 0
143 0 $geo->$what($_[0]);
144 0 $thing->geo($geo);
145 } elsif (defined $geo) {
146 0 return $geo->$what;
147 } else {
148 6 return undef;
149 }
150 }
151  
152  
153 10 ▶sub summary { shift->_do_text('summary', @_) }
Subroutine summary: called CC=1 SCAR=0.0
154 15 ▶sub content { shift->_do_text('content', @_) }
Subroutine content: called CC=1 SCAR=0.0
155  
156 25 ▶sub _do_text {
Subroutine _do_text: called CC=6 SCAR=17.9
157 25 my $entry = shift;
158 25 my $field = shift;
159 25 ▶ if (@_ && defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and defined $_[0]) { } 7 18 25
Condition66%2/3
@_ and defined $_[0]
!ll&&!rl&&r
1807
MC/DC50%1/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table66%2/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
160 7 ▶ if (ref($_[0]) eq 'XML::Feed::Content') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'XML::Feed::Content') { } 3 4 7
161 3 ▶ my $content = (defined $_[0]->type && $_[0]->type eq 'text/plain') ? encode_entities($_[0]->body) : $_[0]->body;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->type && $_[0]->type eq 'text/plain' ? : 1 2 3
Condition100%3/3
defined $_[0]->type and $_[0]->type eq "text/plain"
!ll&&!rl&&r
111
MC/DC100%2/2
defined $_[0]->type and $_[0]->type eq "text/plain"
defined $_[0]->type $_[0]->type eq "text/plain"
Truth table100%3/3
A and B
A= defined $_[0]->typeB= $_[0]->type eq "text/plain"
ABresult
0X0
100
111
162 3 $entry->{entry}->$field($content);
163 } else {
164 4 $entry->{entry}->$field($_[0]);
165 }
166 } else {
167 18 return XML::Feed::Content->new({ type => 'text/html', body => $entry->{entry}->$field });
168 }
169 }
170  
171 9 ▶sub category { shift->{entry}->tags(@_) }
Subroutine category: called CC=1 SCAR=0.0
172  
173 7 ▶sub author {
Subroutine author: called CC=4 SCAR=13.9
174 7 my $entry = shift;
175 7 ▶ if (@_ && $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $_[0]) { } 1 6 7
Condition66%2/3
@_ and $_[0]
!ll&&!rl&&r
601
MC/DC50%1/2
@_ and $_[0]
@_ $_[0]
Truth table66%2/3
A and B
A= @_B= $_[0]
ABresult
0X0
100
111
176 1 my $person = Data::Microformat::hCard->new;
177 1 $person->fn($_[0]);
178 1 $entry->{entry}->author($person);
179 } else {
180 6 ▶ $entry->{entry}->author ? $entry->{entry}->author->fn : undef;
Branch: 1 branch
BranchTrueFalseTotal
$entry->{'entry'}->author ? : 5 1 6
181 }
182 }
183  
184 0 ▶sub as_xml { shift->{entry}->to_html }
Subroutine as_xml: not called CC=1 SCAR=6.9
185  
186 6 1;
187  
188 __END__
↑ Summary