blib/lib/XML/FeedPP.pm

filter: Statementstmt 90.8% 1213 / 1335 Branchbran 75.4% 531 / 704 Conditioncond 66.0% 212 / 321 MC/DCmcdc 39.0% 73 / 187 Subroutinesub 85.4% 194 / 227 Podpod 54.5% 24 / 44 totaltotal 79.7% 2247 / 2818 CC 490 SCAR 23.6
CC
490
Cov
83%
image
156.0
init_feed
25.1
link
20.5
CRAP 10.6
↑ Summary
1 =head1 NAME
2  
3 XML::FeedPP -- Parse/write/merge/edit RSS/RDF/Atom syndication feeds
4  
5 =head1 SYNOPSIS
6  
7 Get an RSS file and parse it:
8  
9 use XML::FeedPP ();
10 my $source = 'http://use.perl.org/index.rss';
11 my $feed = XML::FeedPP->new( $source );
12 print "Title: ", $feed->title(), "\n";
13 print "Date: ", $feed->pubDate(), "\n";
14 foreach my $item ( $feed->get_item() ) {
15 print "URL: ", $item->link(), "\n";
16 print "Title: ", $item->title(), "\n";
17 }
18  
19 Generate an RDF file and save it:
20  
21 use XML::FeedPP ();
22 my $feed = XML::FeedPP::RDF->new();
23 $feed->title( "use Perl" );
24 $feed->link( "http://use.perl.org/" );
25 $feed->pubDate( "Thu, 23 Feb 2006 14:43:43 +0900" );
26 my $item = $feed->add_item( "http://search.cpan.org/~kawasaki/XML-TreePP-0.02" );
27 $item->title( "Pure Perl implementation for parsing/writing xml file" );
28 $item->pubDate( "2006-02-23T14:43:43+09:00" );
29 $feed->to_file( "index.rdf" );
30  
31 Convert some RSS/RDF files to Atom format:
32  
33 use XML::FeedPP ();
34 my $feed = XML::FeedPP::Atom::Atom10->new(); # create empty atom file
35 $feed->merge( "rss.xml" ); # load local RSS file
36 $feed->merge( "http://www.kawa.net/index.rdf" ); # load remote RDF file
37 my $now = time();
38 $feed->pubDate( $now ); # touch date
39 my $atom = $feed->to_string(); # get Atom source code
40  
41 =head1 DESCRIPTION
42  
43 C<XML::FeedPP> is an all-purpose syndication utility that parses and
44 publishes RSS 2.0, RSS 1.0 (RDF), Atom 0.3 and 1.0 feeds.
45 It allows you to add new content, merge feeds, and convert among
46 these various formats.
47 It is a pure Perl implementation and does not require any other
48 module except for XML::TreePP.
49  
50 =head1 METHODS FOR FEED
51  
52 =head2 $feed = XML::FeedPP->new( "index.rss" );
53  
54 This constructor method creates an C<XML::FeedPP> feed instance. The only
55 argument is the local filename. The format of $source must be one of
56 the supported feed formats -- RSS, RDF or Atom -- or execution is
57 halted.
58  
59 =head2 $feed = XML::FeedPP->new( "http://use.perl.org/index.rss" );
60  
61 The URL on the remote web server is also available as the first argument.
62 L<LWP::UserAgent> is required to download it.
63  
64 =head2 $feed = XML::FeedPP->new( '<rss version="2.0">...' );
65  
66 The XML source code is also available as the first argument.
67  
68 =head2 $feed = XML::FeedPP->new( $source, -type => $type );
69  
70 The C<-type> argument allows you to specify type of $source
71 from choice of C<'file'>, C<'url'> or C<'string'>.
72  
73 =head2 $feed = XML::FeedPP->new( $source, utf8_flag => 1 );
74  
75 This makes utf8 flag on for all feed elements.
76 Perl 5.8.1 or later is required to use this.
77  
78 Note that any other options for C<XML::TreePP> constructor are also
79 allowed like this. See more detail on L<XML::TreePP>.
80  
81 =head2 $feed = XML::FeedPP::RSS->new( $source );
82  
83 This constructor method creates an instance for an RSS 2.0 feed.
84 The first argument is optional, but must be valid an RSS source if specified.
85 This method returns an empty instance when $source is undefined.
86  
87 =head2 $feed = XML::FeedPP::RDF->new( $source );
88  
89 This constructor method creates an instance for RSS 1.0 (RDF) feed.
90 The first argument is optional, but must be an RDF source if specified.
91 This method returns an empty instance when $source is undefined.
92  
93 =head2 $feed = XML::FeedPP::Atom->new( $source );
94  
95 This constructor method creates an instance for an Atom 0.3/1.0 feed.
96 The first argument is optional, but must be an Atom source if specified.
97 This method returns an empty instance when $source is undefined.
98  
99 Atom 1.0 feed is also supported since C<XML::FeedPP> version 0.30.
100 Atom 0.3 is still default, however, future version of this module
101 would create Atom 1.0 as default.
102  
103 =head2 $feed = XML::FeedPP::Atom::Atom03->new();
104  
105 This creates an empty Atom 0.3 instance obviously.
106  
107 =head2 $feed = XML::FeedPP::Atom::Atom10->new();
108  
109 This creates an empty Atom 1.0 instance intended.
110  
111 =head2 $feed = XML::FeedPP::RSS->new( link => $link, title => $tile, ... );
112  
113 This creates a RSS instance which has C<link>, C<title> elements etc.
114  
115 =head2 $feed->load( $source );
116  
117 This method loads an RSS/RDF/Atom file,
118 much like C<new()> method does.
119  
120 =head2 $feed->merge( $source );
121  
122 This method merges an RSS/RDF/Atom file into the existing $feed
123 instance. Top-level metadata from the imported feed is incorporated
124 only if missing from the present feed.
125  
126 =head2 $string = $feed->to_string( $encoding );
127  
128 This method generates XML source as string and returns it. The output
129 $encoding is optional, and the default encoding is 'UTF-8'. On Perl
130 5.8 and later, any encodings supported by the Encode module are
131 available. On Perl 5.005 and 5.6.1, only four encodings supported by
132 the Jcode module are available: 'UTF-8', 'Shift_JIS', 'EUC-JP' and
133 'ISO-2022-JP'. 'UTF-8' is recommended for overall compatibility.
134  
135 =head2 $string = $feed->to_string( indent => 4 );
136  
137 This makes the output more human readable by indenting appropriately.
138 This does not strictly follow the XML specification but does looks nice.
139  
140 Note that any other options for C<XML::TreePP> constructor are also
141 allowed like this. See more detail on L<XML::TreePP>.
142  
143 =head2 $feed->to_file( $filename, $encoding );
144  
145 This method generate an XML file. The output $encoding is optional,
146 and the default is 'UTF-8'.
147  
148 =head2 $item = $feed->add_item( $link );
149  
150 This method creates a new item/entry and returns its instance.
151 A mandatory $link argument is the URL of the new item/entry.
152  
153 =head2 $item = $feed->add_item( $srcitem );
154  
155 This method duplicates an item/entry and adds it to $feed.
156 $srcitem is a C<XML::FeedPP::*::Item> class's instance
157 which is returned by C<get_item()> method, as described above.
158  
159 =head2 $item = $feed->add_item( link => $link, title => $tile, ... );
160  
161 This method creates an new item/entry
162 which has C<link>, C<title> elements etc.
163  
164 =head2 $item = $feed->get_item( $index );
165  
166 This method returns item(s) in a $feed.
167 A valid zero-based array $index returns the corresponding item in the feed.
168 An invalid $index yields undef.
169 If $index is undefined in array context, it returns an array of all items.
170 If $index is undefined in scalar context, it returns the number of items.
171  
172 =head2 @items = $feed->match_item( link => qr/.../, title => qr/.../, ... );
173  
174 This method finds item(s) which match all regular expressions given.
175 This method returns an array of all matched items in array context.
176 This method returns the first matched item in scalar context.
177  
178 =head2 $feed->remove_item( $index or $link );
179  
180 This method removes an item/entry specified by zero-based array index or
181 link URL.
182  
183 =head2 $feed->clear_item();
184  
185 This method removes all items/entries from the $feed.
186  
187 =head2 $feed->sort_item();
188  
189 This method sorts the order of items in $feed by C<pubDate>.
190  
191 =head2 $feed->uniq_item();
192  
193 Reduces the list of items, not to include duplicates. RDF and Atoms
194 have a guid attribute to defined uniqueness, for RSS we use the link.
195  
196 =head2 $feed->normalize();
197  
198 This method calls both the C<sort_item()> and C<uniq_item()> methods.
199  
200 =head2 $feed->limit_item( $num );
201  
202 Removes items in excess of the specified numeric limit. Items at the
203 end of the list are removed. When preceded by C<sort_item()> or
204 C<normalize()>, this deletes more recent items.
205  
206 =head2 $feed->xmlns( "xmlns:media" => "http://search.yahoo.com/mrss" );
207  
208 Adds an XML namespace at the document root of the feed.
209  
210 =head2 $url = $feed->xmlns( "xmlns:media" );
211  
212 Returns the URL of the specified XML namespace.
213  
214 =head2 @list = $feed->xmlns();
215  
216 Returns the list of all XML namespaces used in $feed.
217  
218 =head1 METHODS FOR CHANNEL
219  
220 =head2 $feed->title( $text );
221  
222 This method sets/gets the feed's C<title> element,
223 returning its current value when $title is undefined.
224  
225 =head2 $feed->description( $html );
226  
227 This method sets/gets the feed's C<description> element in plain text or HTML,
228 returning its current value when $html is undefined.
229 It is mapped to C<content> element for Atom 0.3/1.0.
230  
231 =head2 $feed->pubDate( $date );
232  
233 This method sets/gets the feed's C<pubDate> element for RSS,
234 returning its current value when $date is undefined.
235 It is mapped to C<dc:date> element for RDF,
236 C<modified> for Atom 0.3, and C<updated> for Atom 1.0.
237 See also L</DATE AND TIME FORMATS> section below.
238  
239 =head2 $feed->copyright( $text );
240  
241 This method sets/gets the feed's C<copyright> element for RSS,
242 returning its current value when $text is undefined.
243 It is mapped to C<dc:rights> element for RDF,
244 C<copyright> for Atom 0.3, and C<rights> for Atom 1.0.
245  
246 =head2 $feed->link( $url );
247  
248 This method sets/gets the URL of the web site as the feed's C<link> element,
249 returning its current value when the $url is undefined.
250  
251 =head2 $feed->language( $lang );
252  
253 This method sets/gets the feed's C<language> element for RSS,
254 returning its current value when the $lang is undefined.
255 It is mapped to C<dc:language> element for RDF,
256 C<feed xml:lang=""> for Atom 0.3/1.0.
257  
258 =head2 $feed->image( $url, $title, $link, $description, $width, $height )
259  
260 This method sets/gets the feed's C<image> element and its child nodes,
261 returning a list of current values when any arguments are undefined.
262  
263 =head1 METHODS FOR ITEM
264  
265 =head2 $item->title( $text );
266  
267 This method sets/gets the item's C<title> element,
268 returning its current value when the $text is undefined.
269  
270 =head2 $item->description( $html );
271  
272 This method sets/gets the item's C<description> element in HTML or plain text,
273 returning its current value when $text is undefined.
274 It is mapped to C<content> element for Atom 0.3/1.0.
275  
276 =head2 $item->pubDate( $date );
277  
278 This method sets/gets the item's C<pubDate> element,
279 returning its current value when $date is undefined.
280 It is mapped to C<dc:date> element for RDF,
281 C<modified> for Atom 0.3, and C<updated> for Atom 1.0.
282 See also L</DATE AND TIME FORMATS> section below.
283  
284 =head2 $item->category( $text );
285  
286 This method sets/gets the item's C<category> element.
287 returning its current value when $text is undefined.
288 It is mapped to C<dc:subject> element for RDF, and ignored for Atom 0.3.
289  
290 =head2 $item->author( $name );
291  
292 This method sets/gets the item's C<author> element,
293 returning its current value when $name is undefined.
294 It is mapped to C<dc:creator> element for RDF,
295 C<author> for Atom 0.3/1.0.
296  
297 =head2 $item->guid( $guid, isPermaLink => $bool );
298  
299 This method sets/gets the item's C<guid> element,
300 returning its current value when $guid is undefined.
301  
302 It is mapped to C<id> element for Atom, and ignored for RDF. In case of
303 RSS, it will return a HASH. The C<isParmaLink> is supported by RSS only,
304 and optional.
305  
306 =head2 $item->set( $key => $value, ... );
307  
308 This method sets customized node values or attributes.
309 See also L</ACCESSOR AND MUTATORS> section below.
310  
311 =head2 $value = $item->get( $key );
312  
313 This method returns the node value or attribute.
314 See also L</ACCESSOR AND MUTATORS> section below.
315  
316 =head2 $link = $item->link();
317  
318 This method returns the item's C<link> element.
319  
320 =head1 ACCESSOR AND MUTATORS
321  
322 This module understands only subset of C<rdf:*>, C<dc:*> modules
323 and RSS/RDF/Atom's default namespaces by itself.
324 There are NO native methods for any other external modules, such as C<media:*>.
325 But C<set()> and C<get()> methods are available to get/set
326 the value of any elements or attributes for these modules.
327  
328 =head2 $item->set( "module:name" => $value );
329  
330 This sets the value of the child node:
331  
332 <item><module:name>$value</module:name>...</item>
333  
334 =head2 $item->set( "module:name@attr" => $value );
335  
336 This sets the value of the child node's attribute:
337  
338 <item><module:name attr="$value" />...</item>
339  
340 =head2 $item->set( "@attr" => $value );
341  
342 This sets the value of the item's attribute:
343  
344 <item attr="$value">...</item>
345  
346 =head2 $item->set( "hoge/pomu@hare" => $value );
347  
348 This code sets the value of the child node's child node's attribute:
349  
350 <item><hoge><pomu attr="$value" /></hoge>...</item>
351  
352 =head1 DATE AND TIME FORMATS
353  
354 C<XML::FeedPP> allows you to describe date/time using any of the three
355 following formats:
356  
357 =head2 $date = "Thu, 23 Feb 2006 14:43:43 +0900";
358  
359 This is the HTTP protocol's preferred format and RSS 2.0's native
360 format, as defined by RFC 1123.
361  
362 =head2 $date = "2006-02-23T14:43:43+09:00";
363  
364 W3CDTF is the native format of RDF, as defined by ISO 8601.
365  
366 =head2 $date = 1140705823;
367  
368 The last format is the number of seconds since the epoch,
369 C<1970-01-01T00:00:00Z>.
370 You know, this is the native format of Perl's C<time()> function.
371  
372 =head1 USING MEDIA RSS
373  
374 To publish Media RSS, add the C<media> namespace then use C<set()>
375 setter method to manipulate C<media:content> element, etc.
376  
377 my $feed = XML::FeedPP::RSS->new();
378 $feed->xmlns('xmlns:media' => 'http://search.yahoo.com/mrss/');
379 my $item = $feed->add_item('http://www.example.com/index.html');
380 $item->set('media:content@url' => 'http://www.example.com/image.jpg');
381 $item->set('media:content@type' => 'image/jpeg');
382 $item->set('media:content@width' => 640);
383 $item->set('media:content@height' => 480);
384  
385 =head1 MODULE DEPENDENCIES
386  
387 C<XML::FeedPP> requires only L<XML::TreePP>
388 which likewise is a pure Perl implementation.
389 The standard L<LWP::UserAgent> is required
390 to download feeds from remote web servers.
391 C<Jcode.pm> is required to convert Japanese encodings on Perl 5.005
392 and 5.6.1, but is NOT required on Perl 5.8.x and later.
393  
394 =head1 AUTHOR
395  
396 Yusuke Kawasaki, http://www.kawa.net/
397  
398 =head1 COPYRIGHT
399  
400 The following copyright notice applies to all the files provided in
401 this distribution, including binary files, unless explicitly noted
402 otherwise.
403  
404 Copyright 2006-2011 Yusuke Kawasaki
405  
406 =head1 LICENSE
407  
408 This library is free software; you can redistribute it and/or modify
409 it under the same terms as Perl itself.
410  
411 =cut
412  
413 # ----------------------------------------------------------------
414 package XML::FeedPP;
415 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
416 44 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
417 44 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
418 44 ▶use XML::TreePP;
Subroutine BEGIN: called CC=1 SCAR=0.0
419  
420 44 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
421 $VERSION $RSS20_VERSION $ATOM03_VERSION
422 $XMLNS_RDF $XMLNS_RSS $XMLNS_DC $XMLNS_ATOM03
423 $XMLNS_NOCOPY $TREEPP_OPTIONS $MIME_TYPES
424 $FEED_METHODS $ITEM_METHODS
425 $XMLNS_ATOM10
426 44 );
427  
428 44 $VERSION = "0.95";
429  
430 44 $RSS20_VERSION = '2.0';
431 44 $ATOM03_VERSION = '0.3';
432  
433 44 $XMLNS_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
434 44 $XMLNS_RSS = 'http://purl.org/rss/1.0/';
435 44 $XMLNS_DC = 'http://purl.org/dc/elements/1.1/';
436 44 $XMLNS_ATOM03 = 'http://purl.org/atom/ns#';
437 44 $XMLNS_ATOM10 = 'http://www.w3.org/2005/Atom';
438 44 $XMLNS_NOCOPY = [qw( xmlns xmlns:rdf xmlns:dc xmlns:atom )];
439  
440 44 $TREEPP_OPTIONS = {
441 force_array => [qw( item rdf:li entry )],
442 first_out => [qw( -xmlns:rdf -xmlns -rel -type url title link )],
443 last_out => [qw( description image item items entry -width -height )],
444 user_agent => "XML-FeedPP/$VERSION ",
445 };
446  
447 44 $MIME_TYPES = { reverse qw(
448 image/bmp bmp
449 image/gif gif
450 image/jpeg jpeg
451 image/jpeg jpg
452 image/png png
453 image/svg+xml svg
454 image/x-icon ico
455 image/x-xbitmap xbm
456 image/x-xpixmap xpm
457 )};
458  
459 44 $FEED_METHODS = [qw(
460 title
461 description
462 language
463 copyright
464 link
465 pubDate
466 image
467 set
468 )];
469  
470 44 $ITEM_METHODS = [qw(
471 title
472 description
473 category
474 author
475 link
476 guid
477 pubDate
478 image
479 set
480 )];
481  
482 179 ▶sub new {
Subroutine new: called CC=10 SCAR=23.2
Pod documented
483 179 my $package = shift;
484 179 my( $init, $source, @rest ) = &XML::FeedPP::Util::param_even_odd(@_);
485 179 my $do_autodetect = $package eq __PACKAGE__;
486  
487 179 ▶ Carp::croak "No feed source"
Branch: 1 branch
BranchTrueFalseTotal
if $do_autodetect and not $source 0 179 179
Condition66%2/3
$do_autodetect and not $source
!ll&&!rl&&r
104750
MC/DC0%0/2
$do_autodetect and not $source
$do_autodetect not $source
Truth table66%2/3
A and not(B)
A= $do_autodetectB= not $source
ABresult
0X0
100
111
488 if $do_autodetect && !$source;
489  
490 179 my $self = bless {}, $package;
491 179 ▶ $self->load($source, @rest) if $source;
Branch: 1 branch
BranchTrueFalseTotal
if $source 80 99 179
492  
493 175 ▶ if($do_autodetect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_autodetect) 71 104 175
494 71 my $class = $self->detect_format;
495 71 ▶ unless ( $class ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 1 70 71
496 1 ▶ my $root = ref $self ? join( " ", sort keys %$self ) : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 1 0 1
497 1 ▶ my $class = ref $self ? ref $self : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 1 0 1
498 1 Carp::croak "Invalid $class feed format: $root";
499 }
500 70 bless $self, $class;
501 }
502  
503 174 ▶ $self->validate_feed() if $source;
Branch: 1 branch
BranchTrueFalseTotal
if $source 75 99 174
504 174 $self->init_feed();
505 174 ▶ $self->elements(@$init) if ref $init;
Branch: 1 branch
BranchTrueFalseTotal
if ref $init 99 75 174
506 174 $self;
507 }
508  
509 75 ▶sub validate_feed {
Subroutine validate_feed: called CC=4 SCAR=23.2
Pod undocumented
510 75 my $self = shift;
511 75 ▶ return if $self->test_feed(@_);
Branch: 1 branch
BranchTrueFalseTotal
if $self->test_feed(@_) 75 0 75
512 0 ▶ my $root = ref $self ? join( " ", sort keys %$self ) : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
513 0 ▶ my $class = ref $self ? ref $self : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
514 0 Carp::croak "Invalid $class feed format: $root";
515 }
516  
517 71 ▶sub detect_format {
Subroutine detect_format: called CC=3 SCAR=11.0
Pod undocumented
518 71 my $self = shift;
519 71 my $list = $self->available_format;
520 71 foreach my $class ( @$list ) {
521 154 my $hit = $class->test_feed($self);
522 154 ▶ return $class if $hit;
Branch: 1 branch
BranchTrueFalseTotal
if $hit 70 84 154
523 }
524 1 undef;
525 }
526  
527 71 ▶sub available_format {
Subroutine available_format: called CC=1 SCAR=0.0
Pod undocumented
528 71 [ 'XML::FeedPP::RSS',
529 'XML::FeedPP::RDF',
530 'XML::FeedPP::Atom::Atom10',
531 'XML::FeedPP::Atom::Atom03',
532 'XML::FeedPP::Atom' ];
533 }
534  
535 80 ▶sub load {
Subroutine load: called CC=11 SCAR=25.5
Pod documented
536 80 my $self = shift;
537 80 my $source = shift;
538 80 my $args = { @_ };
539 80 my $method = $args->{'-type'};
540 80 ▶ Carp::croak "No feed source" unless defined $source;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $source 0 80 80
541  
542 80 ▶ if ( ! $method ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method) 77 3 80
543 77 ▶ if ( $source =~ m#^https?://#s ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($source =~ m[^https?://]s) { } 0 77 77
elsif ($source =~ /(?:\s*\xEF\xBB\xBF)?\s* (<(\?xml|!DOCTYPE|rdf:RDF|rss|feed)\W)/six) { } 75 2 77
elsif (not $source =~ /[\r\n]/ and -f $source) { } 0 2 2
544 0 $method = 'url';
545 }
546 elsif ( $source =~ m#(?:\s*\xEF\xBB\xBF)?\s*
547 (<(\?xml|!DOCTYPE|rdf:RDF|rss|feed)\W)#xis ) {
548 75 $method = 'string';
549 }
550 ▶ elsif ( $source !~ /[\r\n]/ && -f $source ) {
Condition33%1/3
not $source =~ /[\r\n]/ and -f $source
!ll&&!rl&&r
020
MC/DC0%0/2
not $source =~ /[\r\n]/ and -f $source
not $source =~ /[\r\n]/ -f $source
Truth table33%1/3
not(A) and B
A= not $source =~ /[\r\n]/B= -f $source
ABresult
0X0
100
111
551 0 $method = 'file';
552 }
553 else {
554 2 Carp::croak "Invalid feed source: $source";
555 }
556 }
557  
558 78 my $opts = { map { $_ => $args->{$_} } grep { ! /^-/ } keys %$args };
559 78 my $tpp = XML::TreePP->new(%$TREEPP_OPTIONS, %$opts);
560  
561 78 my $tree;
562 78 ▶ if ( $method eq 'url' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($method eq 'url') { } 0 78 78
elsif ($method eq 'string') { } 77 1 78
elsif ($method eq 'file') { } 1 0 1
563 0 $tree = $tpp->parsehttp( GET => $source );
564 }
565 elsif ( $method eq 'string' ) {
566 77 $tree = $tpp->parse($source);
567 }
568 elsif ( $method eq 'file' ) {
569 1 $tree = $tpp->parsefile($source);
570 }
571 else {
572 0 Carp::croak "Invalid load type: $method";
573 }
574  
575 77 ▶ Carp::croak "Loading failed: $source" unless ref $tree;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tree 1 76 77
576 76 %$self = %$tree; # override myself
577 76 $self;
578 }
579  
580 91 ▶sub to_string {
Subroutine to_string: called CC=3 SCAR=11.0
Pod documented
581 91 my $self = shift;
582 91 my( $args, $encode, @rest ) = XML::FeedPP::Util::param_even_odd(@_);
583 91 ▶ $args ||= \@rest;
Condition100%2/2
$args ||= \@rest
l!l
847
MC/DC100%1/1
$args ||= \@rest
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
584 91 ▶ my @opts = ( output_encoding => $encode ) if $encode;
Branch: 1 branch
BranchTrueFalseTotal
if $encode 7 84 91
585 91 my $tpp = XML::TreePP->new( %$TREEPP_OPTIONS, @opts, @$args );
586 91 $tpp->write( $self, $encode );
587 }
588  
589 0 ▶sub to_file {
Subroutine to_file: not called CC=3 SCAR=24.8
Pod documented
590 0 my $self = shift;
591 0 my $file = shift;
592 0 my( $args, $encode, @rest ) = XML::FeedPP::Util::param_even_odd(@_);
593 0 ▶ $args ||= \@rest;
Condition0%0/2
$args ||= \@rest
l!l
00
MC/DC0%0/1
$args ||= \@rest
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
594 0 ▶ my @opts = ( output_encoding => $encode ) if $encode;
Branch: 1 branch
BranchTrueFalseTotal
if $encode 0 0 0
595 0 my $tpp = XML::TreePP->new( %$TREEPP_OPTIONS, @opts, @$args );
596 0 $tpp->writefile( $file, $self, $encode );
597 }
598  
599 31 ▶sub merge {
Subroutine merge: called CC=2 SCAR=7.0
Pod documented
600 31 my $self = shift;
601 31 my $source = shift;
602 31 ▶ my $target = ref $source ? $source : XML::FeedPP->new($source, @_);
Branch: 1 branch
BranchTrueFalseTotal
ref $source ? : 0 31 31
603 31 $self->merge_channel($target);
604 31 $self->merge_item($target);
605 31 $self->normalize();
606 31 $self;
607 }
608  
609 31 ▶sub merge_channel {
Subroutine merge_channel: called CC=3 SCAR=12.0
Pod undocumented
610 31 my $self = shift;
611 31 ▶ my $target = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $target = shift() or return 31 0 31
612 31 ▶ if ( ref $self eq ref $target ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq ref $target) { } 0 31 31
613 0 $self->merge_native_channel($target);
614 }
615 else {
616 31 $self->merge_common_channel($target);
617 }
618 }
619  
620 31 ▶sub merge_item {
Subroutine merge_item: called CC=3 SCAR=11.1
Pod undocumented
621 31 my $self = shift;
622 31 ▶ my $target = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $target = shift() or return 31 0 31
623 31 foreach my $item ( $target->get_item() ) {
624 59 $self->add_item( $item );
625 }
626 }
627  
628 31 ▶sub merge_common_channel {
Subroutine merge_common_channel: called CC=18 SCAR=29.1
Pod undocumented
629 31 my $self = shift;
630 31 ▶ my $target = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $target = shift() or return 31 0 31
631  
632 31 my $title1 = $self->title();
633 31 my $title2 = $target->title();
634 31 ▶ $self->title($title2) if ( !defined $title1 && defined $title2 );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $title1 and defined $title2 13 18 31
Condition100%3/3
not defined $title1 and defined $title2
!ll&&!rl&&r
61213
MC/DC100%2/2
not defined $title1 and defined $title2
not defined $title1 defined $title2
Truth table100%3/3
not(A) and B
A= not defined $title1B= defined $title2
ABresult
0X0
100
111
635  
636 31 my $desc1 = $self->description();
637 31 my $desc2 = $target->description();
638 31 ▶ $self->description($desc2) if ( !defined $desc1 && defined $desc2 );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $desc1 and defined $desc2 8 23 31
Condition66%2/3
not defined $desc1 and defined $desc2
!ll&&!rl&&r
0238
MC/DC50%1/2
not defined $desc1 and defined $desc2
not defined $desc1 defined $desc2
Truth table66%2/3
not(A) and B
A= not defined $desc1B= defined $desc2
ABresult
0X0
100
111
639  
640 31 my $link1 = $self->link();
641 31 my $link2 = $target->link();
642 31 ▶ $self->link($link2) if ( !defined $link1 && defined $link2 );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $link1 and defined $link2 17 14 31
Condition66%2/3
not defined $link1 and defined $link2
!ll&&!rl&&r
01417
MC/DC50%1/2
not defined $link1 and defined $link2
not defined $link1 defined $link2
Truth table66%2/3
not(A) and B
A= not defined $link1B= defined $link2
ABresult
0X0
100
111
643  
644 31 my $lang1 = $self->language();
645 31 my $lang2 = $target->language();
646 31 ▶ $self->language($lang2) if ( !defined $lang1 && defined $lang2 );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $lang1 and defined $lang2 10 21 31
Condition66%2/3
not defined $lang1 and defined $lang2
!ll&&!rl&&r
02110
MC/DC50%1/2
not defined $lang1 and defined $lang2
not defined $lang1 defined $lang2
Truth table66%2/3
not(A) and B
A= not defined $lang1B= defined $lang2
ABresult
0X0
100
111
647  
648 31 my $right1 = $self->copyright();
649 31 my $right2 = $target->copyright();
650 31 ▶ $self->copyright($right2) if ( !defined $right1 && defined $right2 );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $right1 and defined $right2 8 23 31
Condition66%2/3
not defined $right1 and defined $right2
!ll&&!rl&&r
0238
MC/DC50%1/2
not defined $right1 and defined $right2
not defined $right1 defined $right2
Truth table66%2/3
not(A) and B
A= not defined $right1B= defined $right2
ABresult
0X0
100
111
651  
652 31 my $pubDate1 = $self->pubDate();
653 31 my $pubDate2 = $target->pubDate();
654 31 ▶ $self->pubDate($pubDate2) if ( !defined $pubDate1 && defined $pubDate2 );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $pubDate1 and defined $pubDate2 10 21 31
Condition66%2/3
not defined $pubDate1 and defined $pubDate2
!ll&&!rl&&r
02110
MC/DC50%1/2
not defined $pubDate1 and defined $pubDate2
not defined $pubDate1 defined $pubDate2
Truth table66%2/3
not(A) and B
A= not defined $pubDate1B= defined $pubDate2
ABresult
0X0
100
111
655  
656 31 my @image1 = $self->image();
657 31 my @image2 = $target->image();
658 31 ▶ $self->image(@image2) if ( !defined $image1[0] && defined $image2[0] );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $image1[0] and defined $image2[0] 6 25 31
Condition66%2/3
not defined $image1[0] and defined $image2[0]
!ll&&!rl&&r
0256
MC/DC50%1/2
not defined $image1[0] and defined $image2[0]
not defined $image1[0] defined $image2[0]
Truth table66%2/3
not(A) and B
A= not defined $image1[0]B= defined $image2[0]
ABresult
0X0
100
111
659  
660 31 my @xmlns1 = $self->xmlns();
661 31 my @xmlns2 = $target->xmlns();
662 31 my $xmlchk = { map { $_ => 1 } @xmlns1, @$XML::FeedPP::XMLNS_NOCOPY };
663 31 foreach my $ns (@xmlns2) {
664 48 ▶ next if exists $xmlchk->{$ns};
Branch: 1 branch
BranchTrueFalseTotal
if exists $xmlchk->{$ns} 37 11 48
665 11 $self->xmlns( $ns, $target->xmlns($ns) );
666 }
667  
668 31 $self->merge_module_nodes( $self->docroot, $target->docroot );
669  
670 31 $self;
671 }
672  
673 65 ▶sub add_clone_item {
Subroutine add_clone_item: called CC=11 SCAR=24.0
Pod undocumented
674 65 my $self = shift;
675 65 ▶ my $srcitem = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $srcitem = shift() or return 65 0 65
676 65 ▶ my $link = $srcitem->link() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $link = $srcitem->link or return 65 0 65
677 65 my $dstitem = $self->add_item( $link );
678  
679 65 ▶ if ( ref $dstitem eq ref $srcitem ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dstitem eq ref $srcitem) { } 3 62 65
680 3 XML::FeedPP::Util::merge_hash( $dstitem, $srcitem );
681  
682 # A new item starts with a link, and then a merge. Setting the
683 # link often affects the guid. The merge will not set the guid
684 # anymore. So, let's overrule that.
685 3 ▶ if(my $guid = $srcitem->{guid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $guid = $srcitem->{"guid"}) 1 2 3
686 1 $dstitem->{guid} = $guid;
687 }
688 }
689 else {
690 62 my $title = $srcitem->title();
691 62 ▶ $dstitem->title($title) if defined $title;
Branch: 1 branch
BranchTrueFalseTotal
if defined $title 28 34 62
692  
693 62 my $description = $srcitem->description();
694 62 ▶ $dstitem->description($description) if defined $description;
Branch: 1 branch
BranchTrueFalseTotal
if defined $description 9 53 62
695  
696 62 my $category = $srcitem->category();
697 62 ▶ $dstitem->category($category) if defined $category;
Branch: 1 branch
BranchTrueFalseTotal
if defined $category 27 35 62
698  
699 62 my $author = $srcitem->author();
700 62 ▶ $dstitem->author($author) if defined $author;
Branch: 1 branch
BranchTrueFalseTotal
if defined $author 9 53 62
701  
702 62 my $guid = $srcitem->guid();
703 62 ▶ $dstitem->guid($guid) if defined $guid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $guid 35 27 62
704  
705 62 my $pubDate = $srcitem->pubDate();
706 62 ▶ $dstitem->pubDate($pubDate) if defined $pubDate;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pubDate 30 32 62
707  
708 62 $self->merge_module_nodes( $dstitem, $srcitem );
709 }
710  
711 65 $dstitem;
712 }
713  
714 93 ▶sub merge_module_nodes {
Subroutine merge_module_nodes: called CC=3 SCAR=11.0
Pod undocumented
715 93 my $self = shift;
716 93 my $item1 = shift;
717 93 my $item2 = shift;
718 93 foreach my $key ( grep { /:/ } keys %$item2 ) {
719 90 ▶ next if ( $key =~ /^-?(dc|rdf|xmlns):/ );
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^-?(dc|rdf|xmlns):/ 67 23 90
720  
721 # deep copy would be better
722 23 $item1->{$key} = $item2->{$key};
723 }
724 }
725  
726 37 ▶sub normalize {
Subroutine normalize: called CC=1 SCAR=0.0
Pod documented
727 37 my $self = shift;
728 37 $self->normalize_pubDate();
729 37 $self->sort_item();
730 37 $self->uniq_item();
731 }
732  
733 37 ▶sub normalize_pubDate {
Subroutine normalize_pubDate: called CC=4 SCAR=13.9
Pod undocumented
734 37 my $self = shift;
735 37 foreach my $item ( $self->get_item() ) {
736 77 ▶ my $date = $item->get_pubDate_native() or next;
Branch: 1 branch
BranchTrueFalseTotal
my $date = $item->get_pubDate_native or next 45 32 77
737 45 $item->pubDate( $date );
738 }
739 37 my $date = $self->get_pubDate_native();
740 37 ▶ $self->pubDate( $date ) if $date;
Branch: 1 branch
BranchTrueFalseTotal
if $date 13 24 37
741 }
742  
743 312 ▶sub xmlns {
Subroutine xmlns: called CC=4 SCAR=13.9
Pod documented
744 312 my $self = shift;
745 312 my $ns = shift;
746 312 my $url = shift;
747 312 my $root = $self->docroot;
748 312 ▶ if ( !defined $ns ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $ns) { } 74 238 312
elsif (not defined $url) { } 20 218 238
749 74 my $list = [ grep { /^-xmlns(:\S|$)/ } keys %$root ];
750 74 return map { (/^-(.*)$/)[0] } @$list;
751 }
752 elsif ( !defined $url ) {
753 20 ▶ return unless exists $root->{ '-' . $ns };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$root{'-' . $ns} 0 20 20
754 20 return $root->{ '-' . $ns };
755 }
756 else {
757 218 $root->{ '-' . $ns } = $url;
758 }
759 }
760  
761 82 ▶sub get_pubDate_w3cdtf {
Subroutine get_pubDate_w3cdtf: called CC=1 SCAR=0.0
Pod undocumented
762 82 my $self = shift;
763 82 my $date = $self->get_pubDate_native();
764 82 XML::FeedPP::Util::get_w3cdtf($date);
765 }
766  
767 21 ▶sub get_pubDate_rfc1123 {
Subroutine get_pubDate_rfc1123: called CC=1 SCAR=0.0
Pod undocumented
768 21 my $self = shift;
769 21 my $date = $self->get_pubDate_native();
770 21 XML::FeedPP::Util::get_rfc1123($date);
771 }
772  
773 113 ▶sub get_pubDate_epoch {
Subroutine get_pubDate_epoch: called CC=1 SCAR=0.0
Pod undocumented
774 113 my $self = shift;
775 113 my $date = $self->get_pubDate_native();
776 113 XML::FeedPP::Util::get_epoch($date);
777 }
778  
779 0 ▶sub call {
Subroutine call: not called CC=3 SCAR=24.8
Pod undocumented
780 0 my $self = shift;
781 0 my $name = shift;
782 0 my $class = __PACKAGE__."::Plugin::".$name;
783 0 my $pmfile = $class;
784 0 $pmfile =~ s#::#/#g;
785 0 $pmfile .= ".pm";
786 0 local $@;
787 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class->VERSION 0 0 0
788 0 require $pmfile;
789 } unless defined $class->VERSION;
790 0 ▶ Carp::croak "$class failed: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
791 0 return $class->run( $self, @_ );
792 }
793  
794 99 ▶sub elements {
Subroutine elements: called CC=3 SCAR=11.0
Pod undocumented
795 99 my $self = shift;
796 99 my $args = [ @_ ];
797 99 my $methods = { map {$_=>1} @$FEED_METHODS };
798 99 ▶ while ( my $key = shift @$args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = shift @$args) 27 99 126
799 27 my $val = shift @$args;
800 27 ▶ if ( $methods->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($methods->{$key}) { } 24 3 27
801 24 $self->$key( $val );
802 } else {
803 3 $self->set( $key, $val );
804 }
805 }
806 }
807  
808 12 ▶sub match_item {
Subroutine match_item: called CC=8 SCAR=20.8
Pod documented
809 12 my $self = shift;
810 12 my @list = $self->get_item();
811 12 ▶ return unless scalar @list;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @list 0 12 12
812 12 my $methods = { map {$_=>1} @$ITEM_METHODS };
813 12 my $args = [ @_ ];
814 12 my $out = [];
815 12 foreach my $item ( @list ) {
816 36 my $unmatch = 0;
817 36 my $i = 0;
818 36 while( 1 ) {
819 63 ▶ my $key = $args->[$i++] or last;
Branch: 1 branch
BranchTrueFalseTotal
my $key = $$args[$i++] or last 42 21 63
820 42 my $test = $args->[$i++];
821 42 ▶ my $got = $methods->{$key} ? $item->$key() : $item->get( $key );
Branch: 1 branch
BranchTrueFalseTotal
$methods->{$key} ? : 30 12 42
822 42 ▶ unless ( $got =~ $test ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($got =~ /$test/) 15 27 42
823 15 $unmatch ++;
824 15 last;
825 }
826 }
827 36 ▶ unless ( $unmatch ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($unmatch) 21 15 36
828 21 ▶ return $item unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 21 21
829 21 push( @$out, $item );
830 }
831 }
832 12 @$out;
833 }
834  
835 0 ▶sub channel_class { Carp::croak((ref $_[0])."->channel_class() is not implemented"); }
Subroutine channel_class: not called CC=1 SCAR=6.9
Pod undocumented
836 0 ▶sub item_class { Carp::croak((ref $_[0])."->item_class() is not implemented"); }
Subroutine item_class: not called CC=1 SCAR=6.9
Pod undocumented
837 0 ▶sub test_feed { Carp::croak((ref $_[0])."->test_feed() is not implemented"); }
Subroutine test_feed: not called CC=1 SCAR=6.9
Pod undocumented
838 0 ▶sub init_feed { Carp::croak((ref $_[0])."->init_feed() is not implemented"); }
Subroutine init_feed: not called CC=1 SCAR=6.9
Pod undocumented
839 0 ▶sub add_item { Carp::croak((ref $_[0])."->add_item() is not implemented"); }
Subroutine add_item: not called CC=1 SCAR=6.9
Pod documented
840 0 ▶sub clear_item { Carp::croak((ref $_[0])."->clear_item() is not implemented"); }
Subroutine clear_item: not called CC=1 SCAR=6.9
Pod documented
841 0 ▶sub remove_item { Carp::croak((ref $_[0])."->remove_item() is not implemented"); }
Subroutine remove_item: not called CC=1 SCAR=6.9
Pod documented
842 0 ▶sub get_item { Carp::croak((ref $_[0])."->get_item() is not implemented"); }
Subroutine get_item: not called CC=1 SCAR=6.9
Pod documented
843 0 ▶sub sort_item { Carp::croak((ref $_[0])."->sort_item() is not implemented"); }
Subroutine sort_item: not called CC=1 SCAR=6.9
Pod documented
844 0 ▶sub uniq_item { Carp::croak((ref $_[0])."->uniq_item() is not implemented"); }
Subroutine uniq_item: not called CC=1 SCAR=6.9
Pod documented
845 0 ▶sub limit_item { Carp::croak((ref $_[0])."->limit_item() is not implemented"); }
Subroutine limit_item: not called CC=1 SCAR=6.9
Pod documented
846 0 ▶sub docroot { Carp::croak((ref $_[0])."->docroot() is not implemented"); }
Subroutine docroot: not called CC=1 SCAR=6.9
Pod undocumented
847 0 ▶sub channel { Carp::croak((ref $_[0])."->channel() is not implemented"); }
Subroutine channel: not called CC=1 SCAR=6.9
Pod undocumented
848 0 ▶sub set { Carp::croak((ref $_[0])."->set() is not implemented"); }
Subroutine set: not called CC=1 SCAR=6.9
Pod documented
849 0 ▶sub get { Carp::croak((ref $_[0])."->get() is not implemented"); }
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
850 0 ▶sub title { Carp::croak((ref $_[0])."->title() is not implemented"); }
Subroutine title: not called CC=1 SCAR=6.9
Pod documented
851 0 ▶sub description { Carp::croak((ref $_[0])."->description() is not implemented"); }
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
852 0 ▶sub link { Carp::croak((ref $_[0])."->link() is not implemented"); }
Subroutine link: not called CC=1 SCAR=6.9
Pod documented
853 0 ▶sub language { Carp::croak((ref $_[0])."->language() is not implemented"); }
Subroutine language: not called CC=1 SCAR=6.9
Pod documented
854 0 ▶sub copyright { Carp::croak((ref $_[0])."->copyright() is not implemented"); }
Subroutine copyright: not called CC=1 SCAR=6.9
Pod documented
855 0 ▶sub pubDate { Carp::croak((ref $_[0])."->pubDate() is not implemented"); }
Subroutine pubDate: not called CC=1 SCAR=6.9
Pod documented
856 0 ▶sub image { Carp::croak((ref $_[0])."->image() is not implemented"); }
Subroutine image: not called CC=1 SCAR=6.9
Pod documented
857  
858 # ----------------------------------------------------------------
859 package XML::FeedPP::Plugin;
860 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
861  
862 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
863 0 my $class = shift;
864 0 my $feed = shift;
865 0 ▶ my $ref = ref $class ? ref $class : $class;
Branch: 1 branch
BranchTrueFalseTotal
ref $class ? : 0 0 0
866 0 Carp::croak $ref."->run() is not implemented";
867 }
868  
869 # ----------------------------------------------------------------
870 package XML::FeedPP::Item;
871 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
872 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
873 44 @ISA = qw( XML::FeedPP::Element );
874  
875 44 *get_pubDate_w3cdtf = \&XML::FeedPP::get_pubDate_w3cdtf; # import
876 44 *get_pubDate_rfc1123 = \&XML::FeedPP::get_pubDate_rfc1123;
877 44 *get_pubDate_epoch = \&XML::FeedPP::get_pubDate_epoch;
878  
879 33 ▶sub elements {
Subroutine elements: called CC=3 SCAR=11.0
880 33 my $self = shift;
881 33 my $args = [ @_ ];
882 33 my $methods = { map {$_=>1} @$XML::FeedPP::ITEM_METHODS };
883 33 ▶ while ( my $key = shift @$args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = shift @$args) 99 33 132
884 99 my $val = shift @$args;
885 99 ▶ if ( $methods->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($methods->{$key}) { } 87 12 99
886 87 $self->$key( $val );
887 } else {
888 12 $self->set( $key, $val );
889 }
890 }
891 }
892  
893 # ----------------------------------------------------------------
894 package XML::FeedPP::RSS;
895 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
896 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
897 44 @ISA = qw( XML::FeedPP );
898  
899 106 ▶sub channel_class {
Subroutine channel_class: called CC=1 SCAR=0.0
900 106 'XML::FeedPP::RSS::Channel';
901 }
902  
903 67 ▶sub item_class {
Subroutine item_class: called CC=1 SCAR=0.0
904 67 'XML::FeedPP::RSS::Item';
905 }
906  
907 101 ▶sub test_feed {
Subroutine test_feed: called CC=4 SCAR=14.0
908 101 my $self = shift;
909 101 ▶ my $source = shift || $self;
Condition66%2/3
shift() || $self
l!l&&r!l&&!r
71300
MC/DC0%0/2
shift() || $self
shift() $self
Truth table66%2/3
A || B
A= shift()B= $self
ABresult
1X1
011
000
910 101 ▶ return unless ref $source;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source 0 101 101
911 101 ▶ return unless ref $source->{rss};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source->{"rss"} 42 59 101
912 59 __PACKAGE__;
913 }
914  
915 68 ▶sub init_feed {
Subroutine init_feed: called CC=9 SCAR=22.8
916 68 ▶ my $self = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or return 68 0 68
917  
918 68 ▶ $self->{rss} ||= {};
Condition100%2/2
$self->{"rss"} ||= {}
l!l
3038
MC/DC100%1/1
$self->{"rss"} ||= {}
$self->{"rss"}
Truth table100%2/2
A
A= $self->{"rss"}
Aresult
11
00
919 68 ▶ if ( ! UNIVERSAL::isa( $self->{rss}, 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($self->{"rss"}, "HASH")) 0 68 68
920 0 Carp::croak "Invalid RSS 2.0 feed format: $self->{rss}";
921 }
922 68 ▶ $self->{rss}->{'-version'} ||= $XML::FeedPP::RSS20_VERSION;
Condition66%2/3
$self->{"rss"}{"-version"} ||= $XML::FeedPP::RSS20_VERSION
l!l&&r!l&&!r
30380
MC/DC0%0/2
$self->{"rss"}{"-version"} ||= $XML::FeedPP::RSS20_VERSION
$self->{"rss"}{"-version"} $XML::FeedPP::RSS20_VERSION
Truth table66%2/3
A ||= B
A= $self->{"rss"}{"-version"}B= $XML::FeedPP::RSS20_VERSION
ABresult
1X1
011
000
923  
924 68 ▶ my $channel = $self->{rss}{channel} ||= $self->channel_class->new();
Condition66%2/3
$self->{"rss"}{"channel"} ||= $self->channel_class->new
l!l&&r!l&&!r
30380
MC/DC0%0/2
$self->{"rss"}{"channel"} ||= $self->channel_class->new
$self->{"rss"}{"channel"} $self->channel_class->new
Truth table66%2/3
A ||= B
A= $self->{"rss"}{"channel"}B= $self->channel_class->new
ABresult
1X1
011
000
925 68 $self->channel_class->ref_bless($channel);
926  
927 68 ▶ my $items = $channel->{item} || [];
Condition100%2/2
$channel->{'item'} || []
l!l
2444
MC/DC100%1/1
$channel->{'item'} || []
$channel->{'item'}
Truth table100%2/2
A
A= $channel->{'item'}
Aresult
11
00
928 68 ▶ my @items = grep ref $_, # skip empty items
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($items, 'HASH') ? : 0 68 68
929 UNIVERSAL::isa($items, 'HASH') ? $items : @$items;
930  
931 68 $self->item_class->ref_bless($_) for @items;
932 68 $channel->{item} = \@items;
933  
934 68 $self;
935 }
936  
937 0 ▶sub merge_native_channel {
Subroutine merge_native_channel: not called CC=2 SCAR=17.9
938 0 my $self = shift;
939 0 ▶ my $tree = shift or next;
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or next 0 0 0
940  
941 0 XML::FeedPP::Util::merge_hash( $self->{rss}, $tree->{rss}, qw( channel ) );
942 XML::FeedPP::Util::merge_hash(
943 $self->{rss}->{channel},
944 $tree->{rss}->{channel},
945 0 qw( item )
946 );
947 }
948  
949 108 ▶sub add_item {
Subroutine add_item: called CC=6 SCAR=18.0
950 108 my $self = shift;
951 108 my( $init, $link, @rest ) = &XML::FeedPP::Util::param_even_odd(@_);
952  
953 108 ▶ Carp::croak "add_item needs an argument" if ( ! ref $init && ! $link );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $init or $link 0 108 108
Condition66%2/3
ref $init or $link
l!l&&r!l&&!r
11970
MC/DC0%0/2
ref $init or $link
ref $init $link
Truth table66%2/3
A or B
A= ref $initB= $link
ABresult
1X1
011
000
954 108 ▶ if ( ref $link ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $link) 23 85 108
955 23 return $self->add_clone_item( $link );
956 }
957  
958 85 my $item = XML::FeedPP::RSS::Item->new(@rest);
959 85 ▶ $item->link($link) if $link;
Branch: 1 branch
BranchTrueFalseTotal
if $link 74 11 85
960 85 ▶ $item->elements(@$init) if ref $init;
Branch: 1 branch
BranchTrueFalseTotal
if ref $init 11 74 85
961 85 push( @{ $self->{rss}->{channel}->{item} }, $item );
962 85 $item;
963 }
964  
965 1 ▶sub clear_item {
Subroutine clear_item: called CC=1 SCAR=0.0
966 1 my $self = shift;
967 1 $self->{rss}->{channel}->{item} = [];
968 }
969  
970 7 ▶sub remove_item {
Subroutine remove_item: called CC=4 SCAR=13.9
971 7 my $self = shift;
972 7 my $remove = shift;
973 7 ▶ my $list = $self->{rss}->{channel}->{item} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"rss"}{"channel"}{"item"} or return 7 0 7
974 7 my @deleted;
975  
976 7 ▶ if ( $remove =~ /^-?\d+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove =~ /^-?\d+/) { } 6 1 7
977 6 @deleted = splice( @$list, $remove, 1 );
978 }
979 else {
980 1 @deleted = grep { $_->link() eq $remove } @$list;
981 1 @$list = grep { $_->link() ne $remove } @$list;
982 }
983  
984 7 ▶ wantarray ? @deleted : shift @deleted;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
985 }
986  
987 131 ▶sub get_item {
Subroutine get_item: called CC=4 SCAR=13.9
988 131 my $self = shift;
989 131 my $num = shift;
990 131 ▶ $self->{rss}->{channel}->{item} ||= [];
Condition50%1/2
$self->{"rss"}{"channel"}{"item"} ||= []
l!l
1310
MC/DC0%0/1
$self->{"rss"}{"channel"}{"item"} ||= []
$self->{"rss"}{"channel"}{"item"}
Truth table50%1/2
A
A= $self->{"rss"}{"channel"}{"item"}
Aresult
11
00
991 131 ▶ if ( defined $num ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $num) { } 57 74 131
elsif (wantarray) { } 40 34 74
992 57 return $self->{rss}->{channel}->{item}->[$num];
993 }
994 elsif (wantarray) {
995 40 return @{ $self->{rss}->{channel}->{item} };
996 }
997 else {
998 34 return scalar @{ $self->{rss}->{channel}->{item} };
999 }
1000 }
1001  
1002 15 ▶sub sort_item {
Subroutine sort_item: called CC=3 SCAR=11.0
1003 15 my $self = shift;
1004 15 ▶ my $list = $self->{rss}->{channel}->{item} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"rss"}{"channel"}{"item"} or return 15 0 15
1005 15 ▶ my $epoch = [ map { $_->get_pubDate_epoch() || 0 } @$list ];
Condition100%2/2
$_->get_pubDate_epoch || 0
l!l
2314
MC/DC100%1/1
$_->get_pubDate_epoch || 0
$_->get_pubDate_epoch
Truth table100%2/2
A
A= $_->get_pubDate_epoch
Aresult
11
00
1006 37 my $sorted = [ map { $list->[$_] } sort {
1007 15 $epoch->[$b] <=> $epoch->[$a]
1008 } 0 .. $#$list ];
1009 15 @$list = @$sorted;
1010 15 scalar @$list;
1011 }
1012  
1013 13 ▶sub uniq_item {
Subroutine uniq_item: called CC=5 SCAR=16.2
1014 13 my $self = shift;
1015 13 ▶ my $list = $self->{rss}->{channel}->{item} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"rss"}{"channel"}{"item"} or return 13 0 13
1016 13 my (%check, @uniq);
1017 13 foreach my $item (@$list) {
1018 27 ▶ my $key = $item->guid() || $item->link();
Condition66%2/3
$item->guid || $item->link
l!l&&r!l&&!r
2610
MC/DC0%0/2
$item->guid || $item->link
$item->guid $item->link
Truth table66%2/3
A || B
A= $item->guidB= $item->link
ABresult
1X1
011
000
1019 27 ▶ push( @uniq, $item ) unless $check{$key}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $check{$key}++ 25 2 27
1020 }
1021 13 @$list = @uniq;
1022 13 scalar @$list;
1023 }
1024  
1025 7 ▶sub limit_item {
Subroutine limit_item: called CC=6 SCAR=17.9
1026 7 my $self = shift;
1027 7 my $limit = shift;
1028 7 ▶ my $list = $self->{rss}->{channel}->{item} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"rss"}{"channel"}{"item"} or return 7 0 7
1029 7 ▶ if ( $limit > 0 && $limit < scalar @$list ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($limit > 0 and $limit < scalar @$list) { } 3 4 7
elsif ($limit < 0 and -$limit < scalar @$list) { } 2 3 5
Condition100%3/3
$limit > 0 and $limit < scalar @$list
!ll&&!rl&&r
313
MC/DC100%2/2
$limit > 0 and $limit < scalar @$list
$limit > 0 $limit < scalar @$list
Truth table100%3/3
A and B
A= $limit > 0B= $limit < scalar @$list
ABresult
0X0
100
111
1030 3 @$list = splice( @$list, 0, $limit ); # remove from end
1031 }
1032 ▶ elsif ( $limit < 0 && -$limit < scalar @$list ) {
Condition100%3/3
$limit < 0 and -$limit < scalar @$list
!ll&&!rl&&r
112
MC/DC100%2/2
$limit < 0 and -$limit < scalar @$list
$limit < 0 -$limit < scalar @$list
Truth table100%3/3
A and B
A= $limit < 0B= -$limit < scalar @$list
ABresult
0X0
100
111
1033 2 @$list = splice( @$list, $limit ); # remove from start
1034 }
1035 7 scalar @$list;
1036 }
1037  
1038 72 ▶sub docroot { shift->{rss}; }
Subroutine docroot: called CC=1 SCAR=0.0
1039 0 ▶sub channel { shift->{rss}->{channel}; }
Subroutine channel: not called CC=1 SCAR=6.9
1040 2 ▶sub set { shift->{rss}->{channel}->set(@_); }
Subroutine set: called CC=1 SCAR=0.0
1041 25 ▶sub get { shift->{rss}->{channel}->get(@_); }
Subroutine get: called CC=1 SCAR=0.0
1042  
1043 54 ▶sub title { shift->{rss}->{channel}->get_or_set( "title", @_ ); }
Subroutine title: called CC=1 SCAR=0.0
1044 38 ▶sub description { shift->{rss}->{channel}->get_or_set( "description", @_ ); }
Subroutine description: called CC=1 SCAR=0.0
1045 56 ▶sub link { shift->{rss}->{channel}->get_or_set( "link", @_ ); }
Subroutine link: called CC=1 SCAR=0.0
1046 36 ▶sub language { shift->{rss}->{channel}->get_or_set( "language", @_ ); }
Subroutine language: called CC=1 SCAR=0.0
1047 35 ▶sub copyright { shift->{rss}->{channel}->get_or_set( "copyright", @_ ); }
Subroutine copyright: called CC=1 SCAR=0.0
1048  
1049 51 ▶sub pubDate {
Subroutine pubDate: called CC=2 SCAR=6.9
1050 51 my $self = shift;
1051 51 my $date = shift;
1052 51 ▶ return $self->get_pubDate_w3cdtf() unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 33 18 51
1053 18 $date = XML::FeedPP::Util::get_rfc1123($date);
1054 18 $self->{rss}->{channel}->set_value( "pubDate", $date );
1055 }
1056  
1057 52 ▶sub get_pubDate_native {
Subroutine get_pubDate_native: called CC=2 SCAR=6.9
1058 52 my $self = shift;
1059 $self->{rss}->{channel}->get_value("pubDate") # normal RSS 2.0
1060 52 ▶ || $self->{rss}->{channel}->get_value("dc:date"); # strange
Branch: 1 branch
BranchTrueFalseTotal
$self->{"rss"}{"channel"}->get_value("pubDate") or $self->{"rss"}{"channel"}->get_value("dc:date") 23 29 52
1061 }
1062  
1063 32 ▶sub image {
Subroutine image: called CC=12 SCAR=24.8
1064 32 my $self = shift;
1065 32 my $url = shift;
1066 32 ▶ if ( defined $url ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $url) { } 4 28 32
elsif (exists $self->{'rss'}{'channel'}{'image'}) { } 5 23 28
1067 4 my ( $title, $link, $desc, $width, $height ) = @_;
1068 4 ▶ $self->{rss}->{channel}->{image} ||= {};
Condition100%2/2
$self->{"rss"}{"channel"}{"image"} ||= {}
l!l
13
MC/DC100%1/1
$self->{"rss"}{"channel"}{"image"} ||= {}
$self->{"rss"}{"channel"}{"image"}
Truth table100%2/2
A
A= $self->{"rss"}{"channel"}{"image"}
Aresult
11
00
1069 4 my $image = $self->{rss}->{channel}->{image};
1070 4 $image->{url} = $url;
1071 4 ▶ $image->{title} = $title if defined $title;
Branch: 1 branch
BranchTrueFalseTotal
if defined $title 3 1 4
1072 4 ▶ $image->{link} = $link if defined $link;
Branch: 1 branch
BranchTrueFalseTotal
if defined $link 3 1 4
1073 4 ▶ $image->{description} = $desc if defined $desc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $desc 1 3 4
1074 4 ▶ $image->{width} = $width if defined $width;
Branch: 1 branch
BranchTrueFalseTotal
if defined $width 1 3 4
1075 4 ▶ $image->{height} = $height if defined $height;
Branch: 1 branch
BranchTrueFalseTotal
if defined $height 1 3 4
1076 }
1077 elsif ( exists $self->{rss}->{channel}->{image} ) {
1078 5 my $image = $self->{rss}->{channel}->{image};
1079 5 my $array = [];
1080 5 foreach my $key (qw( url title link description width height )) {
1081 30 ▶ push( @$array, exists $image->{$key} ? $image->{$key} : undef );
Branch: 1 branch
BranchTrueFalseTotal
exists $image->{$key} ? : 14 16 30
1082 }
1083 5 ▶ return wantarray ? @$array : shift @$array;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 1 5
1084 }
1085 27 undef;
1086 }
1087  
1088 # ----------------------------------------------------------------
1089 package XML::FeedPP::RSS::Channel;
1090 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1091 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1092 44 @ISA = qw( XML::FeedPP::Element );
1093  
1094 # ----------------------------------------------------------------
1095 package XML::FeedPP::RSS::Item;
1096 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1097 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1098 44 @ISA = qw( XML::FeedPP::Item );
1099  
1100 104 ▶sub title { shift->get_or_set( "title", @_ ); }
Subroutine title: called CC=1 SCAR=0.0
1101 56 ▶sub description { shift->get_or_set( "description", @_ ); }
Subroutine description: called CC=1 SCAR=0.0
1102 99 ▶sub category { shift->get_set_array( "category", @_ ); }
Subroutine category: called CC=1 SCAR=0.0
1103  
1104 45 ▶sub author {
Subroutine author: called CC=3 SCAR=11.0
1105 45 my $self = shift;
1106 45 ▶ if ( scalar @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) { } 7 38 45
1107 7 $self->set_value( 'author', @_ );
1108 } else {
1109 38 ▶ $self->get_value('author') || $self->get_value('dc:creator');
Branch: 1 branch
BranchTrueFalseTotal
$self->get_value("author") or $self->get_value("dc:creator") 8 30 38
1110 }
1111 }
1112  
1113 167 ▶sub link {
Subroutine link: called CC=3 SCAR=11.0
1114 167 my $self = shift;
1115 167 my $link = shift;
1116 167 ▶ return $self->get_value("link") unless defined $link;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $link 81 86 167
1117 86 ▶ $self->guid($link) unless defined $self->guid();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->guid 84 2 86
1118 86 $self->set_value( link => $link );
1119 }
1120  
1121 252 ▶sub guid {
Subroutine guid: called CC=4 SCAR=13.9
1122 252 my $self = shift;
1123 252 my $guid = shift;
1124 252 ▶ return $self->get_value("guid") unless defined $guid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $guid 152 100 252
1125 100 my @args = @_;
1126 100 ▶ if ( ! scalar @args ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not scalar @args) { } 98 2 100
elsif (scalar @args == 1) { } 1 1 2
1127 # default
1128 98 @args = ( 'isPermaLink' => 'true' );
1129 } elsif ( scalar @args == 1 ) {
1130 # XML::FeedPP 0.36's behavior
1131 1 unshift( @args, 'isPermaLink' );
1132 }
1133 100 $self->set_value( guid => $guid, @args );
1134 }
1135  
1136 95 ▶sub pubDate {
Subroutine pubDate: called CC=2 SCAR=6.9
1137 95 my $self = shift;
1138 95 my $date = shift;
1139 95 ▶ return $self->get_pubDate_w3cdtf() unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 42 53 95
1140 53 $date = XML::FeedPP::Util::get_rfc1123($date);
1141 53 $self->set_value( "pubDate", $date );
1142 }
1143  
1144 119 ▶sub get_pubDate_native {
Subroutine get_pubDate_native: called CC=2 SCAR=6.9
1145 119 my $self = shift;
1146 119 ▶ $self->get_value("pubDate") # normal RSS 2.0
Branch: 1 branch
BranchTrueFalseTotal
$self->get_value("pubDate") or $self->get_value("dc:date") 75 44 119
1147 || $self->get_value("dc:date"); # strange
1148 }
1149  
1150 0 ▶sub image {
Subroutine image: not called CC=12 SCAR=50.5
1151 0 my $self = shift;
1152 0 my $url = shift;
1153 0 ▶ if ( defined $url ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $url) { } 0 0 0
elsif (exists $self->{'image'}) { } 0 0 0
1154 0 my ( $title, $link, $desc, $width, $height ) = @_;
1155 0 ▶ $self->{image} ||= {};
Condition0%0/2
$self->{"image"} ||= {}
l!l
00
MC/DC0%0/1
$self->{"image"} ||= {}
$self->{"image"}
Truth table0%0/2
A
A= $self->{"image"}
Aresult
11
00
1156 0 my $image = $self->{image};
1157 0 $image->{url} = $url;
1158 0 ▶ $image->{title} = $title if defined $title;
Branch: 1 branch
BranchTrueFalseTotal
if defined $title 0 0 0
1159 0 ▶ $image->{link} = $link if defined $link;
Branch: 1 branch
BranchTrueFalseTotal
if defined $link 0 0 0
1160 0 ▶ $image->{description} = $desc if defined $desc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $desc 0 0 0
1161 0 ▶ $image->{width} = $width if defined $width;
Branch: 1 branch
BranchTrueFalseTotal
if defined $width 0 0 0
1162 0 ▶ $image->{height} = $height if defined $height;
Branch: 1 branch
BranchTrueFalseTotal
if defined $height 0 0 0
1163 }
1164 elsif ( exists $self->{image} ) {
1165 0 my $image = $self->{image};
1166 0 my $array = [];
1167 0 foreach my $key (qw( url title link description width height )) {
1168 0 ▶ push( @$array, exists $image->{$key} ? $image->{$key} : undef );
Branch: 1 branch
BranchTrueFalseTotal
exists $image->{$key} ? : 0 0 0
1169 }
1170 0 ▶ return wantarray ? @$array : shift @$array;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1171 }
1172 0 undef;
1173 }
1174  
1175 # ----------------------------------------------------------------
1176 package XML::FeedPP::RDF;
1177 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1178 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1179 44 @ISA = qw( XML::FeedPP );
1180  
1181 77 ▶sub channel_class {
Subroutine channel_class: called CC=1 SCAR=0.0
1182 77 'XML::FeedPP::RDF::Channel';
1183 }
1184  
1185 97 ▶sub item_class {
Subroutine item_class: called CC=1 SCAR=0.0
1186 97 'XML::FeedPP::RDF::Item';
1187 }
1188  
1189 61 ▶sub test_feed {
Subroutine test_feed: called CC=4 SCAR=14.0
1190 61 my $self = shift;
1191 61 ▶ my $source = shift || $self;
Condition66%2/3
shift() || $self
l!l&&r!l&&!r
42190
MC/DC0%0/2
shift() || $self
shift() $self
Truth table66%2/3
A || B
A= shift()B= $self
ABresult
1X1
011
000
1192 61 ▶ return unless ref $source;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source 0 61 61
1193 61 ▶ return unless ref $source->{'rdf:RDF'};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source->{"rdf:RDF"} 24 37 61
1194 37 __PACKAGE__;
1195 }
1196  
1197 48 ▶sub init_feed {
Subroutine init_feed: called CC=19 SCAR=32.2
1198 48 ▶ my $self = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or return 48 0 48
1199  
1200 48 ▶ $self->{'rdf:RDF'} ||= {};
Condition100%2/2
$self->{"rdf:RDF"} ||= {}
l!l
1929
MC/DC100%1/1
$self->{"rdf:RDF"} ||= {}
$self->{"rdf:RDF"}
Truth table100%2/2
A
A= $self->{"rdf:RDF"}
Aresult
11
00
1201 48 ▶ if ( ! UNIVERSAL::isa( $self->{'rdf:RDF'}, 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($self->{"rdf:RDF"}, "HASH")) 0 48 48
1202 0 Carp::croak "Invalid RDF 1.0 feed format: $self->{'rdf:RDF'}";
1203 }
1204 48 $self->xmlns( 'xmlns' => $XML::FeedPP::XMLNS_RSS );
1205 48 $self->xmlns( 'xmlns:rdf' => $XML::FeedPP::XMLNS_RDF );
1206 48 $self->xmlns( 'xmlns:dc' => $XML::FeedPP::XMLNS_DC );
1207  
1208 48 ▶ $self->{'rdf:RDF'}->{channel} ||= $self->channel_class->new();
Condition66%2/3
$self->{"rdf:RDF"}{"channel"} ||= $self->channel_class->new
l!l&&r!l&&!r
19290
MC/DC0%0/2
$self->{"rdf:RDF"}{"channel"} ||= $self->channel_class->new
$self->{"rdf:RDF"}{"channel"} $self->channel_class->new
Truth table66%2/3
A ||= B
A= $self->{"rdf:RDF"}{"channel"}B= $self->channel_class->new
ABresult
1X1
011
000
1209 48 $self->channel_class->ref_bless( $self->{'rdf:RDF'}->{channel} );
1210  
1211 48 ▶ $self->{'rdf:RDF'}->{channel}->{items} ||= {};
Condition100%2/2
$self->{"rdf:RDF"}{"channel"}{"items"} ||= {}
l!l
1434
MC/DC100%1/1
$self->{"rdf:RDF"}{"channel"}{"items"} ||= {}
$self->{"rdf:RDF"}{"channel"}{"items"}
Truth table100%2/2
A
A= $self->{"rdf:RDF"}{"channel"}{"items"}
Aresult
11
00
1212 48 ▶ $self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'} ||= {};
Condition100%2/2
$self->{"rdf:RDF"}{"channel"}{"items"}{"rdf:Seq"} ||= {}
l!l
1236
MC/DC100%1/1
$self->{"rdf:RDF"}{"channel"}{"items"}{"rdf:Seq"} ||= {}
$self->{"rdf:RDF"}{"channel"}{"items"}{"rdf:Seq"}
Truth table100%2/2
A
A= $self->{"rdf:RDF"}{"channel"}{"items"}{"rdf:Seq"}
Aresult
11
00
1213  
1214 48 my $rdfseq = $self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'};
1215  
1216 # http://www.kawa.net/works/perl/feedpp/feedpp.html#com-2008-05-17T13:13:33Z
1217 48 ▶ if ( UNIVERSAL::isa( $rdfseq, 'ARRAY' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($rdfseq, "ARRAY")) 1 47 48
1218 1 my $num1 = scalar @$rdfseq;
1219 1 ▶ my $num2 = scalar grep { ref $_ && exists $_->{'rdf:li'} && ref $_->{'rdf:li'} } @$rdfseq;
Condition33%2/6
ref $_ && exists $_->{'rdf:li'} && ref $_->{'rdf:li'}
!ll&&!rl&&r
003
ref $_ and exists $_->{"rdf:li"}
!ll&&!rl&&r
003
MC/DC0%0/3
ref $_ && exists $_->{'rdf:li'} && ref $_->{'rdf:li'}
ref $_ exists $_->{"rdf:li"} ref $_->{'rdf:li'}
Truth table25%1/4
A and B && C
A= ref $_B= exists $_->{"rdf:li"}C= ref $_->{'rdf:li'}
ABCresult
0XX0
10X0
1100
1111
1220 1 ▶ my $num3 = scalar grep { ref $_ && keys %$_ == 1 } @$rdfseq;
Condition33%1/3
ref $_ && keys %$_ == 1
!ll&&!rl&&r
003
MC/DC0%0/2
ref $_ && keys %$_ == 1
ref $_ keys %$_ == 1
Truth table33%1/3
A && B
A= ref $_B= keys %$_ == 1
ABresult
0X0
100
111
1221 1 ▶ if ( $num1 && $num1 == $num2 && $num1 == $num3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num1 and $num1 == $num2 and $num1 == $num3) 1 0 1
Condition33%2/6
$num1 and $num1 == $num2 and $num1 == $num3
!ll&&!rl&&r
001
$num1 and $num1 == $num2
!ll&&!rl&&r
001
MC/DC0%0/3
$num1 and $num1 == $num2 and $num1 == $num3
$num1 $num1 == $num2 $num1 == $num3
Truth table25%1/4
A and B and C
A= $num1B= $num1 == $num2C= $num1 == $num3
ABCresult
0XX0
10X0
1100
1111
1222 1 my $newli = [ map { @{$_->{'rdf:li'}} } @$rdfseq ];
1223 1 $rdfseq = { 'rdf:li' => $newli };
1224 1 $self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'} = $rdfseq;
1225 }
1226 }
1227  
1228 48 ▶ $rdfseq->{'rdf:li'} ||= [];
Condition100%2/2
$rdfseq->{"rdf:li"} ||= []
l!l
1236
MC/DC100%1/1
$rdfseq->{"rdf:li"} ||= []
$rdfseq->{"rdf:li"}
Truth table100%2/2
A
A= $rdfseq->{"rdf:li"}
Aresult
11
00
1229 48 ▶ if ( UNIVERSAL::isa( $rdfseq->{'rdf:li'}, 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($rdfseq->{"rdf:li"}, "HASH")) 0 48 48
1230 0 $rdfseq->{'rdf:li'} = [ $rdfseq->{'rdf:li'} ];
1231 }
1232 48 ▶ $self->{'rdf:RDF'}->{item} ||= [];
Condition100%2/2
$self->{"rdf:RDF"}{"item"} ||= []
l!l
1335
MC/DC100%1/1
$self->{"rdf:RDF"}{"item"} ||= []
$self->{"rdf:RDF"}{"item"}
Truth table100%2/2
A
A= $self->{"rdf:RDF"}{"item"}
Aresult
11
00
1233 48 ▶ if ( UNIVERSAL::isa( $self->{'rdf:RDF'}->{item}, 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($self->{"rdf:RDF"}{"item"}, "HASH")) 0 48 48
1234  
1235 # force array when only one item exist
1236 0 $self->{'rdf:RDF'}->{item} = [ $self->{'rdf:RDF'}->{item} ];
1237 }
1238 48 foreach my $item ( @{ $self->{'rdf:RDF'}->{item} } ) {
1239 27 $self->item_class->ref_bless($item);
1240 }
1241  
1242 48 $self;
1243 }
1244  
1245 0 ▶sub merge_native_channel {
Subroutine merge_native_channel: not called CC=2 SCAR=17.9
1246 0 my $self = shift;
1247 0 ▶ my $tree = shift or next;
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or next 0 0 0
1248  
1249 0 XML::FeedPP::Util::merge_hash( $self->{'rdf:RDF'}, $tree->{'rdf:RDF'},
1250 qw( channel item ) );
1251  
1252 XML::FeedPP::Util::merge_hash(
1253 $self->{'rdf:RDF'}->{channel},
1254 $tree->{'rdf:RDF'}->{channel},
1255 0 qw( items )
1256 );
1257 }
1258  
1259 98 ▶sub add_item {
Subroutine add_item: called CC=7 SCAR=19.5
1260 98 my $self = shift;
1261 98 my( $init, $link, @rest ) = &XML::FeedPP::Util::param_even_odd(@_);
1262  
1263 98 ▶ Carp::croak "add_item needs an argument" if ( ! ref $init && ! $link );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $init or $link 0 98 98
Condition66%2/3
ref $init or $link
l!l&&r!l&&!r
11870
MC/DC0%0/2
ref $init or $link
ref $init $link
Truth table66%2/3
A or B
A= ref $initB= $link
ABresult
1X1
011
000
1264 98 ▶ if ( ref $link ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $link) 28 70 98
1265 28 return $self->add_clone_item( $link );
1266 }
1267  
1268 70 my $rdfli = $self->item_class->new();
1269 70 $rdfli->{'-rdf:resource'} = $link;
1270 70 ▶ $self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'}->{'rdf:li'} ||= [];
Condition50%1/2
$self->{"rdf:RDF"}{"channel"}{"items"}{"rdf:Seq"}{"rdf:li"} ||= []
l!l
700
MC/DC0%0/1
$self->{"rdf:RDF"}{"channel"}{"items"}{"rdf:Seq"}{"rdf:li"} ||= []
$self->{"rdf:RDF"}{"channel"}{"items"}{"rdf:Seq"}{"rdf:li"}
Truth table50%1/2
A
A= $self->{"rdf:RDF"}{"channel"}{"items"}{"rdf:Seq"}{"rdf:li"}
Aresult
11
00
1271 push(
1272 70 @{ $self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'}->{'rdf:li'} },
1273 $rdfli
1274 );
1275  
1276 70 my $item = XML::FeedPP::RDF::Item->new(@rest);
1277 70 ▶ $item->link($link) if $link;
Branch: 1 branch
BranchTrueFalseTotal
if $link 59 11 70
1278 70 ▶ $item->elements(@$init) if ref $init;
Branch: 1 branch
BranchTrueFalseTotal
if ref $init 11 59 70
1279 70 push( @{ $self->{'rdf:RDF'}->{item} }, $item );
1280  
1281 70 $item;
1282 }
1283  
1284 1 ▶sub clear_item {
Subroutine clear_item: called CC=1 SCAR=0.0
1285 1 my $self = shift;
1286 1 $self->{'rdf:RDF'}->{item} = [];
1287 1 $self->__refresh_items();
1288 }
1289  
1290 7 ▶sub remove_item {
Subroutine remove_item: called CC=4 SCAR=13.9
1291 7 my $self = shift;
1292 7 my $remove = shift;
1293 7 ▶ my $list = $self->{'rdf:RDF'}->{item} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"rdf:RDF"}{"item"} or return 7 0 7
1294 7 my @deleted;
1295  
1296 7 ▶ if ( $remove =~ /^-?\d+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove =~ /^-?\d+/) { } 6 1 7
1297 6 @deleted = splice( @$list, $remove, 1 );
1298 }
1299 else {
1300 1 @deleted = grep { $_->link() eq $remove } @$list;
1301 1 @$list = grep { $_->link() ne $remove } @$list;
1302 }
1303  
1304 7 $self->__refresh_items();
1305  
1306 7 ▶ wantarray ? @deleted : shift @deleted;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
1307 }
1308  
1309 101 ▶sub get_item {
Subroutine get_item: called CC=4 SCAR=13.9
1310 101 my $self = shift;
1311 101 my $num = shift;
1312 101 ▶ $self->{'rdf:RDF'}->{item} ||= [];
Condition50%1/2
$self->{"rdf:RDF"}{"item"} ||= []
l!l
1010
MC/DC0%0/1
$self->{"rdf:RDF"}{"item"} ||= []
$self->{"rdf:RDF"}{"item"}
Truth table50%1/2
A
A= $self->{"rdf:RDF"}{"item"}
Aresult
11
00
1313 101 ▶ if ( defined $num ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $num) { } 36 65 101
elsif (wantarray) { } 32 33 65
1314 36 return $self->{'rdf:RDF'}->{item}->[$num];
1315 }
1316 elsif (wantarray) {
1317 32 return @{ $self->{'rdf:RDF'}->{item} };
1318 }
1319 else {
1320 33 return scalar @{ $self->{'rdf:RDF'}->{item} };
1321 }
1322 }
1323  
1324 16 ▶sub sort_item {
Subroutine sort_item: called CC=3 SCAR=11.0
1325 16 my $self = shift;
1326 16 ▶ my $list = $self->{'rdf:RDF'}->{item} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"rdf:RDF"}{"item"} or return 16 0 16
1327 16 ▶ my $epoch = [ map { $_->get_pubDate_epoch() || 0 } @$list ];
Condition100%2/2
$_->get_pubDate_epoch || 0
l!l
3210
MC/DC100%1/1
$_->get_pubDate_epoch || 0
$_->get_pubDate_epoch
Truth table100%2/2
A
A= $_->get_pubDate_epoch
Aresult
11
00
1328 42 my $sorted = [ map { $list->[$_] } sort {
1329 16 $epoch->[$b] <=> $epoch->[$a]
1330 } 0 .. $#$list ];
1331 16 @$list = @$sorted;
1332 16 $self->__refresh_items();
1333 }
1334  
1335 14 ▶sub uniq_item {
Subroutine uniq_item: called CC=4 SCAR=13.9
1336 14 my $self = shift;
1337 14 ▶ my $list = $self->{'rdf:RDF'}->{item} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"rdf:RDF"}{"item"} or return 14 0 14
1338 14 my (%check, @uniq);
1339 14 foreach my $item (@$list) {
1340 32 my $link = $item->link();
1341 32 ▶ push( @uniq, $item ) unless $check{$link}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $check{$link}++ 30 2 32
1342 }
1343 14 $self->{'rdf:RDF'}->{item} = \@uniq;
1344 14 $self->__refresh_items();
1345 }
1346  
1347 7 ▶sub limit_item {
Subroutine limit_item: called CC=6 SCAR=17.9
1348 7 my $self = shift;
1349 7 my $limit = shift;
1350 7 ▶ my $list = $self->{'rdf:RDF'}->{item} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"rdf:RDF"}{"item"} or return 7 0 7
1351 7 ▶ if ( $limit > 0 && $limit < scalar @$list ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($limit > 0 and $limit < scalar @$list) { } 3 4 7
elsif ($limit < 0 and -$limit < scalar @$list) { } 2 3 5
Condition100%3/3
$limit > 0 and $limit < scalar @$list
!ll&&!rl&&r
313
MC/DC100%2/2
$limit > 0 and $limit < scalar @$list
$limit > 0 $limit < scalar @$list
Truth table100%3/3
A and B
A= $limit > 0B= $limit < scalar @$list
ABresult
0X0
100
111
1352 3 @$list = splice( @$list, 0, $limit ); # remove from end
1353 }
1354 ▶ elsif ( $limit < 0 && -$limit < scalar @$list ) {
Condition100%3/3
$limit < 0 and -$limit < scalar @$list
!ll&&!rl&&r
112
MC/DC100%2/2
$limit < 0 and -$limit < scalar @$list
$limit < 0 -$limit < scalar @$list
Truth table100%3/3
A and B
A= $limit < 0B= -$limit < scalar @$list
ABresult
0X0
100
111
1355 2 @$list = splice( @$list, $limit ); # remove from start
1356 }
1357 7 $self->__refresh_items();
1358 }
1359  
1360 45 ▶sub __refresh_items {
Subroutine __refresh_items: called CC=3 SCAR=11.0
1361 45 my $self = shift;
1362 45 ▶ my $list = $self->{'rdf:RDF'}->{item} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"rdf:RDF"}{"item"} or return 45 0 45
1363 45 $self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'}->{'rdf:li'} = [];
1364 45 my $dest = $self->{'rdf:RDF'}->{channel}->{items}->{'rdf:Seq'}->{'rdf:li'};
1365 45 foreach my $item (@$list) {
1366 101 my $rdfli = XML::FeedPP::Element->new();
1367 101 $rdfli->{'-rdf:resource'} = $item->link();
1368 101 push( @$dest, $rdfli );
1369 }
1370 45 scalar @$dest;
1371 }
1372  
1373 204 ▶sub docroot { shift->{'rdf:RDF'}; }
Subroutine docroot: called CC=1 SCAR=0.0
1374 0 ▶sub channel { shift->{'rdf:RDF'}->{channel}; }
Subroutine channel: not called CC=1 SCAR=6.9
1375 3 ▶sub set { shift->{'rdf:RDF'}->{channel}->set(@_); }
Subroutine set: called CC=1 SCAR=0.0
1376 49 ▶sub get { shift->{'rdf:RDF'}->{channel}->get(@_); }
Subroutine get: called CC=1 SCAR=0.0
1377 43 ▶sub title { shift->{'rdf:RDF'}->{channel}->get_or_set( "title", @_ ); }
Subroutine title: called CC=1 SCAR=0.0
1378 32 ▶sub description { shift->{'rdf:RDF'}->{channel}->get_or_set( "description", @_ ); }
Subroutine description: called CC=1 SCAR=0.0
1379 30 ▶sub language { shift->{'rdf:RDF'}->{channel}->get_or_set( "dc:language", @_ ); }
Subroutine language: called CC=1 SCAR=0.0
1380 29 ▶sub copyright { shift->{'rdf:RDF'}->{channel}->get_or_set( "dc:rights", @_ ); }
Subroutine copyright: called CC=1 SCAR=0.0
1381  
1382 45 ▶sub link {
Subroutine link: called CC=2 SCAR=6.9
1383 45 my $self = shift;
1384 45 my $link = shift;
1385 45 ▶ return $self->{'rdf:RDF'}->{channel}->get_value("link")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $link 29 16 45
1386 unless defined $link;
1387 16 $self->{'rdf:RDF'}->{channel}->{'-rdf:about'} = $link;
1388 16 $self->{'rdf:RDF'}->{channel}->set_value( "link", $link, @_ );
1389 }
1390  
1391 48 ▶sub pubDate {
Subroutine pubDate: called CC=2 SCAR=6.9
1392 48 my $self = shift;
1393 48 my $date = shift;
1394 48 ▶ return $self->get_pubDate_w3cdtf() unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 32 16 48
1395 16 $date = XML::FeedPP::Util::get_w3cdtf($date);
1396 16 $self->{'rdf:RDF'}->{channel}->set_value( "dc:date", $date );
1397 }
1398  
1399 52 ▶sub get_pubDate_native {
Subroutine get_pubDate_native: called CC=1 SCAR=0.0
1400 52 shift->{'rdf:RDF'}->{channel}->get_value("dc:date");
1401 }
1402  
1403 44 *get_pubDate_w3cdtf = \&get_pubDate_native;
1404  
1405 25 ▶sub image {
Subroutine image: called CC=11 SCAR=24.1
1406 25 my $self = shift;
1407 25 my $url = shift;
1408 25 ▶ if ( defined $url ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $url) { } 2 23 25
elsif (exists $self->{'rdf:RDF'}{'image'}) { } 3 20 23
elsif (exists $self->{'rdf:RDF'}{'channel'}{'image'}) { } 0 20 20
1409 2 my ( $title, $link ) = @_;
1410 2 ▶ $self->{'rdf:RDF'}->{channel}->{image} ||= {};
Condition50%1/2
$self->{"rdf:RDF"}{"channel"}{"image"} ||= {}
l!l
02
MC/DC0%0/1
$self->{"rdf:RDF"}{"channel"}{"image"} ||= {}
$self->{"rdf:RDF"}{"channel"}{"image"}
Truth table50%1/2
A
A= $self->{"rdf:RDF"}{"channel"}{"image"}
Aresult
11
00
1411 2 $self->{'rdf:RDF'}->{channel}->{image}->{'-rdf:resource'} = $url;
1412 2 ▶ $self->{'rdf:RDF'}->{image} ||= {};
Condition50%1/2
$self->{"rdf:RDF"}{"image"} ||= {}
l!l
02
MC/DC0%0/1
$self->{"rdf:RDF"}{"image"} ||= {}
$self->{"rdf:RDF"}{"image"}
Truth table50%1/2
A
A= $self->{"rdf:RDF"}{"image"}
Aresult
11
00
1413 2 $self->{'rdf:RDF'}->{image}->{'-rdf:about'} = $url; # fix
1414 2 my $image = $self->{'rdf:RDF'}->{image};
1415 2 $image->{url} = $url;
1416 2 ▶ $image->{title} = $title if defined $title;
Branch: 1 branch
BranchTrueFalseTotal
if defined $title 1 1 2
1417 2 ▶ $image->{link} = $link if defined $link;
Branch: 1 branch
BranchTrueFalseTotal
if defined $link 1 1 2
1418 }
1419 elsif ( exists $self->{'rdf:RDF'}->{image} ) {
1420 3 my $image = $self->{'rdf:RDF'}->{image};
1421 3 my $array = [];
1422 3 foreach my $key (qw( url title link )) {
1423 9 ▶ push( @$array, exists $image->{$key} ? $image->{$key} : undef );
Branch: 1 branch
BranchTrueFalseTotal
exists $image->{$key} ? : 5 4 9
1424 }
1425 3 ▶ return wantarray ? @$array : shift @$array;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 1 3
1426 }
1427 elsif ( exists $self->{'rdf:RDF'}->{channel}->{image} ) {
1428 0 return $self->{'rdf:RDF'}->{channel}->{image}->{'-rdf:resource'};
1429 }
1430 22 undef;
1431 }
1432  
1433 # ----------------------------------------------------------------
1434 package XML::FeedPP::RDF::Channel;
1435 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1436 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1437 44 @ISA = qw( XML::FeedPP::Element );
1438  
1439 # ----------------------------------------------------------------
1440 package XML::FeedPP::RDF::Item;
1441 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1442 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1443 44 @ISA = qw( XML::FeedPP::Item );
1444  
1445 56 ▶sub title { shift->get_or_set( "title", @_ ); }
Subroutine title: called CC=1 SCAR=0.0
1446 29 ▶sub description { shift->get_or_set( "description", @_ ); }
Subroutine description: called CC=1 SCAR=0.0
1447 54 ▶sub category { shift->get_set_array( "dc:subject", @_ ); }
Subroutine category: called CC=1 SCAR=0.0
1448 43 ▶sub guid { undef; } # this element is NOT supported for RDF
Subroutine guid: called CC=1 SCAR=0.0
1449  
1450 26 ▶sub author {
Subroutine author: called CC=3 SCAR=11.0
1451 26 my $self = shift;
1452 26 my $author = shift;
1453 26 ▶ return $self->get_value('dc:creator')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $author 21 5 26
Condition66%2/3
$self->get_value('dc:creator') || $self->get_value('creator')
l!l&&r!l&&!r
7014
MC/DC50%1/2
$self->get_value('dc:creator') || $self->get_value('creator')
$self->get_value('dc:creator') $self->get_value('creator')
Truth table66%2/3
A || B
A= $self->get_value('dc:creator')B= $self->get_value('creator')
ABresult
1X1
011
000
1454 || $self->get_value('creator') unless defined $author;
1455 5 $self->set_value( 'dc:creator' => $author );
1456 }
1457  
1458 273 ▶sub link {
Subroutine link: called CC=2 SCAR=6.9
1459 273 my $self = shift;
1460 273 my $link = shift;
1461 273 ▶ return $self->get_value("link") unless defined $link;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $link 200 73 273
1462 73 $self->{'-rdf:about'} = $link;
1463 73 $self->set_value( "link", $link, @_ );
1464 }
1465  
1466 95 ▶sub pubDate {
Subroutine pubDate: called CC=2 SCAR=6.9
1467 95 my $self = shift;
1468 95 my $date = shift;
1469 95 ▶ return $self->get_pubDate_w3cdtf() unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 37 58 95
1470 58 $date = XML::FeedPP::Util::get_w3cdtf($date);
1471 58 $self->set_value( "dc:date", $date );
1472 }
1473  
1474 124 ▶sub get_pubDate_native {
Subroutine get_pubDate_native: called CC=1 SCAR=0.0
1475 124 shift->get_value("dc:date");
1476 }
1477  
1478 44 *get_pubDate_w3cdtf = \&get_pubDate_native;
1479  
1480 # ----------------------------------------------------------------
1481 package XML::FeedPP::Atom::Common;
1482 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1483 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1484 44 @ISA = qw( XML::FeedPP );
1485  
1486 0 ▶sub merge_native_channel {
Subroutine merge_native_channel: not called CC=2 SCAR=17.9
1487 0 my $self = shift;
1488 0 ▶ my $tree = shift or next;
Branch: 1 branch
BranchTrueFalseTotal
my $tree = shift() or next 0 0 0
1489  
1490 0 XML::FeedPP::Util::merge_hash( $self->{feed}, $tree->{feed}, qw( entry ) );
1491 }
1492  
1493 80 ▶sub add_item {
Subroutine add_item: called CC=6 SCAR=18.0
1494 80 my $self = shift;
1495 80 my( $init, $link, @rest ) = &XML::FeedPP::Util::param_even_odd(@_);
1496  
1497 80 ▶ Carp::croak "add_item needs an argument" if ( ! ref $init && ! $link );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $init or $link 0 80 80
Condition66%2/3
ref $init or $link
l!l&&r!l&&!r
11690
MC/DC0%0/2
ref $init or $link
ref $init $link
Truth table66%2/3
A or B
A= ref $initB= $link
ABresult
1X1
011
000
1498 80 ▶ if ( ref $link ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $link) 14 66 80
1499 14 return $self->add_clone_item( $link );
1500 }
1501  
1502 66 my $item = $self->item_class->new(@rest);
1503 66 ▶ $item->link($link) if $link;
Branch: 1 branch
BranchTrueFalseTotal
if $link 55 11 66
1504 66 ▶ $item->elements(@$init) if ref $init;
Branch: 1 branch
BranchTrueFalseTotal
if ref $init 11 55 66
1505 66 push( @{ $self->{feed}->{entry} }, $item );
1506  
1507 66 $item;
1508 }
1509  
1510 1 ▶sub clear_item {
Subroutine clear_item: called CC=1 SCAR=0.0
1511 1 my $self = shift;
1512 1 $self->{feed}->{entry} = [];
1513 }
1514  
1515 7 ▶sub remove_item {
Subroutine remove_item: called CC=4 SCAR=13.9
1516 7 my $self = shift;
1517 7 my $remove = shift;
1518 7 ▶ my $list = $self->{feed}->{entry} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"feed"}{"entry"} or return 7 0 7
1519 7 my @deleted;
1520  
1521 7 ▶ if ( $remove =~ /^-?\d+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove =~ /^-?\d+/) { } 6 1 7
1522 6 @deleted = splice( @$list, $remove, 1 );
1523 }
1524 else {
1525 1 @deleted = grep { $_->link() eq $remove } @$list;
1526 1 @$list = grep { $_->link() ne $remove } @$list;
1527 }
1528  
1529 7 ▶ wantarray ? @deleted : shift @deleted;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
1530 }
1531  
1532 104 ▶sub get_item {
Subroutine get_item: called CC=4 SCAR=13.9
1533 104 my $self = shift;
1534 104 my $num = shift;
1535 104 ▶ $self->{feed}->{entry} ||= [];
Condition50%1/2
$self->{"feed"}{"entry"} ||= []
l!l
1040
MC/DC0%0/1
$self->{"feed"}{"entry"} ||= []
$self->{"feed"}{"entry"}
Truth table50%1/2
A
A= $self->{"feed"}{"entry"}
Aresult
11
00
1536 104 ▶ if ( defined $num ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $num) { } 35 69 104
elsif (wantarray) { } 29 40 69
1537 35 return $self->{feed}->{entry}->[$num];
1538 }
1539 elsif (wantarray) {
1540 29 return @{ $self->{feed}->{entry} };
1541 }
1542 else {
1543 40 return scalar @{ $self->{feed}->{entry} };
1544 }
1545 }
1546  
1547 12 ▶sub sort_item {
Subroutine sort_item: called CC=3 SCAR=11.0
1548 12 my $self = shift;
1549 12 ▶ my $list = $self->{feed}->{entry} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"feed"}{"entry"} or return 12 0 12
1550 12 ▶ my $epoch = [ map { $_->get_pubDate_epoch() || 0 } @$list ];
Condition100%2/2
$_->get_pubDate_epoch || 0
l!l
208
MC/DC100%1/1
$_->get_pubDate_epoch || 0
$_->get_pubDate_epoch
Truth table100%2/2
A
A= $_->get_pubDate_epoch
Aresult
11
00
1551 28 my $sorted = [ map { $list->[$_] } sort {
1552 12 $epoch->[$b] <=> $epoch->[$a]
1553 } 0 .. $#$list ];
1554 12 @$list = @$sorted;
1555 12 scalar @$list;
1556 }
1557  
1558 10 ▶sub uniq_item {
Subroutine uniq_item: called CC=4 SCAR=13.9
1559 10 my $self = shift;
1560 10 ▶ my $list = $self->{feed}->{entry} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"feed"}{"entry"} or return 10 0 10
1561 10 my (%check, @uniq);
1562 10 foreach my $item (@$list) {
1563 18 my $link = $item->guid();
1564 18 ▶ push( @uniq, $item ) unless $check{$link}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $check{$link}++ 16 2 18
1565 }
1566 10 @$list = @uniq;
1567 }
1568  
1569 7 ▶sub limit_item {
Subroutine limit_item: called CC=6 SCAR=17.9
1570 7 my $self = shift;
1571 7 my $limit = shift;
1572 7 ▶ my $list = $self->{feed}->{entry} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->{"feed"}{"entry"} or return 7 0 7
1573 7 ▶ if ( $limit > 0 && $limit < scalar @$list ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($limit > 0 and $limit < scalar @$list) { } 3 4 7
elsif ($limit < 0 and -$limit < scalar @$list) { } 2 3 5
Condition100%3/3
$limit > 0 and $limit < scalar @$list
!ll&&!rl&&r
313
MC/DC100%2/2
$limit > 0 and $limit < scalar @$list
$limit > 0 $limit < scalar @$list
Truth table100%3/3
A and B
A= $limit > 0B= $limit < scalar @$list
ABresult
0X0
100
111
1574 3 @$list = splice( @$list, 0, $limit ); # remove from end
1575 }
1576 ▶ elsif ( $limit < 0 && -$limit < scalar @$list ) {
Condition100%3/3
$limit < 0 and -$limit < scalar @$list
!ll&&!rl&&r
112
MC/DC100%2/2
$limit < 0 and -$limit < scalar @$list
$limit < 0 -$limit < scalar @$list
Truth table100%3/3
A and B
A= $limit < 0B= -$limit < scalar @$list
ABresult
0X0
100
111
1577 2 @$list = splice( @$list, $limit ); # remove from start
1578 }
1579 7 scalar @$list;
1580 }
1581  
1582 98 ▶sub docroot { shift->{feed}; }
Subroutine docroot: called CC=1 SCAR=0.0
1583 0 ▶sub channel { shift->{feed}; }
Subroutine channel: not called CC=1 SCAR=6.9
1584 1 ▶sub set { shift->{feed}->set(@_); }
Subroutine set: called CC=1 SCAR=0.0
1585 1 ▶sub get { shift->{feed}->get(@_); }
Subroutine get: called CC=1 SCAR=0.0
1586  
1587 29 ▶sub language {
Subroutine language: called CC=2 SCAR=6.9
1588 29 my $self = shift;
1589 29 my $lang = shift;
1590 29 ▶ return $self->{feed}->{'-xml:lang'} unless defined $lang;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lang 21 8 29
1591 8 $self->{feed}->{'-xml:lang'} = $lang;
1592 }
1593  
1594 27 ▶sub image {
Subroutine image: called CC=17 SCAR=30.0
1595 27 my $self = shift;
1596 27 my $href = shift;
1597 27 my $title = shift;
1598  
1599 27 ▶ my $link = $self->{feed}->{link} || [];
Condition100%2/2
$self->{'feed'}{'link'} || []
l!l
216
MC/DC100%1/1
$self->{'feed'}{'link'} || []
$self->{'feed'}{'link'}
Truth table100%2/2
A
A= $self->{'feed'}{'link'}
Aresult
11
00
1600 27 ▶ $link = [$link] if UNIVERSAL::isa( $link, 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($link, "HASH") 2 25 27
1601 my $icon = (
1602 grep {
1603 27 ref $_
1604 && exists $_->{'-rel'}
1605 30 ▶ && ($_->{'-rel'} eq "icon" )
Condition50%3/6
ref $_ && exists $_->{'-rel'} && $_->{'-rel'} eq 'icon'
!ll&&!rl&&r
0219
ref $_ and exists $_->{"-rel"}
!ll&&!rl&&r
0030
MC/DC33%1/3
ref $_ && exists $_->{'-rel'} && $_->{'-rel'} eq 'icon'
ref $_ exists $_->{"-rel"} $_->{'-rel'} eq 'icon'
Truth table50%2/4
A and B && C
A= ref $_B= exists $_->{"-rel"}C= $_->{'-rel'} eq 'icon'
ABCresult
0XX0
10X0
1100
1111
1606 } @$link
1607 )[0];
1608  
1609 27 my $rext = join( "|", map {"\Q$_\E"} keys %$XML::FeedPP::MIME_TYPES );
1610  
1611 27 ▶ if ( defined $href ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $href) { } 6 21 27
elsif (ref $icon) { } 8 13 21
1612 6 my $ext = ( $href =~ m#[^/]\.($rext)(\W|$)#i )[0];
1613 6 ▶ my $type = $XML::FeedPP::MIME_TYPES->{$ext} if $ext;
Branch: 1 branch
BranchTrueFalseTotal
if $ext 6 0 6
1614  
1615 6 ▶ if ( ref $icon ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $icon) { } 1 5 6
1616 1 $icon->{'-href'} = $href;
1617 1 ▶ $icon->{'-type'} = $type if $type;
Branch: 1 branch
BranchTrueFalseTotal
if $type 1 0 1
1618 1 ▶ $icon->{'-title'} = $title if $title;
Branch: 1 branch
BranchTrueFalseTotal
if $title 0 1 1
1619 }
1620 else {
1621 5 my $newicon = {};
1622 5 $newicon->{'-rel'} = 'icon';
1623 5 $newicon->{'-href'} = $href;
1624 5 ▶ $newicon->{'-type'} = $type if $type;
Branch: 1 branch
BranchTrueFalseTotal
if $type 5 0 5
1625 5 ▶ $newicon->{'-title'} = $title if $title;
Branch: 1 branch
BranchTrueFalseTotal
if $title 0 5 5
1626 5 my $flink = $self->{feed}->{link};
1627 5 ▶ if ( UNIVERSAL::isa( $flink, 'ARRAY' )) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($flink, 'ARRAY')) { } 5 0 5
elsif (UNIVERSAL::isa($flink, 'HASH')) { } 0 0 0
1628 5 push( @$flink, $newicon );
1629 }
1630 elsif ( UNIVERSAL::isa( $flink, 'HASH' )) {
1631 0 $self->{feed}->{link} = [ $flink, $newicon ];
1632 }
1633 else {
1634 0 $self->{feed}->{link} = [ $newicon ];
1635 }
1636 }
1637 }
1638 elsif ( ref $icon ) {
1639 8 my $array = [ $icon->{'-href'} ];
1640 8 ▶ push( @$array, $icon->{'-title'} ) if exists $icon->{'-title'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $icon->{"-title"} 0 8 8
1641 8 ▶ return wantarray ? @$array : shift @$array;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 6 8
1642 }
1643 19 undef;
1644 }
1645  
1646 # ----------------------------------------------------------------
1647 package XML::FeedPP::Atom::Atom03;
1648 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1649 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1650 44 @ISA = qw( XML::FeedPP::Atom::Common );
1651  
1652 66 ▶sub channel_class {
Subroutine channel_class: called CC=1 SCAR=0.0
1653 66 'XML::FeedPP::Atom::Atom03::Feed';
1654 }
1655  
1656 69 ▶sub item_class {
Subroutine item_class: called CC=1 SCAR=0.0
1657 69 'XML::FeedPP::Atom::Atom03::Entry';
1658 }
1659  
1660 29 ▶sub test_feed {
Subroutine test_feed: called CC=6 SCAR=18.2
1661 29 my $self = shift;
1662 29 ▶ my $source = shift || $self;
Condition66%2/3
shift() || $self
l!l&&r!l&&!r
15140
MC/DC0%0/2
shift() || $self
shift() $self
Truth table66%2/3
A || B
A= shift()B= $self
ABresult
1X1
011
000
1663 29 ▶ return unless ref $source;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source 0 29 29
1664 29 ▶ return unless ref $source->{feed};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source->{"feed"} 1 28 29
1665 28 ▶ return unless exists $source->{feed}->{-xmlns};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $source->{"feed"}{"-xmlns"} 0 28 28
1666 28 my $xmlns = $source->{feed}->{-xmlns};
1667 28 ▶ return if ($xmlns ne $XML::FeedPP::XMLNS_ATOM03);
Branch: 1 branch
BranchTrueFalseTotal
if $xmlns ne $XML::FeedPP::XMLNS_ATOM03 1 27 28
1668 27 __PACKAGE__;
1669 }
1670  
1671 41 ▶sub init_feed {
Subroutine init_feed: called CC=9 SCAR=23.0
1672 41 ▶ my $self = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or return 41 0 41
1673  
1674 41 ▶ $self->{feed} ||= $self->channel_class->new();
Condition66%2/3
$self->{"feed"} ||= $self->channel_class->new
l!l&&r!l&&!r
16250
MC/DC0%0/2
$self->{"feed"} ||= $self->channel_class->new
$self->{"feed"} $self->channel_class->new
Truth table66%2/3
A ||= B
A= $self->{"feed"}B= $self->channel_class->new
ABresult
1X1
011
000
1675 41 $self->channel_class->ref_bless( $self->{feed} );
1676  
1677 41 ▶ if ( ! UNIVERSAL::isa( $self->{feed}, 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($self->{"feed"}, "HASH")) 0 41 41
1678 0 Carp::croak "Invalid Atom 0.3 feed format: $self->{feed}";
1679 }
1680  
1681 41 $self->xmlns( 'xmlns' => $XML::FeedPP::XMLNS_ATOM03 );
1682 41 ▶ $self->{feed}->{'-version'} ||= $XML::FeedPP::ATOM03_VERSION;
Condition66%2/3
$self->{"feed"}{"-version"} ||= $XML::FeedPP::ATOM03_VERSION
l!l&&r!l&&!r
15260
MC/DC0%0/2
$self->{"feed"}{"-version"} ||= $XML::FeedPP::ATOM03_VERSION
$self->{"feed"}{"-version"} $XML::FeedPP::ATOM03_VERSION
Truth table66%2/3
A ||= B
A= $self->{"feed"}{"-version"}B= $XML::FeedPP::ATOM03_VERSION
ABresult
1X1
011
000
1683  
1684 41 ▶ $self->{feed}->{entry} ||= [];
Condition100%2/2
$self->{"feed"}{"entry"} ||= []
l!l
1031
MC/DC100%1/1
$self->{"feed"}{"entry"} ||= []
$self->{"feed"}{"entry"}
Truth table100%2/2
A
A= $self->{"feed"}{"entry"}
Aresult
11
00
1685 41 ▶ if ( UNIVERSAL::isa( $self->{feed}->{entry}, 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($self->{"feed"}{"entry"}, "HASH")) 0 41 41
1686 # if this feed has only one item
1687 0 $self->{feed}->{entry} = [ $self->{feed}->{entry} ];
1688 }
1689 41 foreach my $item ( @{ $self->{feed}->{entry} } ) {
1690 16 $self->item_class->ref_bless($item);
1691 }
1692 41 ▶ $self->{feed}->{author} ||= { name => '' }; # dummy for validation
Condition100%2/2
$self->{"feed"}{"author"} ||= {"name", ""}
l!l
1031
MC/DC100%1/1
$self->{"feed"}{"author"} ||= {"name", ""}
$self->{"feed"}{"author"}
Truth table100%2/2
A
A= $self->{"feed"}{"author"}
Aresult
11
00
1693 41 $self;
1694 }
1695  
1696 37 ▶sub title {
Subroutine title: called CC=2 SCAR=6.9
1697 37 my $self = shift;
1698 37 my $title = shift;
1699 37 ▶ return $self->{feed}->get_value('title') unless defined $title;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title 24 13 37
1700 13 $self->{feed}->set_value( 'title' => $title, type => 'text/plain' );
1701 }
1702  
1703 26 ▶sub description {
Subroutine description: called CC=3 SCAR=11.0
1704 26 my $self = shift;
1705 26 my $desc = shift;
1706 return $self->{feed}->get_value('tagline')
1707 26 ▶ || $self->{feed}->get_value('subtitle') unless defined $desc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $desc 19 7 26
Condition66%2/3
$self->{'feed'}->get_value('tagline') || $self->{'feed'}->get_value('subtitle')
l!l&&r!l&&!r
9010
MC/DC50%1/2
$self->{'feed'}->get_value('tagline') || $self->{'feed'}->get_value('subtitle')
$self->{'feed'}->get_value('tagline') $self->{'feed'}->get_value('subtitle')
Truth table66%2/3
A || B
A= $self->{'feed'}->get_value('tagline')B= $self->{'feed'}->get_value('subtitle')
ABresult
1X1
011
000
1708 7 $self->{feed}->set_value( 'tagline' => $desc, type => 'text/html', mode => 'escaped' );
1709 }
1710  
1711 37 ▶sub pubDate {
Subroutine pubDate: called CC=2 SCAR=6.9
1712 37 my $self = shift;
1713 37 my $date = shift;
1714 37 ▶ return $self->get_pubDate_w3cdtf() unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 23 14 37
1715 14 $date = XML::FeedPP::Util::get_w3cdtf($date);
1716 14 $self->{feed}->set_value( 'modified', $date );
1717 }
1718  
1719 37 ▶sub get_pubDate_native {
Subroutine get_pubDate_native: called CC=2 SCAR=6.9
1720 37 my $self = shift;
1721 $self->{feed}->get_value('modified') # Atom 0.3
1722 37 ▶ || $self->{feed}->get_value('updated'); # Atom 1.0
Branch: 1 branch
BranchTrueFalseTotal
$self->{"feed"}->get_value("modified") or $self->{"feed"}->get_value("updated") 22 15 37
1723 }
1724  
1725 44 *get_pubDate_w3cdtf = \&get_pubDate_native;
1726  
1727 22 ▶sub copyright {
Subroutine copyright: called CC=3 SCAR=11.0
1728 22 my $self = shift;
1729 22 my $copy = shift;
1730 return $self->{feed}->get_value('copyright')
1731 22 ▶ || $self->{feed}->get_value('rights') unless defined $copy;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $copy 16 6 22
Condition66%2/3
$self->{'feed'}->get_value('copyright') || $self->{'feed'}->get_value('rights')
l!l&&r!l&&!r
6010
MC/DC50%1/2
$self->{'feed'}->get_value('copyright') || $self->{'feed'}->get_value('rights')
$self->{'feed'}->get_value('copyright') $self->{'feed'}->get_value('rights')
Truth table66%2/3
A || B
A= $self->{'feed'}->get_value('copyright')B= $self->{'feed'}->get_value('rights')
ABresult
1X1
011
000
1732 6 $self->{feed}->set_value( 'copyright' => $copy );
1733 }
1734  
1735 45 ▶sub link {
Subroutine link: called CC=11 SCAR=24.9
1736 45 my $self = shift;
1737 45 my $href = shift;
1738  
1739 45 ▶ my $link = $self->{feed}->{link} || [];
Condition100%2/2
$self->{'feed'}{'link'} || []
l!l
2124
MC/DC100%1/1
$self->{'feed'}{'link'} || []
$self->{'feed'}{'link'}
Truth table100%2/2
A
A= $self->{'feed'}{'link'}
Aresult
11
00
1740 45 ▶ $link = [$link] if UNIVERSAL::isa( $link, 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($link, "HASH") 10 35 45
1741 45 $link = [ grep { ref $_ } @$link ];
1742 $link = [ grep {
1743 45 ▶ ! exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
Condition66%2/3
!exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
l!l&&r!l&&!r
0218
MC/DC50%1/2
!exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
!exists $_->{'-rel'} $_->{'-rel'} eq 'alternate'
Truth table66%2/3
not(A) || B
A= !exists $_->{'-rel'}B= $_->{'-rel'} eq 'alternate'
ABresult
1X1
011
000
1744 } @$link ];
1745 $link = [ grep {
1746 45 ▶ ! exists $_->{'-type'} || $_->{'-type'} =~ m#^text/(x-)?html#i
Condition66%2/3
!exists $_->{'-type'} || $_->{'-type'} =~ m[^text/(x-)?html]i
l!l&&r!l&&!r
1200
MC/DC0%0/2
!exists $_->{'-type'} || $_->{'-type'} =~ m[^text/(x-)?html]i
!exists $_->{'-type'} $_->{'-type'} =~ m[^text/(x-)?html]i
Truth table66%2/3
not(A) || B
A= !exists $_->{'-type'}B= $_->{'-type'} =~ m[^text/(x-)?html]i
ABresult
1X1
011
000
1747 } @$link ];
1748 45 my $html = shift @$link;
1749  
1750 45 ▶ if ( defined $href ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $href) { } 18 27 45
elsif (ref $html) { } 19 8 27
1751 18 ▶ if ( ref $html ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $html) { } 2 16 18
1752 2 $html->{'-href'} = $href;
1753 }
1754 else {
1755 16 my $hash = {
1756 -rel => 'alternate',
1757 -type => 'text/html',
1758 -href => $href,
1759 };
1760 16 my $flink = $self->{feed}->{link};
1761 16 ▶ if ( ! ref $flink ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $flink) { } 16 0 16
elsif (UNIVERSAL::isa($flink, 'ARRAY')) { } 0 0 0
elsif (UNIVERSAL::isa($flink, 'HASH')) { } 0 0 0
1762 16 $self->{feed}->{link} = [ $hash ];
1763 }
1764 elsif ( UNIVERSAL::isa( $flink, 'ARRAY' )) {
1765 0 push( @$flink, $hash );
1766 }
1767 elsif ( UNIVERSAL::isa( $flink, 'HASH' )) {
1768 0 $self->{feed}->{link} = [ $flink, $hash ];
1769 }
1770 }
1771 }
1772 elsif ( ref $html ) {
1773 19 return $html->{'-href'};
1774 }
1775 26 return;
1776 }
1777  
1778 # ----------------------------------------------------------------
1779 package XML::FeedPP::Atom::Atom10;
1780 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1781 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1782 44 @ISA = qw( XML::FeedPP::Atom::Common );
1783  
1784 24 ▶sub channel_class {
Subroutine channel_class: called CC=1 SCAR=0.0
1785 24 'XML::FeedPP::Atom::Atom10::Feed';
1786 }
1787  
1788 28 ▶sub item_class {
Subroutine item_class: called CC=1 SCAR=0.0
1789 28 'XML::FeedPP::Atom::Atom10::Entry';
1790 }
1791  
1792 34 ▶sub test_feed {
Subroutine test_feed: called CC=6 SCAR=18.2
1793 34 my $self = shift;
1794 34 ▶ my $source = shift || $self;
Condition66%2/3
shift() || $self
l!l&&r!l&&!r
24100
MC/DC0%0/2
shift() || $self
shift() $self
Truth table66%2/3
A || B
A= shift()B= $self
ABresult
1X1
011
000
1795 34 ▶ return unless ref $source;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source 0 34 34
1796 34 ▶ return unless ref $source->{feed};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source->{"feed"} 1 33 34
1797 33 ▶ return unless exists $source->{feed}->{-xmlns};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $source->{"feed"}{"-xmlns"} 0 33 33
1798 33 my $xmlns = $source->{feed}->{-xmlns};
1799 33 ▶ return if ($xmlns ne $XML::FeedPP::XMLNS_ATOM10);
Branch: 1 branch
BranchTrueFalseTotal
if $xmlns ne $XML::FeedPP::XMLNS_ATOM10 14 19 33
1800 19 __PACKAGE__;
1801 }
1802  
1803 17 ▶sub init_feed {
Subroutine init_feed: called CC=7 SCAR=20.5
1804 17 ▶ my $self = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or return 17 0 17
1805  
1806 17 ▶ $self->{feed} ||= $self->channel_class->new();
Condition66%2/3
$self->{"feed"} ||= $self->channel_class->new
l!l&&r!l&&!r
1070
MC/DC0%0/2
$self->{"feed"} ||= $self->channel_class->new
$self->{"feed"} $self->channel_class->new
Truth table66%2/3
A ||= B
A= $self->{"feed"}B= $self->channel_class->new
ABresult
1X1
011
000
1807 17 $self->channel_class->ref_bless( $self->{feed} );
1808  
1809 17 ▶ if ( ! UNIVERSAL::isa( $self->{feed}, 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($self->{"feed"}, "HASH")) 0 17 17
1810 0 Carp::croak "Invalid Atom 1.0 feed format: $self->{feed}";
1811 }
1812  
1813 17 $self->xmlns( 'xmlns' => $XML::FeedPP::XMLNS_ATOM10 );
1814 # $self->{feed}->{'-version'} ||= $XML::FeedPP::ATOM10_VERSION;
1815  
1816 17 ▶ $self->{feed}->{entry} ||= [];
Condition100%2/2
$self->{"feed"}{"entry"} ||= []
l!l
611
MC/DC100%1/1
$self->{"feed"}{"entry"} ||= []
$self->{"feed"}{"entry"}
Truth table100%2/2
A
A= $self->{"feed"}{"entry"}
Aresult
11
00
1817 17 ▶ if ( UNIVERSAL::isa( $self->{feed}->{entry}, 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($self->{"feed"}{"entry"}, "HASH")) 0 17 17
1818 # if this feed has only one item
1819 0 $self->{feed}->{entry} = [ $self->{feed}->{entry} ];
1820 }
1821 17 foreach my $item ( @{ $self->{feed}->{entry} } ) {
1822 15 $self->item_class->ref_bless($item);
1823 }
1824 # $self->{feed}->{author} ||= { name => '' }; # dummy for validation
1825 17 $self;
1826 }
1827  
1828 17 ▶sub title {
Subroutine title: called CC=2 SCAR=6.9
1829 17 my $self = shift;
1830 17 my $title = shift;
1831 17 ▶ return $self->{feed}->get_value('title') unless defined $title;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title 14 3 17
1832 3 $self->{feed}->set_value( 'title' => $title, @_ );
1833 }
1834  
1835 12 ▶sub description {
Subroutine description: called CC=5 SCAR=16.2
1836 12 my $self = shift;
1837 12 my $desc = shift;
1838 return $self->{feed}->get_value('content')
1839 || $self->{feed}->get_value('summary')
1840 || $self->{feed}->get_value('subtitle')
1841 12 ▶ || $self->{feed}->get_value('tagline') unless defined $desc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $desc 9 3 12
Condition77%7/9
$self->{'feed'}->get_value('content') || $self->{'feed'}->get_value('summary') || $self->{'feed'}->get_value('subtitle') || $self->{'feed'}->get_value('tagline')
l!l&&r!l&&!r
603
$self->{"feed"}->get_value("content") or $self->{"feed"}->get_value("summary") or $self->{"feed"}->get_value("subtitle")
l!l&&r!l&&!r
423
$self->{"feed"}->get_value("content") or $self->{"feed"}->get_value("summary")
l!l&&r!l&&!r
405
MC/DC50%2/4
$self->{'feed'}->get_value('content') || $self->{'feed'}->get_value('summary') || $self->{'feed'}->get_value('subtitle') || $self->{'feed'}->get_value('tagline')
$self->{"feed"}->get_value("content") $self->{"feed"}->get_value("summary") $self->{"feed"}->get_value("subtitle") $self->{'feed'}->get_value('tagline')
Truth table60%3/5
A or B or C || D
A= $self->{"feed"}->get_value("content")B= $self->{"feed"}->get_value("summary")C= $self->{"feed"}->get_value("subtitle")D= $self->{'feed'}->get_value('tagline')
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1842 3 $self->{feed}->set_value( 'content' => $desc, @_ ); # type => 'text'
1843 }
1844  
1845 9 ▶sub pubDate {
Subroutine pubDate: called CC=2 SCAR=6.9
1846 9 my $self = shift;
1847 9 my $date = shift;
1848 9 ▶ return $self->get_pubDate_w3cdtf() unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 7 2 9
1849 2 $date = XML::FeedPP::Util::get_w3cdtf($date);
1850 2 $self->{feed}->set_value( 'updated', $date );
1851 }
1852  
1853 9 ▶sub get_pubDate_native {
Subroutine get_pubDate_native: called CC=2 SCAR=6.9
1854 9 my $self = shift;
1855 $self->{feed}->get_value('updated') # Atom 1.0
1856 9 ▶ || $self->{feed}->get_value('modified') # Atom 0.3
Branch: 1 branch
BranchTrueFalseTotal
$self->{"feed"}->get_value("updated") or $self->{"feed"}->get_value("modified") 4 5 9
1857 }
1858  
1859 44 *get_pubDate_w3cdtf = \&get_pubDate_native;
1860  
1861 8 ▶sub copyright {
Subroutine copyright: called CC=3 SCAR=11.0
1862 8 my $self = shift;
1863 8 my $copy = shift;
1864 return $self->{feed}->get_value('rights')
1865 8 ▶ || $self->{feed}->get_value('copyright') unless defined $copy;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $copy 6 2 8
Condition66%2/3
$self->{'feed'}->get_value('rights') || $self->{'feed'}->get_value('copyright')
l!l&&r!l&&!r
303
MC/DC50%1/2
$self->{'feed'}->get_value('rights') || $self->{'feed'}->get_value('copyright')
$self->{'feed'}->get_value('rights') $self->{'feed'}->get_value('copyright')
Truth table66%2/3
A || B
A= $self->{'feed'}->get_value('rights')B= $self->{'feed'}->get_value('copyright')
ABresult
1X1
011
000
1866 2 $self->{feed}->set_value( 'rights' => $copy );
1867 }
1868  
1869 18 ▶sub link {
Subroutine link: called CC=10 SCAR=23.6
1870 18 my $self = shift;
1871 18 my $href = shift;
1872  
1873 18 ▶ my $link = $self->{feed}->{link} || [];
Condition100%2/2
$self->{'feed'}{'link'} || []
l!l
108
MC/DC100%1/1
$self->{'feed'}{'link'} || []
$self->{'feed'}{'link'}
Truth table100%2/2
A
A= $self->{'feed'}{'link'}
Aresult
11
00
1874 18 ▶ $link = [$link] if UNIVERSAL::isa( $link, 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($link, "HASH") 6 12 18
1875 18 $link = [ grep { ref $_ } @$link ];
1876 $link = [ grep {
1877 18 ▶ ! exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
Condition100%3/3
!exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
l!l&&r!l&&!r
192
MC/DC100%2/2
!exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
!exists $_->{'-rel'} $_->{'-rel'} eq 'alternate'
Truth table100%3/3
not(A) || B
A= !exists $_->{'-rel'}B= $_->{'-rel'} eq 'alternate'
ABresult
1X1
011
000
1878 } @$link ];
1879 18 my $html = shift @$link;
1880  
1881 18 ▶ if ( defined $href ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $href) { } 6 12 18
elsif (ref $html) { } 9 3 12
1882 6 ▶ if ( ref $html ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $html) { } 1 5 6
1883 1 $html->{'-href'} = $href;
1884 }
1885 else {
1886 5 my $hash = {
1887 -rel => 'alternate',
1888 -href => $href,
1889 };
1890 5 my $flink = $self->{feed}->{link};
1891 5 ▶ if ( ! ref $flink ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $flink) { } 5 0 5
elsif (UNIVERSAL::isa($flink, 'ARRAY')) { } 0 0 0
elsif (UNIVERSAL::isa($flink, 'HASH')) { } 0 0 0
1892 5 $self->{feed}->{link} = [ $hash ];
1893 }
1894 elsif ( UNIVERSAL::isa( $flink, 'ARRAY' )) {
1895 0 push( @$flink, $hash );
1896 }
1897 elsif ( UNIVERSAL::isa( $flink, 'HASH' )) {
1898 0 $self->{feed}->{link} = [ $flink, $hash ];
1899 }
1900 }
1901 }
1902 elsif ( ref $html ) {
1903 9 return $html->{'-href'};
1904 }
1905 9 return;
1906 }
1907  
1908 # ----------------------------------------------------------------
1909 package XML::FeedPP::Atom;
1910 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1911 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1912 44 @ISA = qw( XML::FeedPP::Atom::Atom03 );
1913  
1914 # @ISA = qw( XML::FeedPP::Atom::Atom10 ); # if Atom 1.0 for default
1915  
1916 4 ▶sub test_feed {
Subroutine test_feed: called CC=4 SCAR=14.0
1917 4 my $self = shift;
1918 4 ▶ my $source = shift || $self;
Condition66%2/3
shift() || $self
l!l&&r!l&&!r
220
MC/DC0%0/2
shift() || $self
shift() $self
Truth table66%2/3
A || B
A= shift()B= $self
ABresult
1X1
011
000
1919 4 ▶ return unless ref $source;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source 0 4 4
1920 4 ▶ return unless ref $source->{feed};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source->{"feed"} 1 3 4
1921 3 __PACKAGE__;
1922 }
1923  
1924 # ----------------------------------------------------------------
1925 package XML::FeedPP::Atom::Common::Feed;
1926 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1927 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1928 44 @ISA = qw( XML::FeedPP::Element );
1929  
1930 # <content type="xhtml"><div>...</div></content>
1931 # http://www.ietf.org/rfc/rfc4287.txt
1932 # 3. If the value of "type" is "xhtml", the content of atom:content
1933 # MUST be a single XHTML div element [XHTML] and SHOULD be suitable
1934 # for handling as XHTML. The XHTML div element itself MUST NOT be
1935 # considered part of the content.
1936  
1937 139 ▶sub _fetch_value {
Subroutine _fetch_value: called CC=6 SCAR=18.1
1938 139 my $self = shift;
1939 139 my $value = shift;
1940  
1941 139 ▶ if ( UNIVERSAL::isa( $value, 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($value, "HASH") and exists $value->{"-type"} and $value->{"-type"} eq "xhtml") 6 133 139
Condition83%5/6
UNIVERSAL::isa($value, "HASH") and exists $value->{"-type"} and $value->{"-type"} eq "xhtml"
!ll&&!rl&&r
68656
UNIVERSAL::isa($value, "HASH") and exists $value->{"-type"}
!ll&&!rl&&r
68071
MC/DC66%2/3
UNIVERSAL::isa($value, "HASH") and exists $value->{"-type"} and $value->{"-type"} eq "xhtml"
UNIVERSAL::isa($value, "HASH") exists $value->{"-type"} $value->{"-type"} eq "xhtml"
Truth table75%3/4
A and B and C
A= UNIVERSAL::isa($value, "HASH")B= exists $value->{"-type"}C= $value->{"-type"} eq "xhtml"
ABCresult
0XX0
10X0
1100
1111
1942 && exists $value->{'-type'}
1943 && ($value->{'-type'} eq "xhtml")) {
1944 6 my $child = [ grep { /^[^\-\#]/ } keys %$value ];
1945 6 ▶ if (scalar @$child == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$child == 1) 6 0 6
1946 6 my $div = shift @$child;
1947 6 ▶ if ($div =~ /^([^:]+:)?div$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($div =~ /^([^:]+:)?div$/i) 6 0 6
1948 6 return $value->{$div};
1949 }
1950 }
1951 }
1952  
1953 133 $self->SUPER::_fetch_value($value);
1954 }
1955  
1956 # ----------------------------------------------------------------
1957 package XML::FeedPP::Atom::Atom03::Feed;
1958 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1959 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1960 44 @ISA = qw( XML::FeedPP::Atom::Common::Feed );
1961  
1962 # ----------------------------------------------------------------
1963 package XML::FeedPP::Atom::Atom10::Feed;
1964 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1965 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1966 44 @ISA = qw( XML::FeedPP::Atom::Common::Feed );
1967  
1968 # ----------------------------------------------------------------
1969 package XML::FeedPP::Atom::Common::Entry;
1970 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1971 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1972 44 @ISA = qw( XML::FeedPP::Item );
1973  
1974 31 ▶sub author {
Subroutine author: called CC=4 SCAR=13.9
1975 31 my $self = shift;
1976 31 my $name = shift;
1977 31 ▶ unless ( defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 22 9 31
1978 22 ▶ my $author = $self->{author}->{name} if ref $self->{author};
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"author"} 13 9 22
1979 22 return $author;
1980 }
1981 9 ▶ my $author = ref $name ? $name : { name => $name };
Branch: 1 branch
BranchTrueFalseTotal
ref $name ? : 0 9 9
1982 9 $self->{author} = $author;
1983 }
1984  
1985 187 ▶sub guid { shift->get_or_set( 'id', @_ ); }
Subroutine guid: called CC=1 SCAR=0.0
1986  
1987 44 *_fetch_value = \&XML::FeedPP::Atom::Common::Feed::_fetch_value;
1988  
1989 # ----------------------------------------------------------------
1990 package XML::FeedPP::Atom::Atom03::Entry;
1991 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1992 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
1993 44 @ISA = qw( XML::FeedPP::Atom::Common::Entry );
1994  
1995 24 ▶sub description {
Subroutine description: called CC=3 SCAR=11.0
1996 24 my $self = shift;
1997 24 my $desc = shift;
1998 24 ▶ return $self->get_value('content')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $desc 16 8 24
Condition100%3/3
$self->get_value('content') || $self->get_value('summary')
l!l&&r!l&&!r
1114
MC/DC100%2/2
$self->get_value('content') || $self->get_value('summary')
$self->get_value('content') $self->get_value('summary')
Truth table100%3/3
A || B
A= $self->get_value('content')B= $self->get_value('summary')
ABresult
1X1
011
000
1999 || $self->get_value('summary') unless defined $desc;
2000 8 $self->set_value(
2001 'content' => $desc,
2002 type => 'text/html',
2003 mode => 'escaped'
2004 );
2005 }
2006  
2007 106 ▶sub link {
Subroutine link: called CC=14 SCAR=30.2
2008 106 my $self = shift;
2009 106 my $href = shift;
2010  
2011 106 ▶ my $link = $self->{link} || [];
Condition100%2/2
$self->{'link'} || []
l!l
5353
MC/DC100%1/1
$self->{'link'} || []
$self->{'link'}
Truth table100%2/2
A
A= $self->{'link'}
Aresult
11
00
2012 106 ▶ $link = [$link] if UNIVERSAL::isa( $link, 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($link, "HASH") 10 96 106
2013 106 $link = [ grep { ref $_ } @$link ];
2014 $link = [ grep {
2015 106 ▶ ! exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
Condition33%1/3
!exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
l!l&&r!l&&!r
0530
MC/DC0%0/2
!exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
!exists $_->{'-rel'} $_->{'-rel'} eq 'alternate'
Truth table33%1/3
not(A) || B
A= !exists $_->{'-rel'}B= $_->{'-rel'} eq 'alternate'
ABresult
1X1
011
000
2016 } @$link ];
2017 $link = [ grep {
2018 106 ▶ ! exists $_->{'-type'} || $_->{'-type'} =~ m#^text/(x-)?html#i
Condition66%2/3
!exists $_->{'-type'} || $_->{'-type'} =~ m[^text/(x-)?html]i
l!l&&r!l&&!r
1520
MC/DC0%0/2
!exists $_->{'-type'} || $_->{'-type'} =~ m[^text/(x-)?html]i
!exists $_->{'-type'} $_->{'-type'} =~ m[^text/(x-)?html]i
Truth table66%2/3
not(A) || B
A= !exists $_->{'-type'}B= $_->{'-type'} =~ m[^text/(x-)?html]i
ABresult
1X1
011
000
2019 } @$link ];
2020 106 my $html = shift @$link;
2021  
2022 106 ▶ if ( defined $href ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $href) { } 54 52 106
elsif (ref $html) { } 52 0 52
2023 54 ▶ if ( ref $html ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $html) { } 1 53 54
2024 1 $html->{'-href'} = $href;
2025 }
2026 else {
2027 53 my $hash = {
2028 -rel => 'alternate',
2029 -type => 'text/html',
2030 -href => $href,
2031 };
2032 53 my $flink = $self->{link};
2033 53 ▶ if ( ! ref $flink ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $flink) { } 53 0 53
elsif (ref $flink and UNIVERSAL::isa($flink, 'ARRAY')) { } 0 0 0
elsif (ref $flink and UNIVERSAL::isa($flink, 'HASH')) { } 0 0 0
2034 53 $self->{link} = [ $hash ];
2035 }
2036 ▶ elsif ( ref $flink && UNIVERSAL::isa( $flink, 'ARRAY' )) {
Condition0%0/3
ref $flink and UNIVERSAL::isa($flink, "ARRAY")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $flink and UNIVERSAL::isa($flink, "ARRAY")
ref $flink UNIVERSAL::isa($flink, "ARRAY")
Truth table0%0/3
A and B
A= ref $flinkB= UNIVERSAL::isa($flink, "ARRAY")
ABresult
0X0
100
111
2037 0 push( @$flink, $hash );
2038 }
2039 ▶ elsif ( ref $flink && UNIVERSAL::isa( $flink, 'HASH' )) {
Condition0%0/3
ref $flink and UNIVERSAL::isa($flink, "HASH")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $flink and UNIVERSAL::isa($flink, "HASH")
ref $flink UNIVERSAL::isa($flink, "HASH")
Truth table0%0/3
A and B
A= ref $flinkB= UNIVERSAL::isa($flink, "HASH")
ABresult
0X0
100
111
2040 0 $self->{link} = [ $flink, $hash ];
2041 }
2042 }
2043 54 ▶ $self->guid( $href ) unless defined $self->guid();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->guid 52 2 54
2044 }
2045 elsif ( ref $html ) {
2046 52 return $html->{'-href'};
2047 }
2048 54 return;
2049 }
2050  
2051 57 ▶sub pubDate {
Subroutine pubDate: called CC=2 SCAR=6.9
2052 57 my $self = shift;
2053 57 my $date = shift;
2054 57 ▶ return $self->get_pubDate_w3cdtf() unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 19 38 57
2055 38 $date = XML::FeedPP::Util::get_w3cdtf($date);
2056 38 $self->set_value( 'issued', $date );
2057 38 $self->set_value( 'modified', $date );
2058 }
2059  
2060 66 ▶sub get_pubDate_native {
Subroutine get_pubDate_native: called CC=4 SCAR=14.2
2061 66 my $self = shift;
2062 66 ▶ $self->get_value('modified') # Atom 0.3
Branch: 1 branch
BranchTrueFalseTotal
$self->get_value("modified") or $self->get_value("issued") or $self->get_value("updated") or $self->get_value("published") 60 6 66
Condition66%4/6
$self->get_value("modified") or $self->get_value("issued") or $self->get_value("updated")
l!l&&r!l&&!r
6006
$self->get_value("modified") or $self->get_value("issued")
l!l&&r!l&&!r
6006
MC/DC33%1/3
$self->get_value("modified") or $self->get_value("issued") or $self->get_value("updated")
$self->get_value("modified") $self->get_value("issued") $self->get_value("updated")
Truth table50%2/4
A or B or C
A= $self->get_value("modified")B= $self->get_value("issued")C= $self->get_value("updated")
ABCresult
1XX1
01X1
0011
0000
2063 || $self->get_value('issued') # Atom 0.3
2064 || $self->get_value('updated') # Atom 1.0
2065 || $self->get_value('published'); # Atom 1.0
2066 }
2067  
2068 44 *get_pubDate_w3cdtf = \&get_pubDate_native;
2069  
2070 48 ▶sub title {
Subroutine title: called CC=2 SCAR=6.9
2071 48 my $self = shift;
2072 48 my $title = shift;
2073 48 ▶ return $self->get_value('title') unless defined $title;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title 23 25 48
2074 25 $self->set_value( 'title' => $title, type => 'text/plain' );
2075 }
2076  
2077 14 ▶sub category { undef; } # this element is NOT supported for Atom 0.3
Subroutine category: called CC=1 SCAR=0.0
2078  
2079 # ----------------------------------------------------------------
2080 package XML::FeedPP::Atom::Atom10::Entry;
2081 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2082 44 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
2083 44 @ISA = qw( XML::FeedPP::Atom::Common::Entry );
2084  
2085 18 ▶sub description {
Subroutine description: called CC=3 SCAR=11.0
2086 18 my $self = shift;
2087 18 my $desc = shift;
2088 18 ▶ return $self->get_value('content')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $desc 15 3 18
Condition100%3/3
$self->get_value('content') || $self->get_value('summary')
l!l&&r!l&&!r
915
MC/DC100%2/2
$self->get_value('content') || $self->get_value('summary')
$self->get_value('content') $self->get_value('summary')
Truth table100%3/3
A || B
A= $self->get_value('content')B= $self->get_value('summary')
ABresult
1X1
011
000
2089 || $self->get_value('summary') unless defined $desc;
2090 3 $self->set_value( 'content' => $desc, @_ );
2091 }
2092  
2093 24 ▶sub link {
Subroutine link: called CC=13 SCAR=28.4
2094 24 my $self = shift;
2095 24 my $href = shift;
2096  
2097 24 ▶ my $link = $self->{link} || [];
Condition100%2/2
$self->{'link'} || []
l!l
1113
MC/DC100%1/1
$self->{'link'} || []
$self->{'link'}
Truth table100%2/2
A
A= $self->{'link'}
Aresult
11
00
2098 24 ▶ $link = [$link] if UNIVERSAL::isa( $link, 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($link, "HASH") 7 17 24
2099 24 $link = [ grep { ref $_ } @$link ];
2100 $link = [ grep {
2101 24 ▶ ! exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
Condition100%3/3
!exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
l!l&&r!l&&!r
1011
MC/DC100%2/2
!exists $_->{'-rel'} || $_->{'-rel'} eq 'alternate'
!exists $_->{'-rel'} $_->{'-rel'} eq 'alternate'
Truth table100%3/3
not(A) || B
A= !exists $_->{'-rel'}B= $_->{'-rel'} eq 'alternate'
ABresult
1X1
011
000
2102 } @$link ];
2103 24 my $html = shift @$link;
2104  
2105 24 ▶ if ( defined $href ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $href) { } 14 10 24
elsif (ref $html) { } 10 0 10
2106 14 ▶ if ( ref $html ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $html) { } 1 13 14
2107 1 $html->{'-href'} = $href;
2108 }
2109 else {
2110 13 my $hash = {
2111 # -rel => 'alternate',
2112 -href => $href,
2113 };
2114 13 my $flink = $self->{link};
2115 13 ▶ if ( ! ref $flink ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $flink) { } 13 0 13
elsif (ref $flink and UNIVERSAL::isa($flink, 'ARRAY')) { } 0 0 0
elsif (ref $flink and UNIVERSAL::isa($flink, 'HASH')) { } 0 0 0
2116 13 $self->{link} = [ $hash ];
2117 }
2118 ▶ elsif ( ref $flink && UNIVERSAL::isa( $flink, 'ARRAY' )) {
Condition0%0/3
ref $flink and UNIVERSAL::isa($flink, "ARRAY")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $flink and UNIVERSAL::isa($flink, "ARRAY")
ref $flink UNIVERSAL::isa($flink, "ARRAY")
Truth table0%0/3
A and B
A= ref $flinkB= UNIVERSAL::isa($flink, "ARRAY")
ABresult
0X0
100
111
2119 0 push( @$flink, $hash );
2120 }
2121 ▶ elsif ( ref $flink && UNIVERSAL::isa( $flink, 'HASH' )) {
Condition0%0/3
ref $flink and UNIVERSAL::isa($flink, "HASH")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $flink and UNIVERSAL::isa($flink, "HASH")
ref $flink UNIVERSAL::isa($flink, "HASH")
Truth table0%0/3
A and B
A= ref $flinkB= UNIVERSAL::isa($flink, "HASH")
ABresult
0X0
100
111
2122 0 $self->{link} = [ $flink, $hash ];
2123 }
2124 }
2125 14 ▶ $self->guid( $href ) unless defined $self->guid();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->guid 13 1 14
2126 }
2127 elsif ( ref $html ) {
2128 10 return $html->{'-href'};
2129 }
2130 14 return;
2131 }
2132  
2133 13 ▶sub pubDate {
Subroutine pubDate: called CC=2 SCAR=6.9
2134 13 my $self = shift;
2135 13 my $date = shift;
2136 13 ▶ return $self->get_pubDate_w3cdtf() unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 9 4 13
2137 4 $date = XML::FeedPP::Util::get_w3cdtf($date);
2138 4 $self->set_value( 'updated', $date );
2139 }
2140  
2141 21 ▶sub get_pubDate_native {
Subroutine get_pubDate_native: called CC=4 SCAR=14.2
2142 21 my $self = shift;
2143 21 ▶ $self->get_value('updated') # Atom 1.0
Branch: 1 branch
BranchTrueFalseTotal
$self->get_value("updated") or $self->get_value("published") or $self->get_value("issued") or $self->get_value("modified") 4 17 21
Condition66%4/6
$self->get_value("updated") or $self->get_value("published") or $self->get_value("issued")
l!l&&r!l&&!r
4017
$self->get_value("updated") or $self->get_value("published")
l!l&&r!l&&!r
4017
MC/DC33%1/3
$self->get_value("updated") or $self->get_value("published") or $self->get_value("issued")
$self->get_value("updated") $self->get_value("published") $self->get_value("issued")
Truth table50%2/4
A or B or C
A= $self->get_value("updated")B= $self->get_value("published")C= $self->get_value("issued")
ABCresult
1XX1
01X1
0011
0000
2144 || $self->get_value('published') # Atom 1.0
2145 || $self->get_value('issued') # Atom 0.3
2146 || $self->get_value('modified'); # Atom 0.3
2147 }
2148  
2149 44 *get_pubDate_w3cdtf = \&get_pubDate_native;
2150  
2151 16 ▶sub title {
Subroutine title: called CC=3 SCAR=11.0
2152 16 my $self = shift;
2153 16 my $title = shift;
2154 16 ▶ my $type = shift || 'text';
Condition50%1/2
shift() || 'text'
l!l
016
MC/DC0%0/1
shift() || 'text'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
2155 16 ▶ return $self->get_value('title') unless defined $title;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title 11 5 16
2156 5 $self->set_value( 'title' => $title, type => $type );
2157 }
2158  
2159 35 ▶sub category {
Subroutine category: called CC=11 SCAR=24.8
2160 35 my $self = shift;
2161 35 ▶ if ( scalar @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) { } 15 20 35
2162 15 ▶ my $cate = ref $_[0] ? $_[0] : \@_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 5 10 15
2163 15 my $list = [ map {+{-term=>$_}} @$cate ];
2164 15 ▶ $self->{category} = ( scalar @$list > 1 ) ? $list : shift @$list;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$list > 1 ? : 6 9 15
2165 }
2166 else {
2167 20 ▶ return unless exists $self->{category};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"category"} 0 20 20
2168 20 ▶ my $list = $self->{category} || [];
Condition50%1/2
$self->{'category'} || []
l!l
200
MC/DC0%0/1
$self->{'category'} || []
$self->{'category'}
Truth table50%1/2
A
A= $self->{'category'}
Aresult
11
00
2169 20 ▶ $list = [ $list ] if ( defined $list && ! UNIVERSAL::isa( $list, 'ARRAY' ));
Branch: 1 branch
BranchTrueFalseTotal
if defined $list and not UNIVERSAL::isa($list, "ARRAY") 11 9 20
Condition66%2/3
defined $list and not UNIVERSAL::isa($list, "ARRAY")
!ll&&!rl&&r
0911
MC/DC50%1/2
defined $list and not UNIVERSAL::isa($list, "ARRAY")
defined $list not UNIVERSAL::isa($list, "ARRAY")
Truth table66%2/3
A and not(B)
A= defined $listB= not UNIVERSAL::isa($list, "ARRAY")
ABresult
0X0
100
111
2170 20 ▶ my $term = [ map {ref $_ && exists $_->{-term} && $_->{-term} } @$list ];
Condition33%2/6
ref $_ && exists $_->{'-term'} && $_->{'-term'}
!ll&&!rl&&r
0036
ref $_ and exists $_->{"-term"}
!ll&&!rl&&r
0036
MC/DC0%0/3
ref $_ && exists $_->{'-term'} && $_->{'-term'}
ref $_ exists $_->{"-term"} $_->{'-term'}
Truth table25%1/4
A and B && C
A= ref $_B= exists $_->{"-term"}C= $_->{'-term'}
ABCresult
0XX0
10X0
1100
1111
2171 # return wantarray ? @$term : shift @$term;
2172 20 ▶ return ( scalar @$term > 1 ) ? $term : shift @$term;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$term > 1 ? : 9 11 20
2173 }
2174 }
2175  
2176 # ----------------------------------------------------------------
2177 package XML::FeedPP::Element;
2178 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2179  
2180 491 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
2181 491 my $package = shift;
2182 491 my $self = {@_};
2183 491 bless $self, $package;
2184 491 $self;
2185 }
2186  
2187 299 ▶sub ref_bless {
Subroutine ref_bless: called CC=1 SCAR=0.0
2188 299 my $package = shift;
2189 299 my $self = shift;
2190 299 bless $self, $package;
2191 299 $self;
2192 }
2193  
2194 29 ▶sub set {
Subroutine set: called CC=16 SCAR=28.1
2195 29 my $self = shift;
2196  
2197 29 ▶ while ( scalar @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 127 29 156
2198 127 my $key = shift @_;
2199 127 my $val = shift @_;
2200 127 my $node = $self;
2201 127 ▶ while ( $key =~ s#^([^/]+)/##s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ s[^([^/]+)/][]s) 36 127 163
2202 36 my $child = $1;
2203 36 ▶ if ( ref $node->{$child} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $node->{$child}) { } 24 12 36
elsif (defined $node->{$child}) { } 0 12 12
2204 # ok
2205 }
2206 elsif ( defined $node->{$child} ) {
2207 0 $node->{$child} = { '#text' => $node->{$child} };
2208 }
2209 else {
2210 12 $node->{$child} = {};
2211 }
2212 36 $node = $node->{$child};
2213 }
2214 127 my ( $tagname, $attr ) = split( /\@/, $key, 2 );
2215 127 ▶ if ( $tagname eq "" && defined $attr ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tagname eq '' and defined $attr) { } 6 121 127
elsif (defined $attr) { } 59 62 121
elsif (defined $tagname) { } 62 0 62
Condition66%2/3
$tagname eq "" and defined $attr
!ll&&!rl&&r
12106
MC/DC50%1/2
$tagname eq "" and defined $attr
$tagname eq "" defined $attr
Truth table66%2/3
A and B
A= $tagname eq ""B= defined $attr
ABresult
0X0
100
111
2216 6 $node->{ '-' . $attr } = $val;
2217 }
2218 elsif ( defined $attr ) {
2219 59 ▶ if ( ref $node->{$tagname} &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node->{$tagname} and UNIVERSAL::isa($node->{$tagname}, "ARRAY")) 1 58 59
Condition100%3/3
ref $node->{$tagname} and UNIVERSAL::isa($node->{$tagname}, "ARRAY")
!ll&&!rl&&r
39191
MC/DC100%2/2
ref $node->{$tagname} and UNIVERSAL::isa($node->{$tagname}, "ARRAY")
ref $node->{$tagname} UNIVERSAL::isa($node->{$tagname}, "ARRAY")
Truth table100%3/3
A and B
A= ref $node->{$tagname}B= UNIVERSAL::isa($node->{$tagname}, "ARRAY")
ABresult
0X0
100
111
2220 UNIVERSAL::isa( $node->{$tagname}, 'ARRAY' )) {
2221 1 $node->{$tagname} = shift @{$node->{$tagname}};
2222 }
2223 59 my $hkey = '-' . $attr;
2224 59 ▶ if ( ref $node->{$tagname} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $node->{$tagname}) { } 19 40 59
elsif (defined $node->{$tagname}) { } 16 24 40
2225 19 $node->{$tagname}->{$hkey} = $val;
2226 }
2227 elsif ( defined $node->{$tagname} ) {
2228 $node->{$tagname} = {
2229 16 '#text' => $node->{$tagname},
2230 $hkey => $val,
2231 };
2232 }
2233 else {
2234 24 $node->{$tagname} = { $hkey => $val };
2235 }
2236 }
2237 elsif ( defined $tagname ) {
2238 62 ▶ if ( ref $node->{$tagname} &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node->{$tagname} and UNIVERSAL::isa($node->{$tagname}, "ARRAY")) 0 62 62
Condition66%2/3
ref $node->{$tagname} and UNIVERSAL::isa($node->{$tagname}, "ARRAY")
!ll&&!rl&&r
5570
MC/DC0%0/2
ref $node->{$tagname} and UNIVERSAL::isa($node->{$tagname}, "ARRAY")
ref $node->{$tagname} UNIVERSAL::isa($node->{$tagname}, "ARRAY")
Truth table66%2/3
A and B
A= ref $node->{$tagname}B= UNIVERSAL::isa($node->{$tagname}, "ARRAY")
ABresult
0X0
100
111
2239 UNIVERSAL::isa( $node->{$tagname}, 'ARRAY' )) {
2240 0 $node->{$tagname} = shift @{$node->{$tagname}};
2241 }
2242 62 ▶ if ( ref $node->{$tagname} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node->{$tagname}) { } 7 55 62
2243 7 $node->{$tagname}->{'#text'} = $val;
2244 }
2245 else {
2246 55 $node->{$tagname} = $val;
2247 }
2248 }
2249 }
2250 }
2251  
2252 228 ▶sub get {
Subroutine get: called CC=19 SCAR=29.6
2253 228 my $self = shift;
2254 228 my $key = shift;
2255 228 my $node = $self;
2256  
2257 228 ▶ while ( $key =~ s#^([^/]+)/##s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ s[^([^/]+)/][]s) 84 216 300
2258 84 my $child = $1;
2259 84 ▶ return unless ref $node;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node 0 84 84
2260 84 ▶ return unless exists $node->{$child};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $node->{$child} 12 72 84
2261 72 $node = $node->{$child};
2262 }
2263 216 my ( $tagname, $attr ) = split( /\@/, $key, 2 );
2264 216 ▶ return unless ref $node;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node 12 204 216
2265 # return unless exists $node->{$tagname};
2266 204 ▶ if ( $tagname eq "" && defined $attr ) { # @attribute
Branch: 2 branches
BranchTrueFalseTotal
if ($tagname eq '' and defined $attr) { } 7 197 204
elsif (defined $attr) { } 98 99 197
Condition66%2/3
$tagname eq "" and defined $attr
!ll&&!rl&&r
19707
MC/DC50%1/2
$tagname eq "" and defined $attr
$tagname eq "" defined $attr
Truth table66%2/3
A and B
A= $tagname eq ""B= defined $attr
ABresult
0X0
100
111
2267 7 ▶ return unless exists $node->{ '-' . $attr };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$node{'-' . $attr} 0 7 7
2268 7 return $node->{ '-' . $attr };
2269 }
2270 elsif ( defined $attr ) { # node@attribute
2271 98 ▶ return unless ref $node->{$tagname};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node->{$tagname} 18 80 98
2272 80 my $hkey = '-' . $attr;
2273 80 ▶ if ( UNIVERSAL::isa( $node->{$tagname}, 'ARRAY' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($node->{$tagname}, "ARRAY")) 8 72 80
2274 my $list = [
2275 28 ▶ map { ref $_ && exists $_->{$hkey} ? $_->{$hkey} : undef }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && exists $_->{$hkey} ? : 8 20 28
Condition100%3/3
ref $_ and exists $_->{$hkey}
!ll&&!rl&&r
1288
MC/DC100%2/2
ref $_ and exists $_->{$hkey}
ref $_ exists $_->{$hkey}
Truth table100%3/3
A and B
A= ref $_B= exists $_->{$hkey}
ABresult
0X0
100
111
2276 8 @{$node->{$tagname}} ];
2277 8 ▶ return @$list if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 4 4 8
2278 4 return ( grep { defined $_ } @$list )[0];
2279 }
2280 72 ▶ return unless exists $node->{$tagname}->{$hkey};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $node->{$tagname}{$hkey} 0 72 72
2281 72 return $node->{$tagname}->{$hkey};
2282 }
2283 else { # node
2284 99 ▶ return $node->{$tagname} unless ref $node->{$tagname};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node->{$tagname} 69 30 99
2285 30 ▶ if ( UNIVERSAL::isa( $node->{$tagname}, 'ARRAY' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($node->{$tagname}, "ARRAY")) 1 29 30
2286 my $list = [
2287 4 ▶ map { ref $_ ? $_->{'#text'} : $_ }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 2 2 4
2288 1 @{$node->{$tagname}} ];
2289 1 ▶ return @$list if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1 0 1
2290 0 return ( grep { defined $_ } @$list )[0];
2291 }
2292 29 return $node->{$tagname}->{'#text'};
2293 }
2294 }
2295  
2296 153 ▶sub get_set_array {
Subroutine get_set_array: called CC=5 SCAR=16.1
2297 153 my $self = shift;
2298 153 my $elem = shift;
2299 153 my $value = shift;
2300 153 ▶ if ( ref $value ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value) { } 21 132 153
elsif (defined $value) { } 29 103 132
2301 21 $self->{$elem} = $value;
2302 } elsif ( defined $value ) {
2303 29 ▶ $value = [ $value, @_ ] if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 29 29
2304 29 $self->{$elem} = $value;
2305 } else {
2306 103 my @ret = $self->get_value($elem);
2307 103 ▶ return scalar @ret > 1 ? \@ret : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
scalar @ret > 1 ? : 36 67 103
2308 }
2309 }
2310  
2311 785 ▶sub get_or_set {
Subroutine get_or_set: called CC=2 SCAR=6.9
2312 785 my $self = shift;
2313 785 my $elem = shift;
2314 return scalar @_
2315 785 ▶ ? $self->set_value( $elem, @_ )
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ ? : 236 549 785
2316 : $self->get_value($elem);
2317 }
2318  
2319 2059 ▶sub get_value {
Subroutine get_value: called CC=6 SCAR=17.9
2320 2059 my $self = shift;
2321 2059 my $elem = shift;
2322 2059 ▶ unless(exists $self->{$elem}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{$elem}) 964 1095 2059
2323 #XXX TreePP does not understand prefixes, which is usually not a
2324 # problem because most clients break on them... "best practices"
2325 # for feeds often explicitly state to use "the default" namespace.
2326 # Let's try to ignore the namespace here.
2327 964 ($elem) = grep /\:\Q$elem\E$/, keys %$self;
2328 964 ▶ defined $elem or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $elem or return 1 963 964
2329 }
2330  
2331 1096 my $value = $self->{$elem};
2332 1096 ▶ return $value unless ref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value 906 190 1096
2333  
2334 # multiple elements
2335 190 ▶ if ( UNIVERSAL::isa( $value, 'ARRAY' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($value, "ARRAY")) 42 148 190
2336 42 ▶ if ( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 39 3 42
2337 39 return map { $self->_fetch_value($_) } @$value;
2338 } else {
2339 3 return $self->_fetch_value($value->[0]);
2340 }
2341 }
2342  
2343 148 return $self->_fetch_value($value);
2344 }
2345  
2346 395 ▶sub _fetch_value {
Subroutine _fetch_value: called CC=4 SCAR=13.9
2347 395 my $self = shift;
2348 395 my $value = shift;
2349  
2350 395 ▶ if ( UNIVERSAL::isa( $value, 'HASH' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($value, "HASH")) 143 252 395
2351 # text node of an element with attributes
2352 return defined $value->{'#text'}
2353 143 ▶ ? $self->_fetch_value($value->{'#text'})
Branch: 1 branch
BranchTrueFalseTotal
defined $value->{'#text'} ? : 143 0 143
2354 : '';
2355 }
2356  
2357 252 ▶ if ( UNIVERSAL::isa( $value, 'SCALAR' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($value, "SCALAR")) 27 225 252
2358 # CDATA section as a scalar reference
2359 27 return $$value;
2360 }
2361  
2362 225 return $value;
2363 }
2364  
2365 839 ▶sub set_value {
Subroutine set_value: called CC=3 SCAR=11.0
2366 839 my $self = shift;
2367 839 my $elem = shift;
2368 839 my $text = shift;
2369 839 my $attr = \@_;
2370 839 ▶ if ( UNIVERSAL::isa( $self->{$elem}, 'HASH' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($self->{$elem}, 'HASH')) { } 15 824 839
2371 15 $self->{$elem}->{'#text'} = $text;
2372 }
2373 else {
2374 824 $self->{$elem} = $text;
2375 }
2376 839 ▶ $self->set_attr( $elem, @$attr ) if scalar @$attr;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$attr 160 679 839
2377 839 undef;
2378 }
2379  
2380 0 ▶sub get_attr {
Subroutine get_attr: not called CC=4 SCAR=30.0
2381 0 my $self = shift;
2382 0 my $elem = shift;
2383 0 my $key = shift;
2384 0 ▶ return unless exists $self->{$elem};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$elem} 0 0 0
2385 0 ▶ return unless ref $self->{$elem};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{$elem} 0 0 0
2386 0 ▶ return unless exists $self->{$elem}->{ '-' . $key };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$elem}{'-' . $key} 0 0 0
2387 0 $self->{$elem}->{ '-' . $key };
2388 }
2389  
2390 160 ▶sub set_attr {
Subroutine set_attr: called CC=6 SCAR=18.1
2391 160 my $self = shift;
2392 160 my $elem = shift;
2393 160 my $attr = \@_;
2394 160 ▶ if ( defined $self->{$elem} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{$elem}) { } 160 0 160
2395 160 my $scalar = ref $self->{$elem};
2396 160 ▶ $scalar = undef if ($scalar eq 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if $scalar eq "SCALAR" 5 155 160
2397 160 ▶ if (! $scalar) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($scalar) 145 15 160
2398 145 $self->{$elem} = { '#text' => $self->{$elem} };
2399 }
2400 }
2401 else {
2402 0 $self->{$elem} = {};
2403 }
2404 160 ▶ while ( scalar @$attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$attr) 175 160 335
2405 175 my $key = shift @$attr;
2406 175 my $val = shift @$attr;
2407 175 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 175 0 175
2408 # $val = $$val if (ref $val eq 'SCALAR');
2409 175 $self->{$elem}->{ '-' . $key } = $val;
2410 }
2411 else {
2412 0 delete $self->{$elem}->{ '-' . $key };
2413 }
2414 }
2415 160 undef;
2416 }
2417  
2418 # ----------------------------------------------------------------
2419 package XML::FeedPP::Util;
2420 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2421  
2422 44 my ( @DoW, @MoY, %MoY );
2423 44 @DoW = qw(Sun Mon Tue Wed Thu Fri Sat);
2424 44 @MoY = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
2425 44 @MoY{ map { uc($_) } @MoY } = ( 1 .. 12 );
2426 44 my $tz_now = time();
2427 44 my $tz_offset = Time::Local::timegm( localtime($tz_now) ) -
2428 Time::Local::timegm( gmtime($tz_now) );
2429 44 my $tz_hour = int( $tz_offset / 3600 );
2430 44 my $tz_min = int( $tz_offset / 60 ) % 60;
2431 44 my $rfc1123_regexp = qr{
2432 ^(?:[A-Za-z]+,\s*)? (\d+)\s+ ([A-Za-z]+)\s+ (\d+)\s+
2433 (\d+):(\d+)(?::(\d+)(?:\.\d*)?)?\s*
2434 ([\+\-]\d+:?\d{2} | [ECMP][DS]T )?
2435 }xi;
2436 44 my $w3cdtf_regexp = qr{
2437 ^(\d+)-(\d+)-(\d+)
2438 (?:T(\d+):(\d+)(?::(\d+)(?:\.\d*)?\:?)?\s*
2439 ([\+\-]\d+:?\d{2})?|$)
2440 }x;
2441 44 my $tzmap = {qw(
2442 EDT -4 EST -5 CDT -5 CST -6
2443 MDT -6 MST -7 PDT -7 PST -8
2444 )};
2445  
2446 15 ▶sub epoch_to_w3cdtf {
Subroutine epoch_to_w3cdtf: called CC=3 SCAR=11.2
2447 15 my $epoch = shift;
2448 15 ▶ return unless defined $epoch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $epoch 0 15 15
2449 15 my ( $sec, $min, $hour, $day, $mon, $year ) = gmtime($epoch+$tz_offset);
2450 15 $year += 1900;
2451 15 $mon++;
2452 15 ▶ my $tz = $tz_offset ? sprintf( '%+03d:%02d', $tz_hour, $tz_min ) : 'Z';
Branch: 1 branch
BranchTrueFalseTotal
$tz_offset ? : 0 15 15
2453 15 sprintf( '%04d-%02d-%02dT%02d:%02d:%02d%s',
2454 $year, $mon, $day, $hour, $min, $sec, $tz );
2455 }
2456  
2457 12 ▶sub epoch_to_rfc1123 {
Subroutine epoch_to_rfc1123: called CC=3 SCAR=11.2
2458 12 my $epoch = shift;
2459 12 ▶ return unless defined $epoch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $epoch 0 12 12
2460 12 my ( $sec, $min, $hour, $mday, $mon, $year, $wday ) = gmtime($epoch+$tz_offset);
2461 12 $year += 1900;
2462 12 ▶ my $tz = $tz_offset ? sprintf( '%+03d%02d', $tz_hour, $tz_min ) : 'GMT';
Branch: 1 branch
BranchTrueFalseTotal
$tz_offset ? : 0 12 12
2463 12 sprintf( '%s, %02d %s %04d %02d:%02d:%02d %s',
2464 $DoW[$wday], $mday, $MoY[$mon], $year, $hour, $min, $sec, $tz );
2465 }
2466  
2467 101 ▶sub rfc1123_to_w3cdtf {
Subroutine rfc1123_to_w3cdtf: called CC=11 SCAR=25.6
2468 101 my $str = shift;
2469 101 ▶ return unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 101 101
2470 101 my ( $mday, $mon, $year, $hour, $min, $sec, $tz ) = ( $str =~ $rfc1123_regexp );
2471 101 ▶ return unless ( $year && $mon && $mday );
Branch: 1 branch
BranchTrueFalseTotal
unless $year and $mon and $mday 0 101 101
Condition33%2/6
$year and $mon and $mday
!ll&&!rl&&r
00101
$year and $mon
!ll&&!rl&&r
00101
MC/DC0%0/3
$year and $mon and $mday
$year $mon $mday
Truth table25%1/4
A and B and C
A= $yearB= $monC= $mday
ABCresult
0XX0
10X0
1100
1111
2472 101 ▶ $year += 2000 if $year < 77;
Branch: 1 branch
BranchTrueFalseTotal
if $year < 77 6 95 101
2473 101 ▶ $year += 1900 if $year < 100;
Branch: 1 branch
BranchTrueFalseTotal
if $year < 100 4 97 101
2474 101 ▶ $mon = $MoY{ uc($mon) } or return;
Branch: 1 branch
BranchTrueFalseTotal
$mon = $MoY{uc $mon} or return 101 0 101
2475 101 ▶ if ( defined $tz && $tz ne '' && $tz ne 'GMT' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz and $tz ne '' and $tz ne 'GMT') { } 64 37 101
Condition66%4/6
defined $tz and $tz ne "" and $tz ne "GMT"
!ll&&!rl&&r
37064
defined $tz and $tz ne ""
!ll&&!rl&&r
37064
MC/DC33%1/3
defined $tz and $tz ne "" and $tz ne "GMT"
defined $tz $tz ne "" $tz ne "GMT"
Truth table50%2/4
A and B and C
A= defined $tzB= $tz ne ""C= $tz ne "GMT"
ABCresult
0XX0
10X0
1100
1111
2476 64 my $off = &get_tz_offset($tz) / 60;
2477 64 $tz = sprintf( '%+03d:%02d', $off/60, $off%60 );
2478 }
2479 else {
2480 37 $tz = 'Z';
2481 }
2482 101 sprintf( '%04d-%02d-%02dT%02d:%02d:%02d%s',
2483 $year, $mon, $mday, $hour, $min, $sec, $tz );
2484 }
2485  
2486 51 ▶sub w3cdtf_to_rfc1123 {
Subroutine w3cdtf_to_rfc1123: called CC=12 SCAR=26.0
2487 51 my $str = shift;
2488 51 ▶ return unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 51 51
2489 51 my ( $year, $mon, $mday, $hour, $min, $sec, $tz ) = ( $str =~ $w3cdtf_regexp );
2490 51 ▶ return unless ( $year > 1900 && $mon && $mday );
Branch: 1 branch
BranchTrueFalseTotal
unless $year > 1900 and $mon and $mday 0 51 51
Condition33%2/6
$year > 1900 and $mon and $mday
!ll&&!rl&&r
0051
$year > 1900 and $mon
!ll&&!rl&&r
0051
MC/DC0%0/3
$year > 1900 and $mon and $mday
$year > 1900 $mon $mday
Truth table25%1/4
A and B and C
A= $year > 1900B= $monC= $mday
ABCresult
0XX0
10X0
1100
1111
2491 51 ▶ $hour ||= 0;
Condition100%2/2
$hour ||= 0
l!l
501
MC/DC100%1/1
$hour ||= 0
$hour
Truth table100%2/2
A
A= $hour
Aresult
11
00
2492 51 ▶ $min ||= 0;
Condition100%2/2
$min ||= 0
l!l
501
MC/DC100%1/1
$min ||= 0
$min
Truth table100%2/2
A
A= $min
Aresult
11
00
2493 51 ▶ $sec ||= 0;
Condition100%2/2
$sec ||= 0
l!l
483
MC/DC100%1/1
$sec ||= 0
$sec
Truth table100%2/2
A
A= $sec
Aresult
11
00
2494 51 ▶ my $epoch = eval { Time::Local::timegm( $sec, $min, $hour, $mday, $mon-1, $year ) }
Branch: 1 branch
BranchTrueFalseTotal
my $epoch = eval { do { Time::Local::timegm($sec, $min, $hour, $mday, $mon - 1, $year) } } or return 51 0 51
2495 or return;
2496  
2497 51 my $wday = ( gmtime($epoch) )[6];
2498 51 ▶ if ( defined $tz && $tz ne '' && $tz ne 'Z' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz and $tz ne '' and $tz ne 'Z') { } 35 16 51
Condition66%4/6
defined $tz and $tz ne "" and $tz ne "Z"
!ll&&!rl&&r
16035
defined $tz and $tz ne ""
!ll&&!rl&&r
16035
MC/DC33%1/3
defined $tz and $tz ne "" and $tz ne "Z"
defined $tz $tz ne "" $tz ne "Z"
Truth table50%2/4
A and B and C
A= defined $tzB= $tz ne ""C= $tz ne "Z"
ABCresult
0XX0
10X0
1100
1111
2499 35 my $off = &get_tz_offset($tz) / 60;
2500 35 $tz = sprintf( '%+03d%02d', $off/60, $off%60 );
2501 }
2502 else {
2503 16 $tz = 'GMT';
2504 }
2505 51 sprintf(
2506 '%s, %02d %s %04d %02d:%02d:%02d %s',
2507 $DoW[$wday], $mday, $MoY[ $mon - 1 ], $year, $hour, $min, $sec, $tz
2508 );
2509 }
2510  
2511 52 ▶sub rfc1123_to_epoch {
Subroutine rfc1123_to_epoch: called CC=9 SCAR=23.7
2512 52 my $str = shift;
2513 52 ▶ return unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 52 52
2514 52 my ( $mday, $mon, $year, $hour, $min, $sec, $tz ) = ( $str =~ $rfc1123_regexp );
2515 52 ▶ return unless ( $year && $mon && $mday );
Branch: 1 branch
BranchTrueFalseTotal
unless $year and $mon and $mday 0 52 52
Condition33%2/6
$year and $mon and $mday
!ll&&!rl&&r
0052
$year and $mon
!ll&&!rl&&r
0052
MC/DC0%0/3
$year and $mon and $mday
$year $mon $mday
Truth table25%1/4
A and B and C
A= $yearB= $monC= $mday
ABCresult
0XX0
10X0
1100
1111
2516 52 ▶ $year += 2000 if $year < 77;
Branch: 1 branch
BranchTrueFalseTotal
if $year < 77 6 46 52
2517 52 ▶ $year += 1900 if $year < 100;
Branch: 1 branch
BranchTrueFalseTotal
if $year < 100 4 48 52
2518 52 ▶ $mon = $MoY{ uc($mon) } or return;
Branch: 1 branch
BranchTrueFalseTotal
$mon = $MoY{uc $mon} or return 52 0 52
2519 52 ▶ my $epoch = eval { Time::Local::timegm( $sec, $min, $hour, $mday, $mon-1, $year ) }
Branch: 1 branch
BranchTrueFalseTotal
my $epoch = eval { do { Time::Local::timegm($sec, $min, $hour, $mday, $mon - 1, $year) } } or return 52 0 52
2520 or return;
2521 52 $epoch -= &get_tz_offset( $tz );
2522 52 $epoch;
2523 }
2524  
2525 73 ▶sub w3cdtf_to_epoch {
Subroutine w3cdtf_to_epoch: called CC=9 SCAR=25.1
2526 73 my $str = shift;
2527 73 ▶ return unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 73 73
2528 73 my ( $year, $mon, $mday, $hour, $min, $sec, $tz ) = ( $str =~ $w3cdtf_regexp );
2529 73 ▶ return unless ( $year > 1900 && $mon && $mday );
Branch: 1 branch
BranchTrueFalseTotal
unless $year > 1900 and $mon and $mday 0 73 73
Condition33%2/6
$year > 1900 and $mon and $mday
!ll&&!rl&&r
0073
$year > 1900 and $mon
!ll&&!rl&&r
0073
MC/DC0%0/3
$year > 1900 and $mon and $mday
$year > 1900 $mon $mday
Truth table25%1/4
A and B and C
A= $year > 1900B= $monC= $mday
ABCresult
0XX0
10X0
1100
1111
2530 73 ▶ $hour ||= 0;
Condition50%1/2
$hour ||= 0
l!l
730
MC/DC0%0/1
$hour ||= 0
$hour
Truth table50%1/2
A
A= $hour
Aresult
11
00
2531 73 ▶ $min ||= 0;
Condition50%1/2
$min ||= 0
l!l
730
MC/DC0%0/1
$min ||= 0
$min
Truth table50%1/2
A
A= $min
Aresult
11
00
2532 73 ▶ $sec ||= 0;
Condition50%1/2
$sec ||= 0
l!l
730
MC/DC0%0/1
$sec ||= 0
$sec
Truth table50%1/2
A
A= $sec
Aresult
11
00
2533 73 ▶ my $epoch = eval { Time::Local::timegm( $sec, $min, $hour, $mday, $mon-1, $year ) }
Branch: 1 branch
BranchTrueFalseTotal
my $epoch = eval { do { Time::Local::timegm($sec, $min, $hour, $mday, $mon - 1, $year) } } or return 73 0 73
2534 or return;
2535  
2536 73 $epoch -= &get_tz_offset( $tz );
2537 73 $epoch;
2538 }
2539  
2540 224 ▶sub get_tz_offset {
Subroutine get_tz_offset: called CC=5 SCAR=16.1
2541 224 my $tz = shift;
2542 224 ▶ return 0 unless defined $tz;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tz 58 166 224
2543 166 ▶ return $tzmap->{$tz}*60*60 if exists $tzmap->{$tz};
Branch: 1 branch
BranchTrueFalseTotal
if exists $tzmap->{$tz} 8 158 166
2544 158 ▶ return 0 unless( $tz =~ m/^([\+\-]?)(\d+):?(\d{2})$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $tz =~ /^([\+\-]?)(\d+):?(\d{2})$/ 0 158 158
2545 158 my( $pm, $ho, $mi ) = ( $1, $2, $3 );
2546 158 my $off = $ho * 60 + $mi;
2547 158 ▶ $off *= ( $pm eq "-" ) ? -60 : 60;
Branch: 1 branch
BranchTrueFalseTotal
$pm eq '-' ? : 74 84 158
2548 158 $off;
2549 }
2550  
2551 218 ▶sub get_w3cdtf {
Subroutine get_w3cdtf: called CC=5 SCAR=16.2
2552 218 my $date = shift;
2553 218 ▶ return unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 37 181 218
2554 181 ▶ if ( $date =~ /^\d+$/s ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($date =~ /^\d+$/s) { } 6 175 181
elsif ($date =~ /$rfc1123_regexp/) { } 81 94 175
elsif ($date =~ /$w3cdtf_regexp/) { } 94 0 94
2555 6 return &epoch_to_w3cdtf($date);
2556 }
2557 elsif ( $date =~ $rfc1123_regexp ) {
2558 81 return &rfc1123_to_w3cdtf($date);
2559 }
2560 elsif ( $date =~ $w3cdtf_regexp ) {
2561 94 return $date;
2562 }
2563 0 undef;
2564 }
2565  
2566 96 ▶sub get_rfc1123 {
Subroutine get_rfc1123: called CC=5 SCAR=16.5
2567 96 my $date = shift;
2568 96 ▶ return unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 0 96 96
2569 96 ▶ if ( $date =~ /^\d+$/s ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($date =~ /^\d+$/s) { } 3 93 96
elsif ($date =~ /$rfc1123_regexp/) { } 42 51 93
elsif ($date =~ /$w3cdtf_regexp/) { } 51 0 51
2570 3 return &epoch_to_rfc1123($date);
2571 }
2572 elsif ( $date =~ $rfc1123_regexp ) {
2573 42 return $date;
2574 }
2575 elsif ( $date =~ $w3cdtf_regexp ) {
2576 51 return &w3cdtf_to_rfc1123($date);
2577 }
2578 0 undef;
2579 }
2580  
2581 129 ▶sub get_epoch {
Subroutine get_epoch: called CC=5 SCAR=17.0
2582 129 my $date = shift;
2583 129 ▶ return unless defined $date;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 32 97 129
2584 97 ▶ if ( $date =~ /^\d+$/s ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($date =~ /^\d+$/s) { } 0 97 97
elsif ($date =~ /$rfc1123_regexp/) { } 33 64 97
elsif ($date =~ /$w3cdtf_regexp/) { } 64 0 64
2585 0 return $date;
2586 }
2587 elsif ( $date =~ $rfc1123_regexp ) {
2588 33 return &rfc1123_to_epoch($date);
2589 }
2590 elsif ( $date =~ $w3cdtf_regexp ) {
2591 64 return &w3cdtf_to_epoch($date);
2592 }
2593 0 undef;
2594 }
2595  
2596 3 ▶sub merge_hash {
Subroutine merge_hash: called CC=6 SCAR=18.8
2597 3 ▶ my $base = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $base = shift() or return 3 0 3
2598 3 ▶ my $merge = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $merge = shift() or return 3 0 3
2599  
2600 0 my %exclude = map { $_ => 1 } @_;
2601 3 foreach my $key ( keys %$merge ) {
2602 31 ▶ next if $exclude{$key} || exists $base->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $exclude{$key} or exists $base->{$key} 6 25 31
Condition66%2/3
$exclude{$key} or exists $base->{$key}
l!l&&r!l&&!r
0625
MC/DC50%1/2
$exclude{$key} or exists $base->{$key}
$exclude{$key} exists $base->{$key}
Truth table66%2/3
A or B
A= $exclude{$key}B= exists $base->{$key}
ABresult
1X1
011
000
2603 25 $base->{$key} = $merge->{$key};
2604 }
2605 }
2606  
2607 556 ▶sub param_even_odd {
Subroutine param_even_odd: called CC=2 SCAR=6.9
2608 556 ▶ if ( (scalar @_) % 2 == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar(@_) % 2 == 0) { } 216 340 556
2609 # even num of args - new( key1 => val1, key2 => arg2 );
2610 216 my $array = [ @_ ];
2611 216 return $array;
2612 }
2613 else {
2614 # odd num of args - new( first, key1 => val1, key2 => arg2 );
2615 340 return ( undef, @_ );
2616 }
2617 }
2618  
2619 # ----------------------------------------------------------------
2620 44 1;
2621 # ----------------------------------------------------------------
↑ Summary