| 1 | package XML::Feed; | ||||||||||||||||||||||||||||||||||||
| 2 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 3 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 35 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||
| 6 | 35 | ▶ | use base qw( Class::ErrorHandler ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | 35 | ▶ | use Feed::Find; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 35 | ▶ | use URI::Fetch; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 35 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 35 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 35 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 35 | use Module::Pluggable search_path => "XML::Feed::Format", | |||||||||||||||||||||||||||||||||||
| 13 | require => 1, | ||||||||||||||||||||||||||||||||||||
| 14 | 35 | ▶ | sub_name => 'formatters'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||
| 16 | 35 | our $VERSION = 'v1.0.0'; | |||||||||||||||||||||||||||||||||||
| 17 | 35 | our $MULTIPLE_ENCLOSURES = 0; | |||||||||||||||||||||||||||||||||||
| 18 | 35 | our @formatters; | |||||||||||||||||||||||||||||||||||
| 19 | BEGIN { | ||||||||||||||||||||||||||||||||||||
| 20 | 35 | ▶ | @formatters = __PACKAGE__->formatters; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||
| 23 | sub _parse_args { | ||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_args: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||
| 25 | 0 | my ($possible_args) = @_; | |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | 0 | my @valid_args = qw[useragent]; | |||||||||||||||||||||||||||||||||||
| 28 | 0 | my $args = {}; | |||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||
| 30 | 0 | for (@valid_args) { | |||||||||||||||||||||||||||||||||||
| 31 | $args->{$_} = delete $possible_args->{$_} | ||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if exists $possible_args->{$_}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | unless (keys %$args) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 36 | 0 | Carp::croak('No valid keys passed to ' . __PACKAGE__ . 'new()'); | |||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||
| 39 | # Validate useragent parameter if provided | ||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (exists $args->{useragent}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | unless (blessed($args->{useragent}) && $args->{useragent}->isa('LWP::UserAgent')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($args->{"useragent"}) and $args->{"useragent"}->isa("LWP::UserAgent")
MC/DC0%0/2
builtin::blessed($args->{"useragent"}) and $args->{"useragent"}->isa("LWP::UserAgent")
builtin::blessed($args->{"useragent"})
$args->{"useragent"}->isa("LWP::UserAgent")
Truth table0%0/3
A and B
A= builtin::blessed($args->{"useragent"})B= $args->{"useragent"}->isa("LWP::UserAgent")
| |||||||||||||||||||||||||||||||||||||
| 42 | 0 | Carp::croak("useragent must be an LWP::UserAgent object"); | |||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||
| 46 | 0 | return $args; | |||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | sub new { | ||||||||||||||||||||||||||||||||||||
| 50 | 14 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 51 | 14 | ▶ | my $format = shift // 'Atom'; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // "Atom"
MC/DC100%1/1
shift() // "Atom"
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | # Handle optional args hash | ||||||||||||||||||||||||||||||||||||
| 54 | 14 | my $args = {}; | |||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||
| 56 | 14 | ▶ | if (@_ && ref($_[-1]) eq 'HASH') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[-1] eq "HASH"
MC/DC0%0/2
@_ and ref $_[-1] eq "HASH"
@_
ref $_[-1] eq "HASH"
Truth table33%1/3
A and B
A= @_B= ref $_[-1] eq "HASH"
| |||||||||||||||||||||||||||||||||||||
| 57 | 0 | $args = $class->_parse_args(pop @_); | |||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | 14 | my $format_class = 'XML::Feed::Format::' . $format; | |||||||||||||||||||||||||||||||||||
| 61 | 14 | eval "use $format_class"; | |||||||||||||||||||||||||||||||||||
| 62 | 14 | ▶ | Carp::croak("Unsupported format $format: $@") if $@; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 63 | 13 | my $feed = bless $args, join('::', __PACKAGE__, "Format", $format); | |||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||
| 65 | 13 | ▶ | $feed->init_empty(@_) or return $class->error($feed->errstr); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 66 | 7 | $feed; | |||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub init_empty { 1 } | ||||||||||||||||||||||||||||||||||
|
Subroutine
init_empty: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||
| 71 | sub parse { | ||||||||||||||||||||||||||||||||||||
| 72 | 36 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=16 SCAR=29.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 73 | 36 | my($stream) = @_; | |||||||||||||||||||||||||||||||||||
| 74 | 36 | ▶ | return $class->error("Stream parameter is required") unless $stream; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||
| 76 | 36 | my ($specified_format, $args) = (undef, {}); | |||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | 36 | ▶ | if (@_ == 3) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 79 | 0 | ($specified_format, $args) = @_[1, 2]; | |||||||||||||||||||||||||||||||||||
| 80 | } elsif (@_ == 2) { | ||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if (ref($_[-1]) eq 'HASH') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 82 | 0 | $args = $_[1]; | |||||||||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||||||||||
| 84 | 0 | $specified_format = $_[1]; | |||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | 36 | ▶ | if (keys %$args) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 89 | 0 | $args = $class->_parse_args($args); | |||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||
| 92 | 36 | my $feed = bless $args, $class; | |||||||||||||||||||||||||||||||||||
| 93 | 36 | my $xml = ''; | |||||||||||||||||||||||||||||||||||
| 94 | 36 | ▶ | if (blessed($stream) and $stream->isa('URI')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
builtin::blessed($stream) and $stream->isa("URI")
MC/DC50%1/2
builtin::blessed($stream) and $stream->isa("URI")
builtin::blessed($stream)
$stream->isa("URI")
Truth table66%2/3
A and B
A= builtin::blessed($stream)B= $stream->isa("URI")
| |||||||||||||||||||||||||||||||||||||
| 95 | 1 | $xml = $feed->get_uri($stream); | |||||||||||||||||||||||||||||||||||
| 96 | } elsif (ref($stream) eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||
| 97 | 8 | $xml = $$stream; | |||||||||||||||||||||||||||||||||||
| 98 | } elsif (ref($stream)) { | ||||||||||||||||||||||||||||||||||||
| 99 | 1 | $xml = $feed->get_fh($stream); | |||||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||||||
| 101 | 26 | $xml = $feed->get_file($stream); | |||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||
| 103 | 36 | my $errstr = "Can't get feed XML content from $stream"; | |||||||||||||||||||||||||||||||||||
| 104 | 36 | ▶ | if ($class->errstr) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 105 | 0 | $errstr .= ": " . $class->errstr; | |||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||
| 107 | 36 | ▶ | return $class->error($errstr) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 108 | unless $xml; | ||||||||||||||||||||||||||||||||||||
| 109 | 36 | my $format; | |||||||||||||||||||||||||||||||||||
| 110 | 36 | ▶ | if ($specified_format) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 111 | 0 | $format = $specified_format; | |||||||||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||||||||
| 113 | 36 | ▶ | $format = $feed->identify_format(\$xml) or return $class->error($feed->errstr); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | 36 | my $format_class = join '::', __PACKAGE__, "Format", $format; | |||||||||||||||||||||||||||||||||||
| 117 | 36 | ▶ | eval "use $format_class"; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 118 | 36 | ▶ | return $class->error("Unsupported format $format: $@") if $@; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 119 | 36 | bless $feed, $format_class; | |||||||||||||||||||||||||||||||||||
| 120 | 36 | ▶ | $feed->init_string(\$xml) or return $class->error($feed->errstr); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 121 | 18 | $feed; | |||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||
| 124 | sub get_file { | ||||||||||||||||||||||||||||||||||||
| 125 | 26 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_file: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 126 | 26 | my ($filename) = @_; | |||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||
| 128 | 26 | ▶ | open my $fh, '<', $filename | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 129 | or return $class->error("Can't open $filename: $!"); | ||||||||||||||||||||||||||||||||||||
| 130 | 26 | my $xml = $class->get_fh($fh); | |||||||||||||||||||||||||||||||||||
| 131 | 26 | close $fh; | |||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||
| 133 | 26 | return $xml; | |||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||
| 136 | sub get_fh { | ||||||||||||||||||||||||||||||||||||
| 137 | 27 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_fh: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 138 | 27 | my ($fh) = @_; | |||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||
| 140 | 27 | my $xml; | |||||||||||||||||||||||||||||||||||
| 141 | 27 | ▶ | while (read $fh, my($chunk), 8192) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 142 | 28 | $xml .= $chunk; | |||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||
| 145 | 27 | return $xml; | |||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||
| 148 | sub get_uri { | ||||||||||||||||||||||||||||||||||||
| 149 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_uri: called CC=5 SCAR=17.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 150 | 1 | my ($stream) = @_; | |||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||
| 152 | # Get or create UserAgent | ||||||||||||||||||||||||||||||||||||
| 153 | 1 | my $ua; | |||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | if (blessed($class) && $class->{useragent}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($class) and $class->{"useragent"}
MC/DC0%0/2
builtin::blessed($class) and $class->{"useragent"}
builtin::blessed($class)
$class->{"useragent"}
Truth table33%1/3
A and B
A= builtin::blessed($class)B= $class->{"useragent"}
| |||||||||||||||||||||||||||||||||||||
| 155 | 0 | $ua = $class->{useragent}; | |||||||||||||||||||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||||||||||||||||||
| 157 | 1 | $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||
| 158 | 1 | $ua->agent(__PACKAGE__ . "/$VERSION"); | |||||||||||||||||||||||||||||||||||
| 159 | 1 | $ua->env_proxy; # force allowing of proxies | |||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||
| 162 | 1 | ▶ | my $res = URI::Fetch->fetch($stream, UserAgent => $ua) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 163 | or return $class->error(URI::Fetch->errstr); | ||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | return $class->error("This feed has been permanently removed") | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 165 | if $res->status == URI::Fetch::URI_GONE(); | ||||||||||||||||||||||||||||||||||||
| 166 | 1 | return $res->content; | |||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||
| 169 | sub identify_format { | ||||||||||||||||||||||||||||||||||||
| 170 | 36 | ▶ | my $feed = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
identify_format: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 171 | 36 | my($xml) = @_; | |||||||||||||||||||||||||||||||||||
| 172 | 36 | foreach my $class (@formatters) { | |||||||||||||||||||||||||||||||||||
| 173 | 54 | my ($name) = ($class =~ m!([^:]+)$!); | |||||||||||||||||||||||||||||||||||
| 174 | # TODO ugly | ||||||||||||||||||||||||||||||||||||
| 175 | 54 | my $tmp = $$xml; | |||||||||||||||||||||||||||||||||||
| 176 | 54 | ▶ | return $name if eval { $class->identify(\$tmp) }; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 177 | 18 | ▶ | return $feed->error($@) if $@; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||
| 179 | 0 | return $feed->error("Cannot detect feed type"); | |||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||
| 182 | sub _get_first_tag { | ||||||||||||||||||||||||||||||||||||
| 183 | 54 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_first_tag: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||
| 184 | 54 | my ($xml) = @_; | |||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||
| 187 | ## Auto-detect feed type based on first element. This is prone | ||||||||||||||||||||||||||||||||||||
| 188 | ## to breakage, but then again we don't want to parse the whole | ||||||||||||||||||||||||||||||||||||
| 189 | ## feed ourselves. | ||||||||||||||||||||||||||||||||||||
| 190 | 54 | my $tag; | |||||||||||||||||||||||||||||||||||
| 191 | 54 | ▶ | while ($$xml =~ /<(\S+)/sg) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 192 | 114 | (my $t = $1) =~ tr/a-zA-Z0-9:\-\?!//cd; | |||||||||||||||||||||||||||||||||||
| 193 | 114 | my $first = substr $t, 0, 1; | |||||||||||||||||||||||||||||||||||
| 194 | 114 | ▶ | $tag = $t, last unless $first eq '?' || $first eq '!'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$first eq "?" or $first eq "!"
MC/DC100%2/2
$first eq "?" or $first eq "!"
$first eq "?"
$first eq "!"
Truth table100%3/3
A or B
A= $first eq "?"B= $first eq "!"
| |||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||
| 196 | 54 | ▶ | die ("Cannot find first element") unless $tag; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 197 | 54 | $tag =~ s/^.*://; | |||||||||||||||||||||||||||||||||||
| 198 | 54 | return $tag; | |||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||
| 201 | sub find_feeds { | ||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
find_feeds: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 203 | 0 | my($uri) = @_; | |||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | my @feeds = Feed::Find->find($uri) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 205 | or return $class->error(Feed::Find->errstr); | ||||||||||||||||||||||||||||||||||||
| 206 | 0 | @feeds; | |||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||
| 209 | sub convert { | ||||||||||||||||||||||||||||||||||||
| 210 | 2 | ▶ | my $feed = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
convert: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 211 | 2 | my($format) = @_; | |||||||||||||||||||||||||||||||||||
| 212 | 2 | my $new = XML::Feed->new($format); | |||||||||||||||||||||||||||||||||||
| 213 | 2 | for my $field (qw( title link description language author copyright modified generator )) { | |||||||||||||||||||||||||||||||||||
| 214 | 16 | my $val = $feed->$field(); | |||||||||||||||||||||||||||||||||||
| 215 | 16 | ▶ | next unless defined $val; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 216 | 11 | $new->$field($val); | |||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||
| 218 | 2 | for my $entry ($feed->entries) { | |||||||||||||||||||||||||||||||||||
| 219 | 3 | $new->add_entry($entry->convert($format)); | |||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||
| 221 | 2 | $new; | |||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||
| 224 | sub splice { | ||||||||||||||||||||||||||||||||||||
| 225 | 2 | ▶ | my $feed = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
splice: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 226 | 2 | my($other) = @_; | |||||||||||||||||||||||||||||||||||
| 227 | 2 | my %ids = map { $_->id => 1 } $feed->entries; | |||||||||||||||||||||||||||||||||||
| 228 | 2 | for my $entry ($other->entries) { | |||||||||||||||||||||||||||||||||||
| 229 | 4 | ▶ | $feed->add_entry($entry) unless $ids{$entry->id}++; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||
| 233 | sub _convert_entry { | ||||||||||||||||||||||||||||||||||||
| 234 | 8 | ▶ | my $feed = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_convert_entry: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||
| 235 | 8 | my $entry = shift; | |||||||||||||||||||||||||||||||||||
| 236 | 8 | my $feed_format = ref($feed); $feed_format =~ s!^XML::Feed::Format::!!; | |||||||||||||||||||||||||||||||||||
| 237 | 8 | my $entry_format = ref($entry); $entry_format =~ s!^XML::Feed::Entry::Format::!!; | |||||||||||||||||||||||||||||||||||
| 238 | 8 | ▶ | return $entry if $entry_format eq $feed_format; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 239 | 0 | return $entry->convert($feed_format); | |||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||
| 242 | sub useragent { | ||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my $feed = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
useragent: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 245 | # Setter: validate the useragent | ||||||||||||||||||||||||||||||||||||
| 246 | 0 | my $ua = shift; | |||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | unless (blessed($ua) && $ua->isa('LWP::UserAgent')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($ua) and $ua->isa("LWP::UserAgent")
MC/DC0%0/2
builtin::blessed($ua) and $ua->isa("LWP::UserAgent")
builtin::blessed($ua)
$ua->isa("LWP::UserAgent")
Truth table0%0/3
A and B
A= builtin::blessed($ua)B= $ua->isa("LWP::UserAgent")
| |||||||||||||||||||||||||||||||||||||
| 248 | 0 | Carp::croak("useragent must be an LWP::UserAgent object"); | |||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||
| 250 | 0 | $feed->{useragent} = $ua; | |||||||||||||||||||||||||||||||||||
| 251 | 0 | return $ua; | |||||||||||||||||||||||||||||||||||
| 252 | } else { | ||||||||||||||||||||||||||||||||||||
| 253 | # Getter: return existing or create new one | ||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | unless ($feed->{useragent}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 255 | 0 | $feed->{useragent} = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||
| 256 | 0 | $feed->{useragent}->agent(__PACKAGE__ . "/$VERSION"); | |||||||||||||||||||||||||||||||||||
| 257 | 0 | $feed->{useragent}->env_proxy; | |||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||
| 259 | 0 | return $feed->{useragent}; | |||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||
| 263 | sub base; | ||||||||||||||||||||||||||||||||||||
| 264 | sub format; | ||||||||||||||||||||||||||||||||||||
| 265 | sub title; | ||||||||||||||||||||||||||||||||||||
| 266 | sub link; | ||||||||||||||||||||||||||||||||||||
| 267 | sub self_link; | ||||||||||||||||||||||||||||||||||||
| 268 | sub description; | ||||||||||||||||||||||||||||||||||||
| 269 | sub language; | ||||||||||||||||||||||||||||||||||||
| 270 | sub author; | ||||||||||||||||||||||||||||||||||||
| 271 | sub copyright; | ||||||||||||||||||||||||||||||||||||
| 272 | sub modified; | ||||||||||||||||||||||||||||||||||||
| 273 | sub generator; | ||||||||||||||||||||||||||||||||||||
| 274 | sub add_entry; | ||||||||||||||||||||||||||||||||||||
| 275 | sub entries; | ||||||||||||||||||||||||||||||||||||
| 276 | sub as_xml; | ||||||||||||||||||||||||||||||||||||
| 277 | sub id; | ||||||||||||||||||||||||||||||||||||
| 278 | sub image; | ||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||
| 280 | 4 | ▶ | sub tagline { shift->description(@_) } | ||||||||||||||||||||||||||||||||||
|
Subroutine
tagline: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | sub items { $_[0]->entries } | ||||||||||||||||||||||||||||||||||
|
Subroutine
items: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||
| 283 | # RFC 5005 | ||||||||||||||||||||||||||||||||||||
| 284 | sub first_link; | ||||||||||||||||||||||||||||||||||||
| 285 | sub last_link; | ||||||||||||||||||||||||||||||||||||
| 286 | sub previous_link; | ||||||||||||||||||||||||||||||||||||
| 287 | sub next_link; | ||||||||||||||||||||||||||||||||||||
| 288 | sub current_link; | ||||||||||||||||||||||||||||||||||||
| 289 | sub prev_archive_link; | ||||||||||||||||||||||||||||||||||||
| 290 | sub next_archive_link; | ||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||
| 292 | 35 | 1; | |||||||||||||||||||||||||||||||||||
| 293 | __END__ | ||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||
| 295 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||
| 297 | XML::Feed - Syndication feed parser and auto-discovery | ||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||
| 299 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||
| 301 | use XML::Feed; | ||||||||||||||||||||||||||||||||||||
| 302 | my $feed = XML::Feed->parse(URI->new('http://example.com/atom.xml')) | ||||||||||||||||||||||||||||||||||||
| 303 | or die XML::Feed->errstr; | ||||||||||||||||||||||||||||||||||||
| 304 | print $feed->title, "\n"; | ||||||||||||||||||||||||||||||||||||
| 305 | for my $entry ($feed->entries) { | ||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||
| 308 | ## Find all of the syndication feeds on a given page, using | ||||||||||||||||||||||||||||||||||||
| 309 | ## auto-discovery. | ||||||||||||||||||||||||||||||||||||
| 310 | my @feeds = XML::Feed->find_feeds('http://example.com/'); | ||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||
| 312 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||
| 314 | I<XML::Feed> is a syndication feed parser for both RSS and Atom feeds. It | ||||||||||||||||||||||||||||||||||||
| 315 | also implements feed auto-discovery for finding feeds, given a URI. | ||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||
| 317 | I<XML::Feed> supports the following syndication feed formats: | ||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||
| 319 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||
| 321 | =item * RSS 0.91 | ||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||
| 323 | =item * RSS 1.0 | ||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||
| 325 | =item * RSS 2.0 | ||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||
| 327 | =item * Atom | ||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||
| 329 | =back | ||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||
| 331 | The goal of I<XML::Feed> is to provide a unified API for parsing and using | ||||||||||||||||||||||||||||||||||||
| 332 | the various syndication formats. The different flavors of RSS and Atom | ||||||||||||||||||||||||||||||||||||
| 333 | handle data in different ways: date handling; summaries and content; | ||||||||||||||||||||||||||||||||||||
| 334 | escaping and quoting; etc. This module attempts to remove those differences | ||||||||||||||||||||||||||||||||||||
| 335 | by providing a wrapper around the formats and the classes implementing | ||||||||||||||||||||||||||||||||||||
| 336 | those formats (L<XML::RSS> and L<XML::Atom::Feed>). For example, dates are | ||||||||||||||||||||||||||||||||||||
| 337 | handled differently in each of the above formats. To provide a unified API for | ||||||||||||||||||||||||||||||||||||
| 338 | date handling, I<XML::Feed> converts all date formats transparently into | ||||||||||||||||||||||||||||||||||||
| 339 | L<DateTime> objects, which it then returns to the caller. | ||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||
| 341 | =head1 USAGE | ||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||
| 343 | =head2 XML::Feed->new($format) | ||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||
| 345 | =head2 XML::Feed->new($format, \%args) | ||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||
| 347 | Creates a new empty I<XML::Feed> object using the format I<$format>. | ||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||
| 349 | $feed = XML::Feed->new('Atom'); | ||||||||||||||||||||||||||||||||||||
| 350 | $feed = XML::Feed->new('RSS'); | ||||||||||||||||||||||||||||||||||||
| 351 | $feed = XML::Feed->new('RSS', version => '0.91'); | ||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||
| 353 | An optional hashref of arguments can be provided as the last parameter: | ||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||
| 355 | my $ua = LWP::UserAgent->new; | ||||||||||||||||||||||||||||||||||||
| 356 | $ua->timeout(30); | ||||||||||||||||||||||||||||||||||||
| 357 | $feed = XML::Feed->new('Atom', { useragent => $ua }); | ||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||
| 359 | Currently supported arguments: | ||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||
| 361 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||
| 363 | =item * useragent | ||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||
| 365 | An L<LWP::UserAgent> object (or subclass) to use for fetching feeds via URI. | ||||||||||||||||||||||||||||||||||||
| 366 | If not provided, a default UserAgent will be created when needed. | ||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||
| 368 | =back | ||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||
| 370 | =head2 XML::Feed->parse($stream) | ||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||
| 372 | =head2 XML::Feed->parse($stream, \%args) | ||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||
| 374 | =head2 XML::Feed->parse($stream, $format) | ||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||
| 376 | =head2 XML::Feed->parse($stream, $format, \%args) | ||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||
| 378 | Parses a syndication feed identified by I<$stream> and returns an | ||||||||||||||||||||||||||||||||||||
| 379 | I<XML::Feed> object. I<$stream> can be any | ||||||||||||||||||||||||||||||||||||
| 380 | one of the following: | ||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||
| 382 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||
| 384 | =item * Scalar reference | ||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||
| 386 | A reference to string containing the XML body of the feed. | ||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||
| 388 | =item * Filehandle | ||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||
| 390 | An open filehandle from which the feed XML will be read. | ||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||
| 392 | =item * File name | ||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||
| 394 | The name of a file containing the feed XML. | ||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||
| 396 | =item * URI object | ||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||
| 398 | A URI from which the feed XML will be retrieved. | ||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||
| 400 | =back | ||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||
| 402 | I<$format> allows you to override format guessing. | ||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||
| 404 | An optional hashref of arguments can be provided as the last parameter: | ||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||
| 406 | my $ua = LWP::UserAgent->new; | ||||||||||||||||||||||||||||||||||||
| 407 | $ua->timeout(30); | ||||||||||||||||||||||||||||||||||||
| 408 | $feed = XML::Feed->parse('https://example.com/feed', { useragent => $ua }); | ||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||
| 410 | Currently supported arguments: | ||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||
| 412 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||
| 414 | =item * useragent | ||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||
| 416 | An L<LWP::UserAgent> object (or subclass) to use for fetching feeds via URI. | ||||||||||||||||||||||||||||||||||||
| 417 | If not provided, a default UserAgent will be created when needed. | ||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||
| 419 | =back | ||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||
| 421 | =head2 XML::Feed->get_file($filename) | ||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||
| 423 | Gets a feed from a file. | ||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||
| 425 | =head3 CML::Feed->get_fh($fh) | ||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||
| 427 | Gets a feed from pre-opened filehandle. | ||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||
| 429 | =head2 XML::Feed->get_uri($uri) | ||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||
| 431 | Gets a feed from a URI. | ||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||
| 433 | =head2 XML::Feed->find_feeds($uri) | ||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||
| 435 | Given a URI I<$uri>, use auto-discovery to find all of the feeds linked | ||||||||||||||||||||||||||||||||||||
| 436 | from that page (using I<E<lt>linkE<gt>> tags). | ||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||
| 438 | Returns a list of feed URIs. | ||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||
| 440 | =head2 XML::Feed->identify_format(\$xml) | ||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||
| 442 | Given the xml of a feed return what format it is in, with C<Atom> or C<RSS> for | ||||||||||||||||||||||||||||||||||||
| 443 | all versions of RSS. Note that you pass in a scalar ref to the xml string. | ||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||
| 445 | =head2 $feed->convert($format) | ||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||
| 447 | Converts the I<XML::Feed> object into the I<$format> format, and returns | ||||||||||||||||||||||||||||||||||||
| 448 | the new object. | ||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||
| 450 | =head2 $feed->splice($other_feed) | ||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||
| 452 | Splices in all of the entries from the feed I<$other_feed> into I<$feed>, | ||||||||||||||||||||||||||||||||||||
| 453 | skipping posts that are already in I<$feed>. | ||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||
| 455 | =head2 $feed->format | ||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||
| 457 | Returns the format of the feed (C<Atom>, or some version of C<RSS>). | ||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||
| 459 | =head2 $feed->title([ $title ]) | ||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||
| 461 | The title of the feed/channel. | ||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||
| 463 | =head2 $feed->base([ $base ]) | ||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||
| 465 | The url base of the feed/channel. | ||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||
| 467 | =head2 $feed->link([ $uri ]) | ||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||
| 469 | The permalink of the feed/channel. | ||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||
| 471 | =head2 $feed->tagline([ $tagline ]) | ||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||
| 473 | The description or tagline of the feed/channel. | ||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||
| 475 | =head2 $feed->description([ $description ]) | ||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||
| 477 | Alias for I<$feed-E<gt>tagline>. | ||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||
| 479 | =head2 $feed->author([ $author ]) | ||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||
| 481 | The author of the feed/channel. | ||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||
| 483 | =head2 $feed->language([ $language ]) | ||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||
| 485 | The language of the feed. | ||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||
| 487 | =head2 $feed->copyright([ $copyright ]) | ||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||
| 489 | The copyright notice of the feed. | ||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||
| 491 | =head2 $feed->modified([ $modified ]) | ||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||
| 493 | A I<DateTime> object representing the last-modified date of the feed. | ||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||
| 495 | If present, I<$modified> should be a I<DateTime> object. | ||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||
| 497 | =head2 $feed->generator([ $generator ]) | ||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||
| 499 | The generator of the feed. | ||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||
| 501 | =head2 $feed->self_link ([ $uri ]) | ||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||
| 503 | The Atom Self-link of the feed: | ||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||
| 505 | L<http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html> | ||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||
| 507 | A string. | ||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||
| 509 | =head2 $feed->entries | ||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||
| 511 | A list of the entries/items in the feed. Returns an array containing | ||||||||||||||||||||||||||||||||||||
| 512 | L<XML::Feed::Entry> objects. | ||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||
| 514 | =head2 $feed->items | ||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||
| 516 | A synonym (alias) for C<$feed-E<gt>entries>. | ||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||
| 518 | =head2 $feed->add_entry($entry) | ||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||
| 520 | Adds an entry to the feed. I<$entry> should be an L<XML::Feed::Entry> | ||||||||||||||||||||||||||||||||||||
| 521 | object in the correct format for the feed. | ||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||
| 523 | =head2 $feed->as_xml | ||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||
| 525 | Returns an XML representation of the feed, in the format determined by | ||||||||||||||||||||||||||||||||||||
| 526 | the current format of the I<$feed> object. | ||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||
| 528 | =head2 $feed->useragent([ $ua ]) | ||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||
| 530 | Get or set the L<LWP::UserAgent> object used for fetching feeds. | ||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||
| 532 | If called without arguments, returns the current UserAgent object, | ||||||||||||||||||||||||||||||||||||
| 533 | creating a default one if it doesn't exist. | ||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||
| 535 | If called with an L<LWP::UserAgent> object (or subclass), sets it as | ||||||||||||||||||||||||||||||||||||
| 536 | the UserAgent for this feed. | ||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||
| 538 | my $ua = LWP::UserAgent->new; | ||||||||||||||||||||||||||||||||||||
| 539 | $ua->timeout(30); | ||||||||||||||||||||||||||||||||||||
| 540 | $feed->useragent($ua); | ||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||
| 542 | # Later, retrieve it | ||||||||||||||||||||||||||||||||||||
| 543 | my $current_ua = $feed->useragent; | ||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||
| 545 | =head2 $feed->first_link ([ $uri ]) | ||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||
| 547 | The Atom First-link for feed paging and archiving (RFC 5005). | ||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||
| 549 | L<http://tools.ietf.org/html/rfc5005> | ||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||
| 551 | =head2 $feed->last_link ([ $uri ]) | ||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||
| 553 | The Atom Last-link for feed paging and archiving. | ||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||
| 555 | =head2 $feed->next_link ([ $uri ]) | ||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||
| 557 | The Atom Next-link for feed paging and archiving. | ||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||
| 559 | =head2 $feed->previous_link ([ $uri ]) | ||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||
| 561 | The Atom Previous-link for feed paging and archiving. | ||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||
| 563 | =head2 $feed->current_link ([ $uri ]) | ||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||
| 565 | The Atom Current-link for feed paging and archiving. | ||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||
| 567 | =head2 $feed->next_archive_link ([ $uri ]) | ||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||
| 569 | The Atom Next-link for feed paging and archiving. | ||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||
| 571 | =head2 $feed->prev_archive_link ([ $uri ]) | ||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||
| 573 | The Atom Prev-Archive-link for feed paging and archiving. | ||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||
| 575 | =head1 PACKAGE VARIABLES | ||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||
| 577 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||
| 579 | =item C<$XML::Feed::Format::RSS::PREFERRED_PARSER> | ||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||
| 581 | If you want to use another RSS parser class than XML::RSS (default), you can | ||||||||||||||||||||||||||||||||||||
| 582 | change the class by setting C<$PREFERRED_PARSER> variable in the | ||||||||||||||||||||||||||||||||||||
| 583 | XML::Feed::Format::RSS package. | ||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||
| 585 | $XML::Feed::Format::RSS::PREFERRED_PARSER = "XML::RSS::LibXML"; | ||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||
| 587 | B<Note:> this will only work for parsing feeds, not creating feeds. | ||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||
| 589 | B<Note:> Only C<XML::RSS::LibXML> version 0.3004 is known to work at the moment. | ||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||
| 591 | =item C<$XML::Feed::MULTIPLE_ENCLOSURES> | ||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||
| 593 | Although the RSS specification states that there can be at most one enclosure per item | ||||||||||||||||||||||||||||||||||||
| 594 | some feeds break this rule. | ||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||
| 596 | If this variable is set then C<XML::Feed> captures all of them and makes them available as a list. | ||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||
| 598 | Otherwise it returns the last enclosure parsed. | ||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||
| 600 | B<Note:> C<XML::RSS> version 1.44 is needed for this to work. | ||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||
| 602 | =back | ||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||
| 604 | =cut | ||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||
| 606 | =head1 VALID FEEDS | ||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||
| 608 | For reference, this cgi script will create valid, albeit nonsensical feeds | ||||||||||||||||||||||||||||||||||||
| 609 | (according to C<http://feedvalidator.org> anyway) for Atom 1.0 and RSS 0.90, | ||||||||||||||||||||||||||||||||||||
| 610 | 0.91, 1.0 and 2.0. | ||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||
| 612 | #!perl -w | ||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||
| 614 | use strict; | ||||||||||||||||||||||||||||||||||||
| 615 | use CGI; | ||||||||||||||||||||||||||||||||||||
| 616 | use CGI::Carp qw(fatalsToBrowser); | ||||||||||||||||||||||||||||||||||||
| 617 | use DateTime; | ||||||||||||||||||||||||||||||||||||
| 618 | use XML::Feed; | ||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||
| 620 | my $cgi = CGI->new; | ||||||||||||||||||||||||||||||||||||
| 621 | my @args = ( $cgi->param('format') // "Atom" ); | ||||||||||||||||||||||||||||||||||||
| 622 | push @args, ( version => $cgi->param('version') ) if $cgi->param('version'); | ||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||
| 624 | my $feed = XML::Feed->new(@args); | ||||||||||||||||||||||||||||||||||||
| 625 | $feed->id("http://".time.rand()."/"); | ||||||||||||||||||||||||||||||||||||
| 626 | $feed->title('Test Feed'); | ||||||||||||||||||||||||||||||||||||
| 627 | $feed->link($cgi->url); | ||||||||||||||||||||||||||||||||||||
| 628 | $feed->self_link($cgi->url( -query => 1, -full => 1, -rewrite => 1) ); | ||||||||||||||||||||||||||||||||||||
| 629 | $feed->modified(DateTime->now); | ||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||
| 631 | my $entry = XML::Feed::Entry->new(); | ||||||||||||||||||||||||||||||||||||
| 632 | $entry->id("http://".time.rand()."/"); | ||||||||||||||||||||||||||||||||||||
| 633 | $entry->link("http://example.com"); | ||||||||||||||||||||||||||||||||||||
| 634 | $entry->title("Test entry"); | ||||||||||||||||||||||||||||||||||||
| 635 | $entry->summary("Test summary"); | ||||||||||||||||||||||||||||||||||||
| 636 | $entry->content("Foo"); | ||||||||||||||||||||||||||||||||||||
| 637 | $entry->modified(DateTime->now); | ||||||||||||||||||||||||||||||||||||
| 638 | $entry->author('test@example.com (Testy McTesterson)'); | ||||||||||||||||||||||||||||||||||||
| 639 | $feed->add_entry($entry); | ||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||
| 641 | my $mime = ("Atom" eq $feed->format) ? "application/atom+xml" : "application/rss+xml"; | ||||||||||||||||||||||||||||||||||||
| 642 | print $cgi->header($mime); | ||||||||||||||||||||||||||||||||||||
| 643 | print $feed->as_xml; | ||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||
| 646 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||
| 648 | I<XML::Feed> is free software; you may redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||
| 649 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||
| 651 | =head1 AUTHOR & COPYRIGHT | ||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||
| 653 | Except where otherwise noted, I<XML::Feed> is Copyright 2004-2008 | ||||||||||||||||||||||||||||||||||||
| 654 | Six Apart. All rights reserved. | ||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||
| 656 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||
| 658 | For support contact the XML::Feed mailing list - xml-feed@perlhacks.com. | ||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||
| 660 | =head1 SOURCE CODE | ||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||
| 662 | The latest version of I<XML::Feed> can be found at | ||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||
| 664 | http://github.com/davorg/XML-Feed | ||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||
| 666 | =cut | ||||||||||||||||||||||||||||||||||||