| 1 | # $Id$ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package XML::Atom::Feed; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use base qw( XML::Atom::Thing ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use XML::Atom; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use XML::Atom::Entry; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 19 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 19 | if (LIBXML) { | |||||||||||||||||||||||||||||||||||||||||
| 11 | 19 | *entries = \&entries_libxml; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 19 | *add_entry = \&add_entry_libxml; | |||||||||||||||||||||||||||||||||||||||||
| 13 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | *entries = \&entries_xpath; | ||||||||||||||||||||||||||||||||||||||||||
| 15 | *add_entry = \&add_entry_xpath; | ||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 20 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 20 | my $atom = shift; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 20 | ▶ | my %param = @_ == 1 ? (Stream => $_[0]) : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 20 | ▶ | if (UNIVERSAL::isa($param{Stream}, 'URI')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my @feeds = __PACKAGE__->find_feeds($param{Stream}); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return $atom->error("Can't find Atom file") unless @feeds; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $req = HTTP::Request->new(GET => $feeds[0]); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $res = $ua->request($req); | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ($res->is_success) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $param{Stream} = \$res->content; | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 20 | $atom->SUPER::init(%param); | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub find_feeds { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_feeds: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my($uri) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $req = HTTP::Request->new(GET => $uri); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $res = $ua->request($req); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return unless $res->is_success; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my @feeds; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($res->content_type eq 'text/html' || $res->content_type eq 'application/xhtml+xml') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$res->content_type eq "text/html" or $res->content_type eq "application/xhtml+xml"
MC/DC0%0/2
$res->content_type eq "text/html" or $res->content_type eq "application/xhtml+xml"
$res->content_type eq "text/html"
$res->content_type eq "application/xhtml+xml"
Truth table0%0/3
A or B
A= $res->content_type eq "text/html"B= $res->content_type eq "application/xhtml+xml"
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $base_uri = $uri; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $find_links = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my($tag, $attr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ($tag eq 'link') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return unless $attr->{rel}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my %rel = map { $_ => 1 } split /\s+/, lc($attr->{rel}); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | (my $type = lc $attr->{type}) =~ s/^\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $type =~ s/\s*$//; | |||||||||||||||||||||||||||||||||||||||||
| 52 | push @feeds, URI->new_abs($attr->{href}, $base_uri)->as_string | ||||||||||||||||||||||||||||||||||||||||||
| 53 | if $rel{alternate} && | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $type eq 'application/atom+xml'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rel{"alternate"} and $type eq "application/atom+xml"
MC/DC0%0/2
$rel{"alternate"} and $type eq "application/atom+xml"
$rel{"alternate"}
$type eq "application/atom+xml"
Truth table0%0/3
A and B
A= $rel{"alternate"}B= $type eq "application/atom+xml"
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } elsif ($tag eq 'base') { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $base_uri = $attr->{href}; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | require HTML::Parser; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $p = HTML::Parser->new(api_version => 3, | |||||||||||||||||||||||||||||||||||||||||
| 61 | start_h => [ $find_links, "tagname, attr" ]); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $p->parse($res->content); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | @feeds = ($uri); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | @feeds; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 8 | ▶ | sub element_name { 'feed' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
element_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 19 | *language = \⟨ # legacy | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 19 | ▶ | sub version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 19 | my $feed = shift; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 19 | my $elem = $feed->elem; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 19 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $elem->setAttribute('version', $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 19 | ▶ | $elem->getAttribute('version') || $feed->SUPER::version(@_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 7 | ▶ | sub entries_libxml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
entries_libxml: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | my $feed = shift; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 7 | ▶ | my @res = $feed->elem->getElementsByTagNameNS($feed->ns, 'entry') or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | my @entries; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | for my $res (@res) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 61 | my $entry = XML::Atom::Entry->new(Elem => $res->cloneNode(1)); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 61 | push @entries, $entry; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 7 | @entries; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub entries_xpath { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
entries_xpath: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $feed = shift; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $set = $feed->elem->find("descendant-or-self::*[local-name()='entry' and namespace-uri()='" . $feed->ns . "']"); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my @entries; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | for my $elem ($set->get_nodelist) { | |||||||||||||||||||||||||||||||||||||||||
| 98 | ## Delete the link to the parent (feed) element, and append | ||||||||||||||||||||||||||||||||||||||||||
| 99 | ## the default Atom namespace. | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $elem->del_parent_link; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $ns = XML::XPath::Node::Namespace->new('#default' => $feed->ns); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $elem->appendNamespace($ns); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $entry = XML::Atom::Entry->new(Elem => $elem); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | push @entries, $entry; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | @entries; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 5 | ▶ | sub add_entry_libxml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_entry_libxml: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 5 | my $feed = shift; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | my($entry, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 5 | ▶ | $opt ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt ||= {}
MC/DC100%1/1
$opt ||= {}
$opt
Truth table100%2/2
A
A= $opt
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | # When doing an insert, we try to insert before the first <entry> so | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # that we don't screw up any preamble. If there are no existing | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # <entry>'s, then fall back to appending, which should be | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # semantically identical. | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | my ($first_entry) = | |||||||||||||||||||||||||||||||||||||||||
| 118 | $feed->elem->getChildrenByTagNameNS($entry->ns, 'entry'); | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 5 | ▶ | if ($opt->{mode} && $opt->{mode} eq 'insert' && $first_entry) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$opt->{"mode"} and $opt->{"mode"} eq "insert" and $first_entry
$opt->{"mode"} and $opt->{"mode"} eq "insert"
MC/DC33%1/3
$opt->{"mode"} and $opt->{"mode"} eq "insert" and $first_entry
$opt->{"mode"}
$opt->{"mode"} eq "insert"
$first_entry
Truth table50%2/4
A and B and C
A= $opt->{"mode"}B= $opt->{"mode"} eq "insert"C= $first_entry
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | $feed->elem->insertBefore($entry->elem, $first_entry); | |||||||||||||||||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 4 | $feed->elem->appendChild($entry->elem); | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub add_entry_xpath { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_entry_xpath: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $feed = shift; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my($entry, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $opt ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt ||= {}
MC/DC0%0/1
$opt ||= {}
$opt
Truth table0%0/2
A
A= $opt
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $set = $feed->elem->find("*[local-name()='entry' and namespace-uri()='" . $entry->ns . "']"); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | my $first_entry = $set ? ($set->get_nodelist)[0] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($opt->{mode} && $opt->{mode} eq 'insert' && $first_entry) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$opt->{"mode"} and $opt->{"mode"} eq "insert" and $first_entry
$opt->{"mode"} and $opt->{"mode"} eq "insert"
MC/DC0%0/3
$opt->{"mode"} and $opt->{"mode"} eq "insert" and $first_entry
$opt->{"mode"}
$opt->{"mode"} eq "insert"
$first_entry
Truth table0%0/4
A and B and C
A= $opt->{"mode"}B= $opt->{"mode"} eq "insert"C= $first_entry
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $feed->elem->insertBefore($entry->elem, $first_entry); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $feed->elem->appendChild($entry->elem); | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 19 | __PACKAGE__->mk_elem_accessors(qw( generator )); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 19 | __PACKAGE__->mk_xml_attr_accessors(qw( lang base )); | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 19 | __PACKAGE__->_rename_elements('modified' => 'updated'); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 19 | __PACKAGE__->_rename_elements('tagline' => 'subtitle'); | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 19 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||||||||||||||||