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