blib/lib/XML/Feed/Entry.pm

filter: Statementstmt 96.0% 48 / 50 Branchbran 90.0% 9 / 10 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 4 / 4 Subroutinesub 84.6% 11 / 13 Podpod 83.3% 5 / 6 totaltotal 93.4% 85 / 91 CC 11 SCAR 13.1
CC
11
Cov
96%
convert
8.0
new
4.0
init_empty
2.0
CRAP 3.7
« Build ↑ Summary blib/lib/XML/Feed/Format/Atom.pm »
1 package XML::Feed::Entry;
2 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 35 our $VERSION = '0.65';
7  
8 35 ▶use base qw( Class::ErrorHandler );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 35 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 35 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub wrap {
15 26 ▶ my $class = shift;
Subroutine wrap: called CC=1 SCAR=0.0
Pod documented
16 26 my($item) = @_;
17 26 bless { entry => $item }, $class;
18 }
19  
20 8 ▶sub unwrap { $_[0]->{entry} }
Subroutine unwrap: called CC=1 SCAR=0.0
Pod documented
21  
22 sub new {
23 10 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=13.9
Pod documented
24 10 my($format) = @_;
25 10 ▶ $format //= 'Atom';
Condition100%2/2
$format //= "Atom"
l!l
82
MC/DC100%1/1
$format //= "Atom"
$format
Truth table100%2/2
A
A= $format
Aresult
11
00
26 10 my $format_class = 'XML::Feed::Format::' . $format;
27 10 ▶ eval "use $format_class";
Subroutine BEGIN: called CC=1 SCAR=0.0
28 10 ▶ Carp::croak("Unsupported format $format: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 9 10
29 9 my $entry = bless {}, join('::', __PACKAGE__, "Format", $format);
30 9 ▶ $entry->init_empty or return $class->error($entry->errstr);
Branch: 1 branch
BranchTrueFalseTotal
$entry->init_empty or return $class->error($entry->errstr) 0 9 9
31 9 $entry;
32 }
33  
34 0 ▶sub init_empty { 1 }
Subroutine init_empty: not called CC=1 SCAR=6.9
Pod undocumented
35  
36 sub convert {
37 3 ▶ my $entry = shift;
Subroutine convert: called CC=8 SCAR=20.8
Pod documented
38 3 my($format) = @_;
39 3 my $new = __PACKAGE__->new($format);
40 3 for my $field (qw( title link content summary author id issued modified lat long )) {
41 30 my $val = $entry->$field();
42 30 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 9 21 30
43 21 ▶ next if blessed $val && $val->isa('XML::Feed::Content') && ! defined $val->body;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($val) and $val->isa("XML::Feed::Content") and not defined $val->body 1 20 21
Condition100%6/6
builtin::blessed($val) and $val->isa("XML::Feed::Content") and not defined $val->body
!ll&&!rl&&r
1551
builtin::blessed($val) and $val->isa("XML::Feed::Content")
!ll&&!rl&&r
1146
MC/DC100%3/3
builtin::blessed($val) and $val->isa("XML::Feed::Content") and not defined $val->body
builtin::blessed($val) $val->isa("XML::Feed::Content") not defined $val->body
Truth table100%4/4
A and B and not(C)
A= builtin::blessed($val)B= $val->isa("XML::Feed::Content")C= not defined $val->body
ABCresult
0XX0
10X0
1100
1111
44 20 $new->$field($val);
45 }
46 3 for my $field (qw( category )) {
47 3 my @val = $entry->$field();
48 3 ▶ next unless @val;
Branch: 1 branch
BranchTrueFalseTotal
unless @val 1 2 3
49 2 $new->$field(@val);
50 }
51 3 $new;
52 }
53  
54 sub title;
55 sub link;
56 sub content;
57 sub summary;
58 sub category;
59 sub author;
60 sub id;
61 sub issued;
62 sub modified;
63 sub lat;
64 sub long;
65 sub format;
66 0 ▶sub tags { shift->category(@_) }
Subroutine tags: not called CC=1 SCAR=6.9
Pod documented
67 sub enclosure;
68  
69 35 1;
70 __END__
71  
72 =head1 NAME
73  
74 XML::Feed::Entry - Entry/item in a syndication feed
75  
76 =head1 SYNOPSIS
77  
78 ## $feed is an XML::Feed object.
79 for my $entry ($feed->entries) {
80 print $entry->title, "\n", $entry->summary, "\n\n";
81 }
82  
83 =head1 DESCRIPTION
84  
85 I<XML::Feed::Entry> represents an entry/item in an L<XML::Feed> syndication
86 feed.
87  
88 =head1 USAGE
89  
90 =head2 XML::Feed::Entry->new($format)
91  
92 Creates a new I<XML::Feed::Entry> object in the format I<$format>, which
93 should be either I<RSS> or I<Atom>.
94  
95 =head2 $entry->convert($format)
96  
97 Converts the I<XML::Feed::Entry> object into the I<$format> format, and
98 returns the new object.
99  
100 =head2 $entry->title([ $title ])
101  
102 The title of the entry.
103  
104 =head2 $entry->base([ $base ])
105  
106 The url base of the entry.
107  
108 =head2 $entry->link([ $uri ])
109  
110 The permalink of the entry, in most cases, except in cases where it points
111 instead to an offsite URI referenced in the entry.
112  
113 =head2 $entry->content([ $content ])
114  
115 An L<XML::Feed::Content> object representing the full entry body, or as
116 much as is available in the feed.
117  
118 In RSS feeds, this method will look first for
119 L<http://purl.org/rss/1.0/modules/content/#encoded> and
120 L<http://www.w3.org/1999/xhtml#body> elements, then fall back to a
121 I<E<lt>descriptionE<gt>> element.
122  
123 =head2 $entry->summary([ $summary ])
124  
125 An L<XML::Feed::Content> object representing a short summary of the entry.
126 Possibly.
127  
128 Since RSS feeds do not have the idea of a summary separate from the entry
129 body, this may not always be what you want. If the entry contains both a
130 I<E<lt>descriptionE<gt>> element B<and> another element typically used for
131 the full content of the entry--either I<http://www.w3.org/1999/xhtml/body>
132 or L<http://purl.org/rss/1.0/modules/content/#encoded>--we treat that as
133 the summary. Otherwise, we assume that there isn't a summary, and return
134 an L<XML::Feed::Content> object with an empty string in the I<body>.
135  
136 =head2 $entry->category([ $category ])
137  
138 The category in which the entry was posted.
139  
140 Returns a list of categories if called in array context or the first
141 category if called in scalar context.
142  
143 B<WARNING> It's possible this API might change to have an
144 I<add_category> instead.
145  
146 =head2 $entry->tags([ $tag ])
147  
148 A synonym (alias) for I<category>;
149  
150 =head2 $entry->author([ $author ])
151  
152 The name or email address of the person who posted the entry.
153  
154 =head2 $entry->id([ $id ])
155  
156 The unique ID of the entry.
157  
158 =head2 $entry->issued([ $issued ])
159  
160 A I<DateTime> object representing the date and time at which the entry
161 was posted.
162  
163 If present, I<$issued> should be a I<DateTime> object.
164  
165 =head2 $entry->modified([ $modified ])
166  
167 A I<DateTime> object representing the last-modified date of the entry.
168  
169 If present, I<$modified> should be a I<DateTime> object.
170  
171 =head2 $entry->wrap
172  
173 Take an entry in its native format and turn it into an I<XML::Feed::Entry> object.
174  
175 =head2 $entry->unwrap
176  
177 Take an I<XML::Feed::Entry> object and turn it into its native format.
178  
179 =head1 AUTHOR & COPYRIGHT
180  
181 Please see the I<XML::Feed> manpage for author, copyright, and license
182 information.
183  
184 =cut
« Build ↑ Summary blib/lib/XML/Feed/Format/Atom.pm »