| 1 | package WWW::Noss::FeedReader::Atom; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use 5.016; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | our $VERSION = '2.05'; | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use WWW::Noss::FeedReader::MediaRSS qw(parse_media_node); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use WWW::Noss::TextToHtml qw(text2html unescape_html strip_tags); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use WWW::Noss::Timestamp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | our $NS = 'http://www.w3.org/2005/Atom'; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 76 | ▶ | sub _name { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_name: called CC=10 SCAR=27.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 76 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 76 | my ($email_node, $name_node); | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 76 | for my $n ($node->childNodes) { | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 532 | my $node_name = $n->nodeName; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 532 | ▶ | if ($node_name eq 'name') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 76 | $name_node = $n; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | } elsif ($node_name eq 'email') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 76 | $email_node = $n; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 76 | ▶ | my $name = defined $name_node ? $name_node->textContent : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 76 | ▶ | my $email = defined $email_node ? $email_node->textContent : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 76 | ▶ | if ($name ne '' and $email ne '') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$name ne "" and $email ne ""
MC/DC0%0/2
$name ne "" and $email ne ""
$name ne ""
$email ne ""
Truth table33%1/3
A and B
A= $name ne ""B= $email ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 76 | return sprintf "%s (%s)", $email, $name; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | } elsif ($email ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return $email; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | } elsif ($name ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 74 | ▶ | sub _link { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_link: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 74 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 74 | my $href = $node->getAttribute('href'); | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 74 | ▶ | return undef unless defined $href; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 74 | ▶ | my $rel = $node->getAttribute('rel') // 'alternate'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node->getAttribute("rel") // "alternate"
MC/DC100%1/1
$node->getAttribute("rel") // "alternate"
$node->getAttribute("rel")
Truth table100%2/2
A
A= $node->getAttribute("rel")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 74 | ▶ | return $rel eq 'alternate' ? $href : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 139 | ▶ | sub _time { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_time: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 139 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 139 | return WWW::Noss::Timestamp->rfc3339($node->textContent); | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 74 | ▶ | sub _title { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_title: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 74 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 74 | my ($title, $display); | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 74 | $title = $node->textContent; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 74 | ▶ | my $type = $node->getAttribute('type') // 'text'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->getAttribute("type") // "text"
MC/DC0%0/1
$node->getAttribute("type") // "text"
$node->getAttribute("type")
Truth table50%1/2
A
A= $node->getAttribute("type")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 74 | ▶ | if ($type eq 'html') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $display = unescape_html(strip_tags($title)); | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 74 | $display = $title; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 74 | $display =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 74 | $display =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 74 | ▶ | return wantarray ? ($title, $display) : $display; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 49 | ▶ | sub _content { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_content: called CC=8 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 49 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 49 | ▶ | my $type = $node->getAttribute('type') // 'text'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node->getAttribute("type") // "text"
MC/DC100%1/1
$node->getAttribute("type") // "text"
$node->getAttribute("type")
Truth table100%2/2
A
A= $node->getAttribute("type")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 49 | my $src = $node->getAttribute('src'); | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 49 | ▶ | if ($type eq 'text') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 13 | return text2html($node->textContent); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } elsif ($type eq 'html') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 12 | return $node->textContent; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | } elsif ($type eq 'xhtml') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 12 | return join '', map { $_->toString } $node->childNodes; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | } elsif (defined $src) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | } elsif ($type =~ /[\+\/]xml$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 12 | return join '', map { $_->toString } $node->childNodes; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | } elsif ($type =~ /^text/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return text2html($node->textContent); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 12 | ▶ | sub _summary { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_summary: called CC=5 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 12 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 12 | ▶ | my $type = $node->getAttribute('type') // 'text'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->getAttribute("type") // "text"
MC/DC0%0/1
$node->getAttribute("type") // "text"
$node->getAttribute("type")
Truth table50%1/2
A
A= $node->getAttribute("type")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 12 | ▶ | if ($type eq 'html') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | return $node->textContent; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | } elsif ($type eq 'xhtml') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return join '', map { $_->toString } $node->childNodes; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | } elsif ($type eq 'text') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 12 | return text2html($node->textContent); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 63 | ▶ | sub _read_entry { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_entry: called CC=19 SCAR=29.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 63 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 63 | my $entry = { | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | nossid => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | status => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | feed => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | title => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | link => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | author => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | category => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | summary => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | published => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | updated => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | uid => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 63 | my $summary; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 63 | for my $n ($node->childNodes) { | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1363 | my $name = $n->nodeName; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1363 | ▶ | if ($name =~ /^media:/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | my $c = parse_media_node($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 5 | for my $k (keys %$c) { | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 14 | ▶ | if (ref $c->{ $k } eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | push @{ $entry->{ $k } }, @{ $c->{ $k } }; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 12 | ▶ | $entry->{ $k } //= $c->{ $k }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$entry->{$k} //= $c->{$k}
MC/DC0%0/2
$entry->{$k} //= $c->{$k}
$entry->{$k}
$c->{$k}
Truth table66%2/3
A //= B
A= $entry->{$k}B= $c->{$k}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } elsif ($name eq 'id') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 63 | $entry->{ uid } = $n->textContent; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } elsif ($name eq 'title') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 61 | @{ $entry }{ qw(title displaytitle) } = _title($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | } elsif ($name eq 'updated') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 63 | $entry->{ updated } = _time($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | } elsif ($name eq 'author') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 63 | $entry->{ author } = _name($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | } elsif ($name eq 'content') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 49 | $entry->{ summary } = _content($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | } elsif ($name eq 'link') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 61 | $entry->{ link } = _link($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } elsif ($name eq 'summary') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 12 | $summary = _summary($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | } elsif ($name eq 'category') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 210 | my $term = $n->getAttribute('term'); | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 210 | ▶ | next unless defined $term; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 210 | push @{ $entry->{ category } }, $term; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | } elsif ($name eq 'published') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 63 | $entry->{ published } = _time($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 63 | ▶ | if (not defined $entry->{ summary } and defined $summary) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $entry->{"summary"} and defined $summary
MC/DC50%1/2
not defined $entry->{"summary"} and defined $summary
not defined $entry->{"summary"}
defined $summary
Truth table66%2/3
not(A) and B
A= not defined $entry->{"summary"}B= defined $summary
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 12 | $entry->{ summary } = $summary; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 63 | ▶ | $entry->{ title } //= $entry->{ link }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$entry->{"title"} //= $entry->{"link"}
MC/DC0%0/2
$entry->{"title"} //= $entry->{"link"}
$entry->{"title"}
$entry->{"link"}
Truth table33%1/3
A //= B
A= $entry->{"title"}B= $entry->{"link"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 63 | return $entry; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 13 | ▶ | sub read_feed { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_feed: called CC=26 SCAR=36.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 13 | my ($class, $feed, $dom) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 13 | my $channel = { | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | nossname => $feed->name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | nosslink => $feed->feed, | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | title => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | link => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | description => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | updated => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | author => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | category => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | generator => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | image => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | rights => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | skiphours => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | skipdays => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 13 | my $entries = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 13 | my @entry_nodes; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 13 | for my $n ($dom->documentElement->childNodes) { | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 425 | my $name = $n->nodeName; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 425 | ▶ | if ($name eq 'entry') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 63 | push @entry_nodes, $n; | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | } elsif ($name eq 'title') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 13 | $channel->{ title } = _title($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | } elsif ($name eq 'link') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 13 | $channel->{ link } = _link($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | } elsif ($name eq 'updated') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 13 | $channel->{ updated } = _time($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | } elsif ($name eq 'author') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 13 | $channel->{ author } = _name($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | } elsif ($name eq 'category') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 39 | my $term = $n->getAttribute('term'); | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | 39 | ▶ | next unless defined $term; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 39 | push @{ $channel->{ category } }, $term; | |||||||||||||||||||||||||||||||||||||||||||||
| 237 | } elsif ($name eq 'generator') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 13 | $channel->{ generator } = $n->textContent; | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | } elsif ($name eq 'logo') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 13 | $channel->{ image } = $n->textContent; | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | } elsif ($name eq 'rights') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 13 | $channel->{ rights } = $n->textContent; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | } elsif ($name eq 'subtitle') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 13 | $channel->{ description } = $n->textContent; | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 13 | ▶ | if (not defined $channel->{ title }) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | die sprintf "%s is not a valid Atom feed\n", $feed->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 13 | for my $n (@entry_nodes) { | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | 63 | my $e = _read_entry($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | 63 | ▶ | next unless defined $e; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 63 | $e->{ feed } = $channel->{ nossname }; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 63 | push @$entries, $e; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 13 | ▶ | unless (@$entries) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | die sprintf "%s contains no posts\n", $feed->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | @$entries = | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 63 | map { $_->[1] } | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | sort { | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 99 | ▶ | my $at = $a->[1]{ published } // $a->[1]{ updated }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$WWW::Noss::FeedReader::Atom::a->[1]{"published"} // $WWW::Noss::FeedReader::Atom::a->[1]{"updated"}
MC/DC0%0/2
$WWW::Noss::FeedReader::Atom::a->[1]{"published"} // $WWW::Noss::FeedReader::Atom::a->[1]{"updated"}
$WWW::Noss::FeedReader::Atom::a->[1]{"published"}
$WWW::Noss::FeedReader::Atom::a->[1]{"updated"}
Truth table33%1/3
A // B
A= $WWW::Noss::FeedReader::Atom::a->[1]{"published"}B= $WWW::Noss::FeedReader::Atom::a->[1]{"updated"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 99 | ▶ | my $bt = $b->[1]{ published } // $b->[1]{ updated }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$WWW::Noss::FeedReader::Atom::b->[1]{"published"} // $WWW::Noss::FeedReader::Atom::b->[1]{"updated"}
MC/DC0%0/2
$WWW::Noss::FeedReader::Atom::b->[1]{"published"} // $WWW::Noss::FeedReader::Atom::b->[1]{"updated"}
$WWW::Noss::FeedReader::Atom::b->[1]{"published"}
$WWW::Noss::FeedReader::Atom::b->[1]{"updated"}
Truth table33%1/3
A // B
A= $WWW::Noss::FeedReader::Atom::b->[1]{"published"}B= $WWW::Noss::FeedReader::Atom::b->[1]{"updated"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 99 | ▶ | if (not defined $at and not defined $bt) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
defined $at || defined $bt
MC/DC0%0/2
defined $at || defined $bt
defined $at
defined $bt
Truth table33%1/3
A || B
A= defined $atB= defined $bt
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $a->[0] <=> $b->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | } elsif (not defined $at) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | } elsif (not defined $bt) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 99 | $at <=> $bt; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 13 | map { [ $_, $entries->[$_]] } | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 .. $#$entries; | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | $channel->{ updated } //= | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | $entries->[$#$entries]{ updated } // | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 13 | ▶ | $entries->[$#$entries]{ published }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition16%1/6
$channel->{"updated"} //= $$entries[$entries->$#*]{"updated"} // $$entries[$entries->$#*]{"published"}
$$entries[$entries->$#*]{"updated"} // $$entries[$entries->$#*]{"published"}
MC/DC0%0/3
$channel->{"updated"} //= $$entries[$entries->$#*]{"updated"} // $$entries[$entries->$#*]{"published"}
$channel->{"updated"}
$$entries[$entries->$#*]{"updated"}
$$entries[$entries->$#*]{"published"}
Truth table0%0/4
A //= B // C
A= $channel->{"updated"}B= $$entries[$entries->$#*]{"updated"}C= $$entries[$entries->$#*]{"published"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # So the feed doesn't have an updated field (which is technically required), | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # and none of its posts have an updated or published field either. The | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # feed is probably beyond saving. | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 13 | ▶ | if (not defined $channel->{ updated }) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | die sprintf "%s is not a valid Atom feed\n", $feed->name; | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 13 | return ($channel, $entries); | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # vim: expandtab shiftwidth=4 | ||||||||||||||||||||||||||||||||||||||||||||||