RSS2Leafnode.pm

filter: Statementstmt 7.6% 127 / 1666 Branchbran 0.0% 0 / 734 Conditioncond 0.0% 0 / 629 MC/DCmcdc 0.0% 0 / 316 Subroutinesub 17.5% 29 / 165 Podpod 3.2% 4 / 124 totaltotal 4.4% 160 / 3634 CC 633 SCAR 70.5
CC
633
Cov
4%
item_to_links
6972.0
fetch_rss_process_one_item
3195.2
item_image_uwh
2450.0
CRAP 1155.4
↑ Summary RSS2Leafnode/XML/Twig/Other.pm »
1 # Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2017 Kevin Ryde
2 #
3 # This file is part of RSS2Leafnode.
4 #
5 # RSS2Leafnode is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # RSS2Leafnode is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with RSS2Leafnode. If not, see <http://www.gnu.org/licenses/>.
17  
18  
19 # maybe:
20 # location links
21 # http://maps.google.com/maps?ll=-35.066667,148.1
22 # http://maps.google.com/maps?ll=-35.066667,148.1&spn=0.01,0.01&t=m
23 #
24 # <link rel="canonical" href="http://www.example.com/">
25 # when site has mutliple names for a page, relative or absolute
26  
27  
28  
29 package App::RSS2Leafnode;
30 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use Hash::Util::FieldHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶use List::Util 'min', 'max';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use List::MoreUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use POSIX (); # ENOENT, etc
Subroutine BEGIN: called CC=1 SCAR=0.0
39 2 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use Text::Trim 1.02; # version 1.02 for undef support
Subroutine BEGIN: called CC=1 SCAR=0.0
41 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 2 ▶use HTML::Entities::Interpolate;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 2 ▶use App::RSS2Leafnode::XML::Twig::Other;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 # version 1.17 for __p(), and version 1.16 for turn_utf_8_on()
47 2 ▶use Locale::TextDomain 1.17;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ▶use Locale::TextDomain ('App-RSS2Leafnode');
Subroutine BEGIN: called CC=1 SCAR=0.0
49 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
50 2 ▶ use Locale::Messages;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 2 Locale::Messages::bind_textdomain_codeset ('App-RSS2Leafnode','UTF-8');
52 2 Locale::Messages::bind_textdomain_filter ('App-RSS2Leafnode',
53 \&Locale::Messages::turn_utf_8_on);
54 }
55  
56 # uncomment this to run the ### lines
57 # use Smart::Comments;
58  
59 2 our $VERSION;
60 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
61 2 $VERSION = 79;
62 }
63  
64 ## no critic (ProhibitFixedStringMatches)
65  
66  
67 # Cribs:
68 #
69 # RSS
70 # http://my.netscape.com/publish/help/
71 # RSS 0.9 spec.
72 # http://my.netscape.com/publish/help/mnn20/quickstart.html
73 # RSS 0.91 spec.
74 # http://purl.org/rss/1.0/
75 # RSS 1.0 spec.
76 # http://www.rssboard.org/rss-specification
77 # http://www.rssboard.org/files/rss-2.0-sample.xml
78 # RSS 2.0 spec and sample.
79 #
80 # http://www.rssboard.org/rss-profile
81 # "Best practices."
82 #
83 # Dublin Core
84 # RFC 5013 -- summary
85 # http://dublincore.org/documents/dcmi-terms/ -- dc/terms
86 #
87 # Atom
88 # RFC 4287 -- Atom spec
89 # RFC 3339 -- ISO timestamps as used in Atom
90 # RFC 4685 -- "thr" threading extensions
91 # RFC 4946 -- <link rel="license">
92 # RFC 5005 -- <link rel="next"> etc paging and archiving
93 # http://diveintomark.org/archives/2004/05/28/howto-atom-id
94 # Making an <id>
95 # http://www.iana.org/assignments/link-relations/link-relations.xhtml
96 # <link rel="xxx"> assigned values
97 #
98 # RSS Modules:
99 # http://www.meatballwiki.org/wiki/ModWiki -- wiki
100 # http://web.resource.org/rss/1.0/modules/slash/
101 # http://code.google.com/apis/feedburner/feedburner_namespace_reference.html
102 # http://backend.userland.com/creativeCommonsRSSModule
103 #
104 # http://web.resource.org/rss/1.0/modules/content/
105 # http://www.rssboard.org/rss-profile#namespace-elements-content
106 # http://validator.w3.org/feed/docs/warning/NeedDescriptionBeforeContent.html
107 # <content:encoded> should precede <description>
108 #
109 # http://www.apple.com/itunes/podcasts/specs.html
110 # http://www.feedforall.com/itunes.htm
111 # http://www.w3.org/2003/01/geo/wgs84_pos -- <geo:lat> etc
112 # http://www.georss.org/
113 # http://www.georss.org/Encodings
114 # http://www.georss.org/atom
115 # http://www.georss.org/rdf_rss1
116 #
117 # http://activitystrea.ms/specs/atom/1.0/
118 # activity:
119 # http://prismstandard.org/namespaces/basic/2.0/
120 # http://www.prismstandard.org/specifications/2.0/PRISM_prism_namespace_2.0.pdf
121 # Prism
122 #
123 # URIs
124 # RFC 1738, RFC 2396, RFC 3986 -- URI formats (news/nntp in 1738)
125 # draft-ellermann-news-nntp-uri-11.txt -- news/nntp update
126 # RFC 2732 -- ipv6 "[]" hostnames
127 # RFC 2141 -- urn:
128 # RFC 4122 -- uuid format (as under urn:uuid:)
129 # RFC 4151 -- tag:
130 # RFC 1034, RFC 1123 -- domain names
131 # RFC 2606 -- reserved domain names ".invalid"
132 #
133 # XML
134 # http://www.w3.org/TR/xmlbase/ -- xml:base
135 # RFC 3023 text/xml etc media types
136 #
137 # Mail Messages
138 # RFC 850, RFC 1036
139 # -- News message format, inc headers and rnews format
140 # RFC 2822, RFC 5322, RFC 5536
141 # -- Email message format.
142 # RFC 2076, RFC 4021 -- headers summary.
143 # RFC 2557 -- MHTML Content-Location
144 # RFC 1864 -- Content-MD5 header
145 # RFC 2369 -- List-Post header and friends
146 # http://www.ietf.org/proceedings/98dec/I-D/draft-ietf-drums-mail-followup-to-00.txt
147 # Draft "Mail-Followup-To" header.
148 #
149 # RFC 1327 -- X.400 to RFC822 introducing Language header
150 # RFC 3282 -- Content-Language header
151 # RFC 1766, RFC 3066, RFC 4646 -- language tag form
152 #
153 #
154 # NNTP
155 # RFC 977 -- NNTP
156 # RFC 2616 -- HTTP/1.1 Accept-Encoding header
157 # RFC 2980 -- NNTP extensions
158 #
159 # RFC 4642 -- NNTP with SSL
160 #
161 # For XML in Perl there's several ways to do it!
162 # - XML::Parser looks likely for stream/event processing, but its builtin
163 # tree mode is very basic.
164 # - XML::Twig extends XML::Parser to a good tree, though the docs are
165 # slightly light on. It only does a subset of "XPath" but the
166 # functions/regexps are more perl-like for matching and there's various
167 # handy shortcuts for common operations.
168 # - XML::LibXML is the full blown libxml and is rather a lot to learn.
169 # Because it's mainly C it's not easy to find where or how you're going
170 # wrong when your code doesn't work. libxml also seems stricter about
171 # namespace matters than XML::Parser/XML::Twig.
172 # - XML::RSS uses XML::Parser to build its own style tree of RSS,
173 # including unifying differences among RSS/RDF 0.91, 1.0 and 2.0.
174 # Nested elements seem to need specific handling in its code, which can
175 # make it tricky for sub-element oddities. A fair amount of it is about
176 # writing RSS too.
177 # - XML::RSS::LibXML uses libxml for XML::RSS compatible reading and
178 # writing. It seems to do better on unrecognised sub-elements.
179 # - XML::Atom offers the basic Atom elements but doesn't seem to give
180 # access to extra stuff that might be in a feed.
181 # - XML::Feed tries to unify XML::RSS and XML::Atom but again doesn't seem
182 # to go much beyond the basics. It too is geared towards writing as
183 # well as reading.
184 # - XML::TreePP pure perl parser to a hash tree.
185 #
186 # The choice of XML::Twig is based on wanting both RSS and Atom, but
187 # XML::Feed not going far enough. Tree processing is easier than stream,
188 # and an RSS isn't meant to be huge. A tree may help if channel fields
189 # follow items or something equally unnatural, but will probably assume that
190 # doesn't happen and look at the twig partial-tree mode. Between the tree
191 # styles XML::LibXML is harder to get into than Twig.
192 #
193  
194 #------------------------------------------------------------------------------
195 # mostly generic
196  
197 # return $str with a newline at the end, if it doesn't already have one
198 0 ▶sub str_ensure_newline {
Subroutine str_ensure_newline: not called CC=2 SCAR=17.9
Pod undocumented
199 0 my ($str) = @_;
200 0 ▶ if ($str !~ /\n$/) { $str .= "\n" }
Branch: 1 branch
BranchTrueFalseTotal
unless ($str =~ /\n$/) 0 0 0
201 0 return $str;
202 }
203  
204 0 ▶sub md5_of_utf8 {
Subroutine md5_of_utf8: not called CC=1 SCAR=6.9
Pod undocumented
205 0 my ($str) = @_;
206 0 require Digest::MD5;
207 0 return Digest::MD5::md5_base64 (Encode::encode_utf8 ($str));
208 }
209  
210 0 ▶sub is_empty {
Subroutine is_empty: not called CC=2 SCAR=17.9
Pod undocumented
211 0 my ($str) = @_;
212 0 ▶ return (! defined $str || $str =~ /^\s*$/);
Condition0%0/3
!defined($str) || $str =~ /^\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($str) || $str =~ /^\s*$/
!defined($str) $str =~ /^\s*$/
Truth table0%0/3
not(A) || B
A= !defined($str)B= $str =~ /^\s*$/
ABresult
1X1
011
000
213 }
214 0 ▶sub is_non_empty {
Subroutine is_non_empty: not called CC=1 SCAR=6.9
Pod undocumented
215 0 my ($str) = @_;
216 0 return ! is_empty($str);
217 }
218 0 ▶sub non_empty {
Subroutine non_empty: not called CC=2 SCAR=17.9
Pod undocumented
219 0 my ($str) = @_;
220 0 ▶ return (is_non_empty($str) ? $str : ());
Branch: 1 branch
BranchTrueFalseTotal
is_non_empty($str) ? : 0 0 0
221 }
222  
223 0 ▶sub join_non_empty {
Subroutine join_non_empty: not called CC=1 SCAR=6.9
Pod undocumented
224 0 my $sep = shift;
225 0 return non_empty (join($sep, map {non_empty($_)} @_));
226 }
227  
228 0 ▶sub collapse_whitespace {
Subroutine collapse_whitespace: not called CC=3 SCAR=24.8
Pod undocumented
229 0 my ($str) = @_;
230 0 ▶ defined $str or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $str or return undef 0 0 0
231 0 ▶ $str =~ s/(\s+)/($1 eq ' ' ? $1 : ' ')/ge;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq ' ' ? : 0 0 0
232 0 return Text::Trim::trim($str);
233 }
234  
235 # return true if $str is entirely ascii chars 0 to 127
236 0 ▶sub is_ascii {
Subroutine is_ascii: not called CC=1 SCAR=6.9
Pod undocumented
237 0 my ($str) = @_;
238 0 return ($str !~ /[^[:ascii:]]/);
239 }
240  
241 # Return the number of lines in $str.
242 # If $str ends with a newline then that counts as the last line, so "xyz\n"
243 # is one line. If $str doesn't end with a newline then the final chars are
244 # a line, so "abc\ndef" is two lines.
245 0 ▶sub str_count_lines {
Subroutine str_count_lines: not called CC=2 SCAR=17.9
Pod undocumented
246 0 my ($str) = @_;
247 0 ▶ return scalar($str =~ tr/\n//) + (length($str) && substr($str,-1) ne "\n");
Condition0%0/3
length $str && substr($str, -1) ne "\n"
!ll&&!rl&&r
000
MC/DC0%0/2
length $str && substr($str, -1) ne "\n"
length $str substr($str, -1) ne "\n"
Truth table0%0/3
A && B
A= length $strB= substr($str, -1) ne "\n"
ABresult
0X0
100
111
248 }
249  
250 0 ▶sub File_Temp_DEBUG_saver {
Subroutine File_Temp_DEBUG_saver: not called CC=1 SCAR=6.9
Pod undocumented
251 0 my ($self, $newval) = @_;
252 0 require Scope::Guard;
253 0 require File::Temp;
254 0 my $oldval = $File::Temp::DEBUG;
255 0 ▶ my $ret = Scope::Guard->new (sub { $File::Temp::DEBUG = $oldval });
Subroutine __ANON__: not called CC=1 SCAR=6.9
256 0 $File::Temp::DEBUG = $newval;
257 0 return $ret;
258 }
259 0 ▶sub MIME_Tools_debugging {
Subroutine MIME_Tools_debugging: not called CC=1 SCAR=6.9
Pod undocumented
260 0 my ($self, $newval) = @_;
261 0 require Scope::Guard;
262 0 require MIME::Tools;
263 0 my $oldval = MIME::Tools->debugging;
264 0 ▶ my $ret = Scope::Guard->new (sub { MIME::Tools->debugging($oldval) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
265 0 MIME::Tools->debugging ($newval);
266 0 return $ret;
267 }
268  
269 0 ▶sub homedir {
Subroutine homedir: not called CC=2 SCAR=17.9
Pod undocumented
270 # my ($self) = @_;
271 0 require File::HomeDir;
272 # call each time just in case playing tricks with $ENV{HOME} in conf file
273 0 ▶ return File::HomeDir->my_home
Condition0%0/2
"File::HomeDir"->my_home // croak("File::HomeDir says you have no home directory")
l!l
00
MC/DC0%0/1
"File::HomeDir"->my_home // croak("File::HomeDir says you have no home directory")
"File::HomeDir"->my_home
Truth table0%0/2
A
A= "File::HomeDir"->my_home
Aresult
11
00
274 // croak 'File::HomeDir says you have no home directory';
275 }
276  
277 #------------------------------------------------------------------------------
278 # Number::Format for sizes in bytes
279  
280 2 ▶use constant::defer NUMBER_FORMAT => sub {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=6.9
281 0 require Number::Format;
282 0 Number::Format->VERSION(1.5); # for format_bytes() options params
283 0 return Number::Format->new
284 (-kilo_suffix => __p('number-format-kilobytes','K'),
285 -mega_suffix => __p('number-format-megabytes','M'),
286 -giga_suffix => __p('number-format-gigabytes','G'));
287 2 };
288  
289 0 ▶sub format_size_in_bytes {
Subroutine format_size_in_bytes: not called CC=2 SCAR=17.9
Pod undocumented
290 0 my ($self, $length) = @_;
291 0 ▶ if ($length >= 2000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length >= 2000) { } 0 0 0
292 0 return $self->NUMBER_FORMAT()->format_bytes ($length, precision => 1);
293 } else {
294 0 return __x('{size} bytes', size => $length);
295 }
296 }
297  
298 #------------------------------------------------------------------------------
299  
300 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
301 2 my $class = shift;
302 2 return bless {
303 # config variables
304 verbose => 0,
305 render => 0,
306 render_width => 60,
307 rss_get_links => 0,
308 rss_get_comments => 0,
309 rss_newest_only => 0,
310 get_icon => 0,
311 html_charset_from_content => 0,
312  
313 # secret extra
314 msgidextra => '',
315  
316 @_,
317 }, $class;
318 }
319  
320 0 ▶sub command_line {
Subroutine command_line: not called CC=3 SCAR=24.8
Pod documented
321 0 my ($self) = @_;
322  
323 0 my $done_version;
324 0 require Getopt::Long;
325 0 Getopt::Long::Configure ('no_ignore_case');
326 Getopt::Long::GetOptions
327 ('config=s' => \$self->{'config_filename'},
328 'verbose:1' => \$self->{'verbose'},
329 0 ▶ 'version' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
330 0 say __x("RSS2Leafnode version {version}", version => $VERSION);
331 0 $done_version = 1;
332 },
333 0 ▶ 'bareversion' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
334 0 say $VERSION;
335 0 $done_version = 1;
336 },
337 'msgid=s' => \$self->{'msgidextra'},
338 0 ▶ 'help|?' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
339 0 say __x("rss2leafnode [--options]");
340 0 say __x(" --config=filename configuration file (default ~/.rss2leafnode.conf)");
341 0 say __x(" --help print this help");
342 0 say __x(" --verbose describe what's done");
343 0 say __x(" --verbose=2 show technical details of what's done");
344 0 say __x(" --version print program version number");
345 0 exit 0;
346 0 ▶ }) or return 1;
Branch: 1 branch
BranchTrueFalseTotal
Getopt::Long::GetOptions("config=s", \$self->{"config_filename"}, "verbose:1", \$self->{"verbose"}, "version", sub { say &__x("RSS2Leafnode version {version}", "version", $VERSION); $done_version = 1; } , "bareversion", sub { say $VERSION; $done_version = 1; } , "msgid=s", \$self->{"msgidextra"}, "help|?", sub { say &__x("rss2leafnode [--options]"); say &__x(" --config=filename configuration file (default ~/.rss2leafnode.conf)"); say &__x(" --help print this help"); say &__x(" --verbose describe what's done"); say &__x(" --verbose=2 show technical details of what's done"); say &__x(" --version print program version number"); exit 0; } ) or return 1 0 0 0
347 0 ▶ if (! $done_version) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done_version) 0 0 0
348 0 $self->do_config_file;
349 0 $self->nntp_close;
350 }
351 0 return 0;
352 }
353  
354 0 ▶sub verbose {
Subroutine verbose: not called CC=2 SCAR=17.9
Pod undocumented
355 0 my $self = shift;
356 0 my $count = shift;
357 0 ▶ if ($self->{'verbose'} >= $count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} >= $count) 0 0 0
358 0 say @_;
359 }
360 }
361  
362 0 ▶sub config_filename {
Subroutine config_filename: not called CC=2 SCAR=17.9
Pod undocumented
363 0 my ($self) = @_;
364 0 ▶ return $self->{'config_filename'} // do {
Condition0%0/3
$self->{"config_filename"} // do { require File::Spec; "File::Spec"->catfile($self->homedir, ".rss2leafnode.conf") }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"config_filename"} // do { require File::Spec; "File::Spec"->catfile($self->homedir, ".rss2leafnode.conf") }
$self->{"config_filename"} do { require File::Spec; "File::Spec"->catfile($self->homedir, ".rss2leafnode.conf") }
Truth table0%0/3
A // B
A= $self->{"config_filename"}B= do { require File::Spec; "File::Spec"->catfile($self->homedir, ".rss2leafnode.conf") }
ABresult
1X1
011
000
365 0 require File::Spec;
366 0 File::Spec->catfile ($self->homedir, '.rss2leafnode.conf');
367 };
368 }
369 0 ▶sub status_filename {
Subroutine status_filename: not called CC=2 SCAR=17.9
Pod undocumented
370 0 my ($self) = @_;
371 0 ▶ return $self->{'status_filename'} // do {
Condition0%0/3
$self->{"status_filename"} // do { require File::Spec; "File::Spec"->catfile($self->homedir, ".rss2leafnode.status") }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"status_filename"} // do { require File::Spec; "File::Spec"->catfile($self->homedir, ".rss2leafnode.status") }
$self->{"status_filename"} do { require File::Spec; "File::Spec"->catfile($self->homedir, ".rss2leafnode.status") }
Truth table0%0/3
A // B
A= $self->{"status_filename"}B= do { require File::Spec; "File::Spec"->catfile($self->homedir, ".rss2leafnode.status") }
ABresult
1X1
011
000
372 0 require File::Spec;
373 0 File::Spec->catfile ($self->homedir, '.rss2leafnode.status');
374 };
375 }
376  
377 0 ▶sub do_config_file {
Subroutine do_config_file: not called CC=5 SCAR=34.0
Pod undocumented
378 0 my ($self) = @_;
379 0 my @guards;
380  
381 0 ▶ open STDERR, '>&STDOUT' or die "Oops, can't join STDERR to STDOUT";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&STDOUT" or die "Oops, can't join STDERR to STDOUT" 0 0 0
382  
383 # File::Temp::DEBUG for possible temp files used by HTML::FormatExternal
384 # these debugs turned on only for the duration of running the config file
385 # and the downloading etc in it
386 0 ▶ if ($self->{'verbose'} >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} >= 2) 0 0 0
387 0 push @guards, $self->File_Temp_DEBUG_saver(1);
388 0 push @guards, $self->MIME_Tools_debugging(1);
389 }
390  
391 0 my $config_filename = $self->config_filename;
392 0 $self->verbose (1, "config: ", $config_filename);
393  
394 0 require App::RSS2Leafnode::Conf;
395 0 local $App::RSS2Leafnode::Conf::r2l = $self;
396 0 ▶ if (! defined (do { package App::RSS2Leafnode::Conf;
Branch: 1 branch
BranchTrueFalseTotal
if (not defined do { package App::RSS2Leafnode::Conf; do $config_filename }) 0 0 0
397 0 do $config_filename;
398 })) {
399 0 ▶ if (! -e $config_filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $config_filename) { } 0 0 0
400 0 croak "rss2leafnode: config file $config_filename doesn't exist\n";
401 } else {
402 0 croak $@;
403 }
404 }
405 }
406  
407 #------------------------------------------------------------------------------
408 # LWP stuff
409  
410 0 ▶sub user_agent {
Subroutine user_agent: not called CC=2 SCAR=17.9
Pod undocumented
411 0 my ($self) = @_;
412 0 ▶ if (defined $self->{'user_agent'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'user_agent'}) { } 0 0 0
413 0 return $self->{'user_agent'};
414 } else {
415 0 return 'RSS2leafnode/' . $self->VERSION . ' ';
416 }
417 }
418  
419 0 ▶sub ua {
Subroutine ua: not called CC=2 SCAR=17.9
Pod undocumented
420 0 my ($self) = @_;
421 0 ▶ return ($self->{'ua'} ||= do {
Condition0%0/3
$self->{"ua"} ||= do { require LWP::UserAgent; "LWP::UserAgent"->VERSION("5.832"); my $ua = "LWP::UserAgent"->new("keep_alive", 1); builtin::weaken($ua->{"App::RSS2Leafnode"} = $self); $ua->agent($self->user_agent); builtin::weaken(my $weak_self = $self); $ua->add_handler("request_send", \&App::RSS2Leafnode::lwp_request_send__verbose); $ua->add_handler("response_done", sub { lwp_response_done__check_md5($weak_self, @_); } ); require HTTP::Message; my $decodable = HTTP::Message::decodable(); $self->verbose(2, "HTTP decodable: ", $decodable); $ua->default_header("Accept-Encoding", $decodable); $ua }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ua"} ||= do { require LWP::UserAgent; "LWP::UserAgent"->VERSION("5.832"); my $ua = "LWP::UserAgent"->new("keep_alive", 1); builtin::weaken($ua->{"App::RSS2Leafnode"} = $self); $ua->agent($self->user_agent); builtin::weaken(my $weak_self = $self); $ua->add_handler("request_send", \&App::RSS2Leafnode::lwp_request_send__verbose); $ua->add_handler("response_done", sub { lwp_response_done__check_md5($weak_self, @_); } ); require HTTP::Message; my $decodable = HTTP::Message::decodable(); $self->verbose(2, "HTTP decodable: ", $decodable); $ua->default_header("Accept-Encoding", $decodable); $ua }
$self->{"ua"} do { require LWP::UserAgent; "LWP::UserAgent"->VERSION("5.832"); my $ua = "LWP::UserAgent"->new("keep_alive", 1); builtin::weaken($ua->{"App::RSS2Leafnode"} = $self); $ua->agent($self->user_agent); builtin::weaken(my $weak_self = $self); $ua->add_handler("request_send", \&App::RSS2Leafnode::lwp_request_send__verbose); $ua->add_handler("response_done", sub { lwp_response_done__check_md5($weak_self, @_); } ); require HTTP::Message; my $decodable = HTTP::Message::decodable(); $self->verbose(2, "HTTP decodable: ", $decodable); $ua->default_header("Accept-Encoding", $decodable); $ua }
Truth table0%0/3
A ||= B
A= $self->{"ua"}B= do { require LWP::UserAgent; "LWP::UserAgent"->VERSION("5.832"); my $ua = "LWP::UserAgent"->new("keep_alive", 1); builtin::weaken($ua->{"App::RSS2Leafnode"} = $self); $ua->agent($self->user_agent); builtin::weaken(my $weak_self = $self); $ua->add_handler("request_send", \&App::RSS2Leafnode::lwp_request_send__verbose); $ua->add_handler("response_done", sub { lwp_response_done__check_md5($weak_self, @_); } ); require HTTP::Message; my $decodable = HTTP::Message::decodable(); $self->verbose(2, "HTTP decodable: ", $decodable); $ua->default_header("Accept-Encoding", $decodable); $ua }
ABresult
1X1
011
000
422 0 require LWP::UserAgent;
423 0 LWP::UserAgent->VERSION(5.832); # 5.832 for content_charset()
424  
425 # one connection kept alive
426 0 my $ua = LWP::UserAgent->new (keep_alive => 1);
427 0 Scalar::Util::weaken ($ua->{(__PACKAGE__)} = $self);
428 0 $ua->agent ($self->user_agent);
429  
430 0 Scalar::Util::weaken (my $weak_self = $self);
431 0 $ua->add_handler (request_send => \&lwp_request_send__verbose);
432 0 ▶ $ua->add_handler (response_done => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
433 0 lwp_response_done__check_md5 ($weak_self, @_);
434 0 });
435  
436 # ask for everything $resp->decode() / $resp->decoded_content() can cope
437 # with, in particular "gzip" and "deflate" compression if Compress::Zlib
438 # etc is available
439 #
440 0 require HTTP::Message;
441 0 my $decodable = HTTP::Message::decodable();
442 0 $self->verbose (2, "HTTP decodable: ", $decodable);
443 0 $ua->default_header ('Accept-Encoding' => $decodable);
444  
445 0 $ua
446 });
447 }
448  
449 0 ▶sub lwp_request_send__verbose {
Subroutine lwp_request_send__verbose: not called CC=1 SCAR=6.9
Pod undocumented
450 0 my ($req, $ua, $h) = @_;
451 0 my $self = $ua->{(__PACKAGE__)};
452 0 $self->verbose (2, "request_send:", $req->dump, "\n"); # extra newline
453 0 return; # continue processing
454 }
455  
456 0 ▶sub lwp_response_done__check_md5 {
Subroutine lwp_response_done__check_md5: not called CC=4 SCAR=30.0
Pod undocumented
457 0 my ($self, $resp, $ua, $h) = @_;
458 0 ▶ $self || return;
Branch: 1 branch
BranchTrueFalseTotal
$self or return 0 0 0
459 ### lwp_response_done__check_md5() ...
460 0 ▶ my $want = $resp->header('Content-MD5') // do {
Condition0%0/3
$resp->header("Content-MD5") // do { $self->verbose(2, "no Content-MD5 header"); return }
l!l&&r!l&&!r
000
MC/DC0%0/2
$resp->header("Content-MD5") // do { $self->verbose(2, "no Content-MD5 header"); return }
$resp->header("Content-MD5") do { $self->verbose(2, "no Content-MD5 header"); return }
Truth table0%0/3
A // B
A= $resp->header("Content-MD5")B= do { $self->verbose(2, "no Content-MD5 header"); return }
ABresult
1X1
011
000
461 0 $self->verbose (2, 'no Content-MD5 header');
462 0 return;
463 };
464 0 $resp->decode;
465 0 my $cref = $resp->content_ref;
466 0 require Digest::MD5;
467 0 my $got = Digest::MD5::md5_hex($$cref);
468 0 ▶ if ($got ne $want) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got ne $want) { } 0 0 0
469 0 print __x("Warning, MD5 checksum mismatch on download {url}\n",
470 url => $resp->request->uri);
471 } else {
472 0 $self->verbose(2, 'Content-MD5 ok');
473 }
474 }
475  
476 # $resp is a HTTP::Response object. Modify its headers to apply our
477 # $html_charset_from_content option, which means if it's set then prefer the
478 # document's Content-Type over what the server says.
479 #
480 # The LWP::UserAgent parse_head option appends the document <META> bits to
481 # the message headers. If the server and the document both offer a
482 # Content-Type then there's two, with the document one last, so all we have
483 # to do is change to make the last one the only one.
484 #
485 0 ▶sub enforce_html_charset_from_content {
Subroutine enforce_html_charset_from_content: not called CC=3 SCAR=24.8
Pod undocumented
486 0 my ($self, $resp) = @_;
487 0 ▶ if ($self->{'html_charset_from_content'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"html_charset_from_content"} and $resp->headers->content_is_html) 0 0 0
Condition0%0/3
$self->{"html_charset_from_content"} and $resp->headers->content_is_html
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"html_charset_from_content"} and $resp->headers->content_is_html
$self->{"html_charset_from_content"} $resp->headers->content_is_html
Truth table0%0/3
A and B
A= $self->{"html_charset_from_content"}B= $resp->headers->content_is_html
ABresult
0X0
100
111
488 && $resp->headers->content_is_html) {
489 0 my $old = $resp->header('Content-Type');
490 0 $resp->header('Content-Type' => $resp->headers->content_type);
491  
492 0 $self->verbose (2, 'html_charset_from_content mangled Content-Type from');
493 0 $self->verbose (2, " from ", $old);
494 0 $self->verbose (2, " to ", $resp->header('Content-Type'));
495 0 $self->verbose (2, " giving charset ", $resp->content_charset);
496 }
497 }
498  
499  
500 #------------------------------------------------------------------------------
501 2 my %known;
502  
503 # <dcterms:valid> dates through which thing is valid
504 # ENHANCE-ME: is this something to work into the skipdays? or a message expiry?
505 #
506 2 $known{'/channel/item/dcterms:valid'} = undef;
507  
508 # <dcterms:audience> maybe the target audience for speeches, announcements.
509 2 $known{'/channel/item/dcterms:audience'} = undef;
510  
511 # <eq:depth> earthquake depth, repeat of text
512 # <eq:seconds> unix seconds since 1970 date of earthquake, repeating text
513 2 @known{qw(/channel/item/eq:depth
514 /channel/item/eq:seconds)} = ();
515  
516 # rdf structure stuff
517 2 @known{qw(/channel/items
518 /channel/items/rdf:Seq
519 /channel/items/rdf:Seq/rdf:li)} = ();
520  
521 2 @known{('/channel/cloud',
522 '/channel/link',
523 '/channel/docs',
524 '/channel/generator',
525 '/channel/rating',
526 '/channel/id',
527 '/channel/description',
528 '/channel/tagline',
529 '/channel/info', # atom something freeform
530 '/channel/itunes:summary',
531 '/channel/feedburner:info',
532  
533 # nothing much in these as yet eg. rssboard
534 '/channel/item/sitemap:priority',
535 '/channel/item/sitemap:changefreq',
536  
537 # feedburner junk
538 '/channel/feedburner:feedFlare',
539  
540 # images
541 '/channel/itunes:owner',
542 '/channel/itunes:owner/itunes:name',
543 '/channel/itunes:owner/itunes:email',
544  
545 '/channel/textInput',
546 '/channel/textInput/description',
547 '/channel/textInput/link',
548 '/channel/textInput/name',
549 '/channel/textInput/title',
550 '/channel/textinput',
551 '/channel/textinput/title',
552 '/channel/textinput/description',
553 '/channel/textinput/name',
554 '/channel/textinput/link',
555  
556 '/channel/openSearch:totalResults',
557 '/channel/openSearch:startIndex',
558 '/channel/openSearch:itemsPerPage',
559  
560 '/channel/item',
561 '/channel/item/source',
562  
563 '/channel/item/twitter:source',
564  
565 # something from radio free france
566 # eg. http://radiofrance-podcast.net/podcast09/rss_10193.xml
567 '/channel/item/podcastRF:businessReference',
568  
569 # google documents stuff
570 '/channel/item/gd:extendedProperty',
571  
572 # <cb:statistics> repeats in structured form the rate shown in the text
573 # eg. RBA http://www.rba.gov.au/rss/rss-cb-exchange-rates.xml
574 'channel/item/cb:statistics',
575  
576 # <cb:news> repeats plain text
577 # eg. Fed Reserve http://www.federalreserve.gov/feeds/press_taf.xml
578 '/channel/item/cb:news',
579  
580 # FIXME: <cb:speech> may have bit extra detail
581 # Fed eg. http://www.federalreserve.gov/feeds/speeches.xml
582 '/channel/item/cb:speech',
583  
584 # <cb:paper> repeat in structured form
585 # <cb:event> guess likewise
586 # Fed eg. http://www.federalreserve.gov/feeds/ifdp.xml
587 # FIXME: except <cb:resource><cb:link> has extra pdf form link
588 '/channel/item/cb:paper',
589 '/channel/item/cb:event',
590  
591 # <media:hash> is an sha-1 or similar hash of a target media file etc
592 '/channel/item/media:hash',
593  
594 # not sure what these are, but don't seem very interesting
595 '/channel/item/slate:slate_plus', # <slate:slate_plus>false</slate:slate_plus>
596 '/channel/item/slate:paywall', # <slate:paywall>false</slate:paywall>
597 '/channel/item/slate:sponsored', # <slate:sponsored>false</slate:sponsored>
598 )} = ();
599  
600 # weather
601 # '/channel/item/w:current',
602 # '/channel/item/w:forecast',
603 # '/channel/yweather:location',
604 # '/channel/yweather:units',
605 # '/channel/yweather:wind',
606 # '/channel/yweather:atmosphere',
607 # '/channel/yweather:astronomy',
608 # '/channel/item/yweather:condition',
609 # '/channel/item/yweather:forecast',
610  
611 # --central-bank
612 # /channel/item/cb:statistics
613 # /channel/item/cb:statistics/cb:country
614 # /channel/item/cb:statistics/cb:institutionAbbrev
615 # /channel/item/cb:statistics/cb:exchangeRate
616 # /channel/item/cb:statistics/cb:exchangeRate/cb:value
617 # /channel/item/cb:statistics/cb:exchangeRate/cb:baseCurrency
618 # /channel/item/cb:statistics/cb:exchangeRate/cb:targetCurrency
619 # /channel/item/cb:statistics/cb:exchangeRate/cb:rateType
620 # /channel/item/cb:statistics/cb:exchangeRate/cb:observationPeriod
621 # /channel/item/cb:speech
622 # /channel/item/cb:speech/cb:simpleTitle
623 # /channel/item/cb:speech/cb:occurrenceDate
624 # /channel/item/cb:speech/cb:person
625 # /channel/item/cb:speech/cb:person/cb:givenName
626 # /channel/item/cb:speech/cb:person/cb:surname
627 # /channel/item/cb:speech/cb:person/cb:personalTitle
628 # /channel/item/cb:speech/cb:person/cb:nameAsWritten
629 # /channel/item/cb:speech/cb:person/cb:role
630 # /channel/item/cb:speech/cb:person/cb:role/cb:jobTitle
631 # /channel/item/cb:speech/cb:person/cb:role/cb:affiliation
632 # /channel/item/cb:speech/cb:venue
633  
634  
635 #------------------------------------------------------------------------------
636 # dates
637  
638 2 ▶use constant RFC822_STRFTIME_FORMAT => '%a, %d %b %Y %H:%M:%S %z';
Subroutine BEGIN: called CC=1 SCAR=0.0
639  
640 # return a string which is current time in RFC 822 format
641 0 ▶sub rfc822_time_now {
Subroutine rfc822_time_now: not called CC=1 SCAR=6.9
Pod undocumented
642 0 return POSIX::strftime (RFC822_STRFTIME_FORMAT, localtime(time()));
643 }
644  
645 0 ▶sub isodate_to_rfc822 {
Subroutine isodate_to_rfc822: not called CC=7 SCAR=40.3
Pod undocumented
646 0 my ($isodate) = @_;
647 0 ▶ if (! defined $isodate) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $isodate) 0 0 0
648 0 my $date = $isodate; # the original goes through if unrecognised
649  
650 0 ▶ if ($isodate =~ /\dT\d/ || $isodate =~ /^\d{4}-\d{2}-\d{2}$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isodate =~ /\dT\d/ or $isodate =~ /^\d{4}-\d{2}-\d{2}$/) 0 0 0
Condition0%0/3
$isodate =~ /\dT\d/ or $isodate =~ /^\d{4}-\d{2}-\d{2}$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$isodate =~ /\dT\d/ or $isodate =~ /^\d{4}-\d{2}-\d{2}$/
$isodate =~ /\dT\d/ $isodate =~ /^\d{4}-\d{2}-\d{2}$/
Truth table0%0/3
A or B
A= $isodate =~ /\dT\d/B= $isodate =~ /^\d{4}-\d{2}-\d{2}$/
ABresult
1X1
011
000
651 # eg. "2000-01-01T12:00+00:00"
652 # "2000-01-01T12:00:00Z"
653 # "2000-01-01"
654 0 ▶ my $zonestr = ($isodate =~ s/([+-][0-9][0-9]):([0-9][0-9])$// ? " $1$2"
Branch: 2 branches
BranchTrueFalseTotal
$isodate =~ s/([+-][0-9][0-9]):([0-9][0-9])$// ? : 0 0 0
$isodate =~ s/Z$// ? : 0 0 0
655 : $isodate =~ s/Z$// ? ' +0000'
656 : '');
657 0 require Date::Parse;
658 0 my $time_t = Date::Parse::str2time($isodate);
659 0 ▶ if (defined $time_t) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time_t) 0 0 0
660 0 $date = POSIX::strftime ("%a, %d %b %Y %H:%M:%S$zonestr",
661 localtime ($time_t));
662 }
663 }
664 0 return $date;
665 }
666  
667 # Return an RFC822 date string, or undef if nothing known.
668 # This gets a sensible sort-by-date in the newsreader.
669 # <jf:creationDate> seems to be accompanied by the usual <pubDate> so may be
670 # redundant.
671 #
672 0 ▶sub item_to_date {
Subroutine item_to_date: not called CC=13 SCAR=52.0
Pod undocumented
673 0 my ($self, $item) = @_;
674 0 my $date;
675 0 foreach my $elt ($item, elt_to_channel($item)) {
676 0 ▶ $date = (non_empty ($elt->first_child_trimmed_text('pubDate'))
Condition0%0/30
(((((((((non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))) // non_empty($elt->first_child_trimmed_text("jf:creationDate"))) // non_empty($elt->first_child_trimmed_text("modified"))) // non_empty($elt->first_child_trimmed_text("updated"))) // non_empty($elt->first_child_trimmed_text("issued"))) // non_empty($elt->first_child_trimmed_text("dcterms:issued"))) // non_empty($elt->first_child_trimmed_text("created"))) // non_empty($elt->first_child_trimmed_text("lastBuildDate"))) // non_empty($elt->first_child_trimmed_text("published"))) // non_empty($elt->first_child_trimmed_text("prism:publicationDate"))
l!l&&r!l&&!r
000
((((((((non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))) // non_empty($elt->first_child_trimmed_text("jf:creationDate"))) // non_empty($elt->first_child_trimmed_text("modified"))) // non_empty($elt->first_child_trimmed_text("updated"))) // non_empty($elt->first_child_trimmed_text("issued"))) // non_empty($elt->first_child_trimmed_text("dcterms:issued"))) // non_empty($elt->first_child_trimmed_text("created"))) // non_empty($elt->first_child_trimmed_text("lastBuildDate"))) // non_empty($elt->first_child_trimmed_text("published"))
l!l&&r!l&&!r
000
(((((((non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))) // non_empty($elt->first_child_trimmed_text("jf:creationDate"))) // non_empty($elt->first_child_trimmed_text("modified"))) // non_empty($elt->first_child_trimmed_text("updated"))) // non_empty($elt->first_child_trimmed_text("issued"))) // non_empty($elt->first_child_trimmed_text("dcterms:issued"))) // non_empty($elt->first_child_trimmed_text("created"))) // non_empty($elt->first_child_trimmed_text("lastBuildDate"))
l!l&&r!l&&!r
000
((((((non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))) // non_empty($elt->first_child_trimmed_text("jf:creationDate"))) // non_empty($elt->first_child_trimmed_text("modified"))) // non_empty($elt->first_child_trimmed_text("updated"))) // non_empty($elt->first_child_trimmed_text("issued"))) // non_empty($elt->first_child_trimmed_text("dcterms:issued"))) // non_empty($elt->first_child_trimmed_text("created"))
l!l&&r!l&&!r
000
(((((non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))) // non_empty($elt->first_child_trimmed_text("jf:creationDate"))) // non_empty($elt->first_child_trimmed_text("modified"))) // non_empty($elt->first_child_trimmed_text("updated"))) // non_empty($elt->first_child_trimmed_text("issued"))) // non_empty($elt->first_child_trimmed_text("dcterms:issued"))
l!l&&r!l&&!r
000
((((non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))) // non_empty($elt->first_child_trimmed_text("jf:creationDate"))) // non_empty($elt->first_child_trimmed_text("modified"))) // non_empty($elt->first_child_trimmed_text("updated"))) // non_empty($elt->first_child_trimmed_text("issued"))
l!l&&r!l&&!r
000
(((non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))) // non_empty($elt->first_child_trimmed_text("jf:creationDate"))) // non_empty($elt->first_child_trimmed_text("modified"))) // non_empty($elt->first_child_trimmed_text("updated"))
l!l&&r!l&&!r
000
((non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))) // non_empty($elt->first_child_trimmed_text("jf:creationDate"))) // non_empty($elt->first_child_trimmed_text("modified"))
l!l&&r!l&&!r
000
(non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))) // non_empty($elt->first_child_trimmed_text("jf:creationDate"))
l!l&&r!l&&!r
000
non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))
l!l&&r!l&&!r
000
MC/DC0%0/11
(((((((((non_empty($elt->first_child_trimmed_text("pubDate")) // non_empty($elt->first_child_trimmed_text("dc:date"))) // non_empty($elt->first_child_trimmed_text("jf:creationDate"))) // non_empty($elt->first_child_trimmed_text("modified"))) // non_empty($elt->first_child_trimmed_text("updated"))) // non_empty($elt->first_child_trimmed_text("issued"))) // non_empty($elt->first_child_trimmed_text("dcterms:issued"))) // non_empty($elt->first_child_trimmed_text("created"))) // non_empty($elt->first_child_trimmed_text("lastBuildDate"))) // non_empty($elt->first_child_trimmed_text("published"))) // non_empty($elt->first_child_trimmed_text("prism:publicationDate"))
non_empty($elt->first_child_trimmed_text("pubDate")) non_empty($elt->first_child_trimmed_text("dc:date")) non_empty($elt->first_child_trimmed_text("jf:creationDate")) non_empty($elt->first_child_trimmed_text("modified")) non_empty($elt->first_child_trimmed_text("updated")) non_empty($elt->first_child_trimmed_text("issued")) non_empty($elt->first_child_trimmed_text("dcterms:issued")) non_empty($elt->first_child_trimmed_text("created")) non_empty($elt->first_child_trimmed_text("lastBuildDate")) non_empty($elt->first_child_trimmed_text("published")) non_empty($elt->first_child_trimmed_text("prism:publicationDate"))
Truth table0%0/12
A // B // C // D // E // F // G // H // I // J // K
A= non_empty($elt->first_child_trimmed_text("pubDate"))B= non_empty($elt->first_child_trimmed_text("dc:date"))C= non_empty($elt->first_child_trimmed_text("jf:creationDate"))D= non_empty($elt->first_child_trimmed_text("modified"))E= non_empty($elt->first_child_trimmed_text("updated"))F= non_empty($elt->first_child_trimmed_text("issued"))G= non_empty($elt->first_child_trimmed_text("dcterms:issued"))H= non_empty($elt->first_child_trimmed_text("created"))I= non_empty($elt->first_child_trimmed_text("lastBuildDate"))J= non_empty($elt->first_child_trimmed_text("published"))K= non_empty($elt->first_child_trimmed_text("prism:publicationDate"))
ABCDEFGHIJKresult
1XXXXXXXXXX1
01XXXXXXXXX1
001XXXXXXXX1
0001XXXXXXX1
00001XXXXXX1
000001XXXXX1
0000001XXXX1
00000001XXX1
000000001XX1
0000000001X1
000000000011
000000000000
677 // non_empty ($elt->first_child_trimmed_text('dc:date'))
678 // non_empty ($elt->first_child_trimmed_text('jf:creationDate'))
679 # Atom
680 // non_empty ($elt->first_child_trimmed_text('modified'))
681 // non_empty ($elt->first_child_trimmed_text('updated'))
682 // non_empty ($elt->first_child_trimmed_text('issued'))
683 // non_empty ($elt->first_child_trimmed_text('dcterms:issued'))
684 // non_empty ($elt->first_child_trimmed_text('created'))
685 # channel
686 // non_empty ($elt->first_child_trimmed_text('lastBuildDate'))
687 # Atom
688 // non_empty ($elt->first_child_trimmed_text('published'))
689 # from Nature have dc:date anyway
690 // non_empty ($elt->first_child_trimmed_text('prism:publicationDate'))
691 );
692 0 ▶ last if defined $date;
Branch: 1 branch
BranchTrueFalseTotal
if defined $date 0 0 0
693 }
694 0 return isodate_to_rfc822($date);
695 }
696 2 @known{qw(/channel/dc:date
697 /channel/lastBuildDate
698 /channel/pubDate
699 /channel/updated
700 /channel/modified
701  
702 /channel/item/dc:date
703 /channel/item/pubDate
704 /channel/item/updated
705 /channel/item/published
706 /channel/item/modified
707 /channel/item/created
708 /channel/item/issued
709 /channel/item/dcterms:issued
710  
711 /channel/item/jf:creationDate --java-locale-human-readable
712 /channel/item/jf:modificationDate
713 /channel/item/jf:date --free-form
714 )} = ();
715  
716  
717 0 ▶sub item_to_timet {
Subroutine item_to_timet: not called CC=3 SCAR=24.8
Pod undocumented
718 0 my ($self, $item) = @_;
719 ### item_to_timet() ...
720 0 ▶ my $str = $self->item_to_date($item)
Condition0%0/2
$self->item_to_date($item) // (return "-1.79769313486232e+308")
l!l
00
MC/DC0%0/1
$self->item_to_date($item) // (return "-1.79769313486232e+308")
$self->item_to_date($item)
Truth table0%0/2
A
A= $self->item_to_date($item)
Aresult
11
00
721 // return - POSIX::DBL_MAX(); # no date fields
722  
723 0 require Date::Parse;
724 ### $str
725 # print Date::Parse::str2time($str)," $str\n";
726 return (Date::Parse::str2time($str)
727 0 ▶ // do {
Condition0%0/3
Date::Parse::str2time($str) // do { say &__x("Unrecognised date \"{date}\" from {url}", "date", $str, "url", $self->{"uri"}); "-1.79769313486232e+308" }
l!l&&r!l&&!r
000
MC/DC0%0/2
Date::Parse::str2time($str) // do { say &__x("Unrecognised date \"{date}\" from {url}", "date", $str, "url", $self->{"uri"}); "-1.79769313486232e+308" }
Date::Parse::str2time($str) do { say &__x("Unrecognised date \"{date}\" from {url}", "date", $str, "url", $self->{"uri"}); "-1.79769313486232e+308" }
Truth table0%0/3
A // B
A= Date::Parse::str2time($str)B= do { say &__x("Unrecognised date \"{date}\" from {url}", "date", $str, "url", $self->{"uri"}); "-1.79769313486232e+308" }
ABresult
1X1
011
000
728 say __x('Unrecognised date "{date}" from {url}',
729 date => $str,
730 0 url => $self->{'uri'});
731 0 - POSIX::DBL_MAX();
732 });
733 }
734  
735 #-----------------------------------------------------------------------------
736 # Message-ID
737  
738 # Return a message ID for something at $uri, optionally uniquified by $str.
739 # $uri is either a URI object or a url string.
740 # Weird chars in $uri or $str are escaped as necessary.
741 # Secret $self->{'msgidextra'} can make different message ids for the same
742 # content when testing.
743 #
744 # The path from $uri is incorporated in the result. fetch_html() needs this
745 # since the ETag identifier is only per-url, not globally unique. Suspect
746 # fetch_rss() needs it for a guid too (a non-permaLink one), as think the
747 # guid is only unique within the particular $uri feed, not globally and not
748 # even across multiple feeds on the same server.
749 #
750 0 ▶sub url_to_msgid {
Subroutine url_to_msgid: not called CC=10 SCAR=47.0
Pod undocumented
751 0 my ($self, $url, $str) = @_;
752  
753 0 my $host;
754 0 my $pathbit = $url;
755  
756 0 ▶ if (my $uri = eval { URI->new($url) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $uri = eval { do { "URI"->new($url) } }) 0 0 0
757 0 $uri = $uri->canonical;
758 0 ▶ if ($uri->can('host')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($uri->can('host')) { } 0 0 0
elsif ($uri->can('authority')) { } 0 0 0
759 0 $host = $uri->host;
760 0 $uri->host('');
761 0 $pathbit = $uri->as_string;
762  
763 # If the $uri schema has a host part but it's empty or "localhost"
764 # then try expanding that to hostname().
765 #
766 # $uri schemas without a host part, like "urn:" in an Atom <id> don't
767 # get hostname(), since want the generated msgid to come out the same
768 # if such a urn: appears from different downloaded locations.
769 #
770 0 ▶ if (is_empty($host) || $host eq 'localhost') {
Branch: 1 branch
BranchTrueFalseTotal
if (is_empty($host) or $host eq "localhost") 0 0 0
Condition0%0/3
is_empty($host) or $host eq "localhost"
l!l&&r!l&&!r
000
MC/DC0%0/2
is_empty($host) or $host eq "localhost"
is_empty($host) $host eq "localhost"
Truth table0%0/3
A or B
A= is_empty($host)B= $host eq "localhost"
ABresult
1X1
011
000
771 0 require Sys::Hostname;
772 0 eval { $host = Sys::Hostname::hostname() };
773 }
774  
775 } elsif ($uri->can('authority')) {
776 # the "authority" part of a "tag:" schema
777 0 $host = $uri->authority;
778 0 $uri->authority('');
779 0 $pathbit = $uri->as_string;
780 }
781 }
782  
783 # $host can be empty if running from a file:///
784 # "localhost" is a bit bogus and in particular leafnode won't accept it.
785 # ".invalid" as per RFC 2606
786 0 ▶ if (is_empty($host) || $host eq 'localhost') {
Branch: 1 branch
BranchTrueFalseTotal
if (is_empty($host) or $host eq "localhost") 0 0 0
Condition0%0/3
is_empty($host) or $host eq "localhost"
l!l&&r!l&&!r
000
MC/DC0%0/2
is_empty($host) or $host eq "localhost"
is_empty($host) $host eq "localhost"
Truth table0%0/3
A or B
A= is_empty($host)B= $host eq "localhost"
ABresult
1X1
011
000
787 0 $host = 'rss2leafnode.invalid';
788 }
789  
790 # ipv6 dotted hostname "[1234:5678::0000]" -> "1234.5678.0000..ipv6",
791 # because [ and : are not allowed (RFC 2822 "Atom" atext)
792 # $uri->canonical above lower cases any hex, for consistency
793 0 ▶ if (($host =~ s/^\[|\]$//g) | ($host =~ tr/:/./)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ s/^\[|\]$//g | $host =~ tr/:/./) 0 0 0
794 0 $host .= '.ipv6';
795 }
796  
797 # leafnode 2.0.0.alpha20070602a seems to insist on a "." in the host name
798 0 ▶ unless ($host =~ /\./) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($host =~ /\./) 0 0 0
799 0 $host .= '.withadot';
800 }
801  
802 return ('<'
803 . msgid_chars(join_non_empty('.',
804 0 "rss2leafnode" . $self->{'msgidextra'},
805 $pathbit,
806 $str))
807 . '@'
808 . msgid_chars($host)
809 . '>');
810 }
811 # msgid_chars($str) returns $str with invalid Message-ID characters munged.
812 # Per RFC850 must be printing ascii and not < > or whitespace, but for
813 # safety reduce that a bit, in particular excluding ' and ".
814 0 ▶sub msgid_chars {
Subroutine msgid_chars: not called CC=1 SCAR=6.9
Pod undocumented
815 0 my ($str) = @_;
816 0 require URI::Escape;
817 0 return URI::Escape::uri_escape_utf8 ($str, "^A-Za-z0-9\\-_.!~*/:");
818 }
819  
820 #------------------------------------------------------------------------------
821 # news posting
822 #
823 # This used to run the "rnews" program, which in leafnode 2 does some direct
824 # writing to the spool. But that requires user "news" perms, and as of the
825 # June 2007 leafnode beta it tends to be a good deal slower because it reads
826 # the whole groupinfo file. It has the advantage of not being picky about
827 # message ID hostnames, and allowing read-only groups to be filled. But
828 # apart from that plain POST seems much easier for being "server neutral".
829 #
830 # IHAVE instead of POST would be a possibility, when available, though POST
831 # is probably more accurate in the sense it's a new article coming into the
832 # news system.
833 #
834 # Net::NNTP looks at $ENV{NNTPSERVER}, $ENV{NEWSHOST} and Net::Config
835 # nntp_hosts list for the news server. Maybe could have that here too,
836 # instead of always defaulting to localhost (in $self->{'nntp_host'}).
837 # Would want to find out the name chosen to show in diagnostics though.
838  
839 # return a string "host:port", suitable for the Host arg to Net::NNTP->new
840 0 ▶sub uri_to_nntp_host {
Subroutine uri_to_nntp_host: not called CC=2 SCAR=17.9
Pod undocumented
841 0 my ($uri) = @_;
842 0 ▶ return (non_empty($uri->host) // 'localhost') . ':' . $uri->port;
Condition0%0/2
non_empty($uri->host) // "localhost"
l!l
00
MC/DC0%0/1
non_empty($uri->host) // "localhost"
non_empty($uri->host)
Truth table0%0/2
A
A= non_empty($uri->host)
Aresult
11
00
843 }
844  
845 0 ▶sub nntp {
Subroutine nntp: not called CC=6 SCAR=37.4
Pod undocumented
846 0 my ($self) = @_;
847 # reopen if different 'nntp_host'
848 0 ▶ if (! $self->{'nntp'}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"nntp"} or $self->{"nntp"}->host ne $self->{"nntp_host"}) 0 0 0
Condition0%0/3
not $self->{"nntp"} or $self->{"nntp"}->host ne $self->{"nntp_host"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $self->{"nntp"} or $self->{"nntp"}->host ne $self->{"nntp_host"}
not $self->{"nntp"} $self->{"nntp"}->host ne $self->{"nntp_host"}
Truth table0%0/3
not(A) or B
A= not $self->{"nntp"}B= $self->{"nntp"}->host ne $self->{"nntp_host"}
ABresult
1X1
011
000
849 || $self->{'nntp'}->host ne $self->{'nntp_host'}) {
850 0 my $host = $self->{'nntp_host'};
851 0 $self->verbose (1, __x("nntp: {host}", host => $host));
852 0 require Net::NNTP;
853 my $nntp = $self->{'nntp'}
854 0 ▶ = Net::NNTP->new ($host, ($self->{'verbose'} >= 2
Branch: 1 branch
BranchTrueFalseTotal
$self->{'verbose'} >= 2 ? : 0 0 0
855 ? (Debug => 1)
856 : ()));
857 0 ▶ if (! $nntp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nntp) 0 0 0
858 0 croak __x("Cannot connect to NNTP on \"{host}\"\n", host => $host);
859 }
860 0 ▶ if (! $nntp->postok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nntp->postok) 0 0 0
861 0 $self->verbose (1, "Hmm, ", $nntp->host, " doesn't say \"posting ok\" ...");
862 }
863 }
864 0 return $self->{'nntp'};
865 }
866  
867 0 ▶sub nntp_close {
Subroutine nntp_close: not called CC=3 SCAR=24.8
Pod undocumented
868 0 my ($self) = @_;
869 0 ▶ if (my $nntp = delete $self->{'nntp'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $nntp = delete $self->{"nntp"}) 0 0 0
870 0 ▶ if (! $nntp->quit) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $nntp->quit) 0 0 0
871 0 say "Error closing nntp: ",$nntp->message;
872 }
873 }
874 }
875  
876 # check that $group exists in the NNTP, return 1 if so, or 0 if not
877 0 ▶sub nntp_group_check {
Subroutine nntp_group_check: not called CC=2 SCAR=17.9
Pod undocumented
878 0 my ($self, $group) = @_;
879 0 my $nntp = $self->nntp;
880 0 ▶ if (! $nntp->group($group)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nntp->group($group)) 0 0 0
881 0 print __x("rss2leafnode: no group \"{group}\" on host \"{host}\"
882 (See the rss2leafnode man page for notes on creating groups.)
883 ",
884 host => $nntp->host,
885 group => $group);
886 0 return 0;
887 }
888  
889 0 return 1;
890 }
891  
892 0 ▶sub nntp_message_id_exists {
Subroutine nntp_message_id_exists: not called CC=5 SCAR=34.0
Pod undocumented
893 0 my ($self, $msgid) = @_;
894 0 my $ret = $self->nntp->nntpstat($msgid);
895 0 ▶ if ($self->{'verbose'} >= 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'verbose'} >= 2) { } 0 0 0
elsif ($self->{'verbose'} >= 1) { } 0 0 0
896 0 ▶ $self->verbose (2, "'$msgid' ", ($ret ? 'exists already' : 'new'));
Branch: 1 branch
BranchTrueFalseTotal
$ret ? : 0 0 0
897 } elsif ($self->{'verbose'} >= 1) {
898 0 ▶ if ($ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) 0 0 0
899 0 $self->verbose (1, ' ', __('exists already'));
900 }
901 }
902 0 return $ret;
903 }
904  
905 # post $msg to NNTP, return true if successful
906 0 ▶sub nntp_post {
Subroutine nntp_post: not called CC=2 SCAR=17.9
Pod undocumented
907 0 my ($self, $msg) = @_;
908 0 my $nntp = $self->nntp;
909 0 ▶ if (! $nntp->post ($msg->as_string)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nntp->post($msg->as_string)) 0 0 0
910 0 say __x('Cannot post: {message}',
911 message => scalar($nntp->message));
912 0 return 0;
913 }
914 0 return 1;
915 }
916  
917  
918 #------------------------------------------------------------------------------
919 # HTML title
920  
921 # extra data associated against a HTTP::Response object
922 2 Hash::Util::FieldHash::fieldhash (my %resp_exiftool_info);
923  
924 # return hashref { Title => $str, ... }, or empty {} if no exiftool etc
925 0 ▶sub resp_exiftool_info {
Subroutine resp_exiftool_info: not called CC=3 SCAR=24.8
Pod undocumented
926 0 my ($resp) = @_;
927 0 ▶ defined $resp or return {};
Branch: 1 branch
BranchTrueFalseTotal
defined $resp or return {} 0 0 0
928 0 ▶ if (! exists $resp_exiftool_info{$resp}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $resp_exiftool_info{$resp}) 0 0 0
929 0 $resp_exiftool_info{$resp} = _resp_exiftool_info($resp);
930 ### exiftool info: $resp_exiftool_info{$resp}
931 }
932 0 return $resp_exiftool_info{$resp};
933 }
934 0 ▶sub _resp_exiftool_info {
Subroutine _resp_exiftool_info: not called CC=2 SCAR=17.9
935 0 my ($resp) = @_;
936  
937 # Want ExifTool 8.22 to have PNG tEXt returned as utf8, but don't bother
938 # to enforce that.
939 #
940 # The returned fields from image formats with a defined charset are
941 # converted to the exiftool default "Charset" of utf8, and from other
942 # image formats the fields are bytes of something unknown. Might slightly
943 # like to know which is the case, and show raw bytes different from "bytes
944 # which ought to be utf8", but for now just Encode::decode_utf8() and let
945 # its Encode::FB_DEFAULT() put substitution chars for non-ascii non-utf8.
946 #
947 0 ▶ eval { require Image::ExifTool; 1 } || return {};
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Image::ExifTool; 1 } } or return {} 0 0 0
948 0 $resp->decode;
949 0 my $cref = $resp->content_ref;
950 0 return Image::ExifTool::ImageInfo
951 ($cref,
952 ['Title','Author','Copyright','ImageSize'], # just these tags
953 {List => 0}); # get list values as comma separated
954 }
955  
956 # $resp is a HTTP::Response, return title
957 0 ▶sub html_title {
Subroutine html_title: not called CC=4 SCAR=30.0
Pod undocumented
958 0 my ($resp) = @_;
959  
960 return (# for images prefer filename+size over URI::Title just filename
961 0 ▶ non_empty (html_title_exiftool_image($resp))
Condition0%0/9
((non_empty(html_title_exiftool_image($resp)) // non_empty(html_title_urititle($resp))) // non_empty(html_title_exiftool($resp))) // $resp->title
l!l&&r!l&&!r
000
(non_empty(html_title_exiftool_image($resp)) // non_empty(html_title_urititle($resp))) // non_empty(html_title_exiftool($resp))
l!l&&r!l&&!r
000
non_empty(html_title_exiftool_image($resp)) // non_empty(html_title_urititle($resp))
l!l&&r!l&&!r
000
MC/DC0%0/4
((non_empty(html_title_exiftool_image($resp)) // non_empty(html_title_urititle($resp))) // non_empty(html_title_exiftool($resp))) // $resp->title
non_empty(html_title_exiftool_image($resp)) non_empty(html_title_urititle($resp)) non_empty(html_title_exiftool($resp)) $resp->title
Truth table0%0/5
A // B // C // D
A= non_empty(html_title_exiftool_image($resp))B= non_empty(html_title_urititle($resp))C= non_empty(html_title_exiftool($resp))D= $resp->title
ABCDresult
1XXX1
01XX1
001X1
00011
00000
962  
963 // non_empty (html_title_urititle($resp))
964 // non_empty (html_title_exiftool($resp))
965 // $resp->title);
966 }
967 0 ▶sub html_title_urititle {
Subroutine html_title_urititle: not called CC=3 SCAR=24.8
Pod undocumented
968 0 my ($resp) = @_;
969 0 ▶ eval { require URI::Title } or return undef;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require URI::Title } } or return undef 0 0 0
970  
971 # suppress some dodginess in URI::Title 1.82
972 0 ▶ local $SIG{'__WARN__'} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
973 0 my ($msg) = @_;
974 0 ▶ $msg =~ /Use of uninitialized value/ or warn @_;
Branch: 1 branch
BranchTrueFalseTotal
$msg =~ /Use of uninitialized value/ or warn @_ 0 0 0
975 0 };
976 0 $resp->decode;
977 0 ▶ return URI::Title::title
Condition0%0/2
$resp->request->uri // ""
l!l
00
MC/DC0%0/1
$resp->request->uri // ""
$resp->request->uri
Truth table0%0/2
A
A= $resp->request->uri
Aresult
11
00
978 ({ url => ($resp->request->uri // ''),
979 data => $resp->content});
980 }
981 0 ▶sub html_title_exiftool_image {
Subroutine html_title_exiftool_image: not called CC=5 SCAR=34.0
Pod undocumented
982 0 my ($resp) = @_;
983 0 ▶ $resp->content_type =~ m{^image/} or return;
Branch: 1 branch
BranchTrueFalseTotal
$resp->content_type =~ m[^image/] or return 0 0 0
984 0 ▶ if (defined (my $title = html_title_exiftool($resp))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $title = html_title_exiftool($resp))) 0 0 0
985 0 return $title;
986 }
987 0 ▶ my $info = resp_exiftool_info($resp) // return;
Condition0%0/2
resp_exiftool_info($resp) // (return)
l!l
00
MC/DC0%0/1
resp_exiftool_info($resp) // (return)
resp_exiftool_info($resp)
Truth table0%0/2
A
A= resp_exiftool_info($resp)
Aresult
11
00
988 ### html_title_exiftool_image() on: $info
989 0 ▶ defined $info->{'ImageSize'} or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $info->{"ImageSize"} or return 0 0 0
990 0 return $resp->filename.' '.$info->{'ImageSize'};
991 }
992 0 ▶sub html_title_exiftool {
Subroutine html_title_exiftool: not called CC=2 SCAR=17.9
Pod undocumented
993 0 my ($resp) = @_;
994 0 ▶ my $title = resp_exiftool_info($resp)->{'Title'} // return;
Condition0%0/2
resp_exiftool_info($resp)->{"Title"} // (return)
l!l
00
MC/DC0%0/1
resp_exiftool_info($resp)->{"Title"} // (return)
resp_exiftool_info($resp)->{"Title"}
Truth table0%0/2
A
A= resp_exiftool_info($resp)->{"Title"}
Aresult
11
00
995 0 return Encode::decode_utf8 ($title);
996 }
997  
998  
999 #------------------------------------------------------------------------------
1000 # mime
1001  
1002 # prepended to "X-Mailer" header
1003 2 ▶use constant mime_mailer_extra => "RSS2Leafnode $VERSION";
Subroutine BEGIN: called CC=1 SCAR=0.0
1004  
1005 # $body is a MIME::Body object, append $str to it
1006 0 ▶sub mime_body_append {
Subroutine mime_body_append: not called CC=3 SCAR=24.8
Pod undocumented
1007 0 my ($body, $str) = @_;
1008 0 $str = $body->as_string . "\n" . str_ensure_newline ($str);
1009 0 ▶ my $IO = $body->open('w')
Branch: 1 branch
BranchTrueFalseTotal
my $IO = $body->open("w") or die "rss2leafnode: body I/O open: $!" 0 0 0
1010 or die "rss2leafnode: body I/O open: $!";
1011 0 $IO->print ($str);
1012 0 ▶ $IO->close
Branch: 1 branch
BranchTrueFalseTotal
$IO->close or die "rss2leafnode: body I/O close: $!" 0 0 0
1013 or die "rss2leafnode: body I/O close: $!";
1014 }
1015  
1016 # if $str is not ascii then apply encode_mimewords()
1017 0 ▶sub mimewords_non_ascii {
Subroutine mimewords_non_ascii: not called CC=3 SCAR=24.8
Pod undocumented
1018 0 my ($str) = @_;
1019 0 ▶ if (defined $str && ! is_ascii($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and not is_ascii($str)) 0 0 0
Condition0%0/3
defined $str and not is_ascii($str)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $str and not is_ascii($str)
defined $str not is_ascii($str)
Truth table0%0/3
A and not(B)
A= defined $strB= not is_ascii($str)
ABresult
0X0
100
111
1020 0 require MIME::Words;
1021 0 $str = MIME::Words::encode_mimewords (Encode::encode_utf8($str),
1022 Charset => 'UTF-8');
1023 }
1024 0 return $str;
1025 }
1026  
1027 0 ▶sub mime_build {
Subroutine mime_build: not called CC=14 SCAR=53.5
Pod undocumented
1028 0 my ($self, $headers, @args) = @_;
1029  
1030 # Headers in utf-8, the same as other text. The docs of
1031 # encode_mimewords() isn't clear, but seems to expect bytes of the
1032 # specified charset.
1033 0 foreach my $key (sort keys %$headers) {
1034 $headers->{$key}
1035 0 = mimewords_non_ascii(Text::Trim::trim($headers->{$key}));
1036 }
1037  
1038 0 %$headers = (%$headers, @args);
1039 0 ▶ $headers->{'Top'} //= 0; # default to a part not a toplevel
Condition0%0/2
$headers->{"Top"} //= 0
l!l
00
MC/DC0%0/1
$headers->{"Top"} //= 0
$headers->{"Top"}
Truth table0%0/2
A
A= $headers->{"Top"}
Aresult
11
00
1040 0 ▶ $headers->{'Encoding'} //= '-SUGGEST';
Condition0%0/2
$headers->{"Encoding"} //= "-SUGGEST"
l!l
00
MC/DC0%0/1
$headers->{"Encoding"} //= "-SUGGEST"
$headers->{"Encoding"}
Truth table0%0/2
A
A= $headers->{"Encoding"}
Aresult
11
00
1041  
1042 0 ▶ if ($headers->{'Top'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headers->{"Top"}) 0 0 0
1043 0 my $now822 = rfc822_time_now();
1044 0 ▶ $headers->{'Date'} //= $now822;
Condition0%0/3
$headers->{"Date"} //= $now822
l!l&&r!l&&!r
000
MC/DC0%0/2
$headers->{"Date"} //= $now822
$headers->{"Date"} $now822
Truth table0%0/3
A //= B
A= $headers->{"Date"}B= $now822
ABresult
1X1
011
000
1045 0 $headers->{'Date-Received:'} = $now822;
1046 }
1047  
1048 0 ▶ if (utf8::is_utf8($headers->{'Data'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($headers->{"Data"})) 0 0 0
1049 0 warn 'Oops, mime_build() data should be bytes';
1050 }
1051  
1052 # downgrade utf-8 to us-ascii if possible
1053 0 ▶ if ($headers->{'Type'} eq 'text/plain'
Branch: 1 branch
BranchTrueFalseTotal
if ($headers->{"Type"} eq "text/plain" and lc($headers->{"Charset"} || 0) eq "utf-8" and is_ascii($headers->{"Data"})) 0 0 0
Condition0%0/8
$headers->{"Type"} eq "text/plain" and lc($headers->{"Charset"} || 0) eq "utf-8" and is_ascii($headers->{"Data"})
!ll&&!rl&&r
000
$headers->{"Type"} eq "text/plain" and lc($headers->{"Charset"} || 0) eq "utf-8"
!ll&&!rl&&r
000
$headers->{'Charset'} || 0
l!l
00
MC/DC0%0/3
$headers->{"Type"} eq "text/plain" and lc($headers->{"Charset"} || 0) eq "utf-8" and is_ascii($headers->{"Data"})
$headers->{"Type"} eq "text/plain" $headers->{'Charset'} is_ascii($headers->{"Data"})
Truth table0%0/4
A and B and C
A= $headers->{"Type"} eq "text/plain"B= $headers->{'Charset'}C= is_ascii($headers->{"Data"})
ABCresult
0XX0
10X0
1100
1111
1054 && lc($headers->{'Charset'}||0) eq 'utf-8'
1055 && is_ascii ($headers->{'Data'})) {
1056 0 $headers->{'Charset'} = 'us-ascii';
1057  
1058 # not sure mangling text/html body content is a good idea -- would only
1059 # want it on generated html, not downloaded
1060 #
1061 # if ($headers->{'Type'} eq 'text/html') {
1062 # $headers->{'Data'} =~ s{(<meta http-equiv=Content-Type content="text/html; charset=)([^"]+)}{$1us-ascii};
1063 # }
1064 }
1065  
1066 0 @args = map {$_,$headers->{$_}} sort keys %$headers;
1067 0 ▶ if ($self->{'verbose'} >= 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} >= 4) 0 0 0
1068 0 require Data::Dumper;
1069 0 $self->verbose (4, Data::Dumper->new([\@args],['mime headers'])->Dump);
1070 }
1071  
1072 0 require MIME::Entity;
1073 0 my $top = MIME::Entity->build (Disposition => 'inline', @args);
1074  
1075 0 ▶ if ($headers->{'Top'} && ! defined $headers->{'X-Mailer:'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headers->{"Top"} and not defined $headers->{"X-Mailer:"}) 0 0 0
Condition0%0/3
$headers->{"Top"} and not defined $headers->{"X-Mailer:"}
!ll&&!rl&&r
000
MC/DC0%0/2
$headers->{"Top"} and not defined $headers->{"X-Mailer:"}
$headers->{"Top"} not defined $headers->{"X-Mailer:"}
Truth table0%0/3
A and not(B)
A= $headers->{"Top"}B= not defined $headers->{"X-Mailer:"}
ABresult
0X0
100
111
1076 0 my $head = $top->head;
1077 0 $head->set('X-Mailer', join_non_empty (', ',
1078 $self->mime_mailer_extra,
1079 $head->get('X-Mailer')));
1080 }
1081  
1082 0 return $top;
1083 }
1084  
1085 # $resp is a HTTP::Response
1086 # Return a MIME::Entity which contains the response, and any further @headers.
1087 # If $self->{'render'} is true then render HTML to plain text.
1088 #
1089 0 ▶sub mime_part_from_response {
Subroutine mime_part_from_response: not called CC=2 SCAR=17.9
Pod undocumented
1090 0 my ($self, $resp, @headers) = @_;
1091  
1092 0 my $content_type = $resp->content_type;
1093 0 $self->verbose (2, ' content-type: ',$content_type);
1094 0 $resp->decode;
1095 0 my $content = $resp->content; # the bytes
1096 0 my $charset = $resp->content_charset; # and their charset
1097 0 my $url = $resp->request->uri->as_string;
1098 0 my $content_md5 = $resp->header('Content-MD5');
1099  
1100 0 ($content, $content_type, $charset, my $rendered)
1101 = $self->render_maybe ($content, $content_type, $charset, $url);
1102 0 ▶ if ($rendered) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rendered) 0 0 0
1103 0 undef $content_md5;
1104 }
1105  
1106 0 return $self->mime_build
1107 ({ 'Content-Language:' => scalar($resp->header('Content-Language')),
1108 'Content-Location:' => $url,
1109 'Content-MD5:' => $content_md5,
1110 @headers,
1111 },
1112 Type => $content_type,
1113 Charset => $charset,
1114 Data => $content,
1115 Filename => $resp->filename);
1116 }
1117  
1118  
1119 # set "Lines:" header per RFC 1036
1120 # MIME::Entity 5.428 doesn't seem to have anything for this itself
1121 # this is after qp or base64, is that right? the actual message lines
1122 0 ▶sub mime_entity_lines {
Subroutine mime_entity_lines: not called CC=1 SCAR=6.9
Pod undocumented
1123 0 my ($top) = @_;
1124 0 $top->head->set('Lines', str_count_lines ($top->stringify_body));
1125 }
1126  
1127 #------------------------------------------------------------------------------
1128 # XML::Twig stuff
1129  
1130 # Return the text of $elt and treat child elements as improperly escaped
1131 # parts of the text too.
1132 #
1133 # This is good for elements which are supposed to be HTML with <p> etc
1134 # escaped as &lt;p&gt;, but copes with feeds that don't have the necessary
1135 # escapes and thus come out with xml child elements under $elt.
1136 #
1137 # For elements which are supposed to be plain text with no markup and no
1138 # sub-elements this will at least make improper child text visible, though
1139 # it might not look very good.
1140 #
1141 # As of June 2010 http://www.drweil.com/drw/ecs/rss.xml is an example of
1142 # improperly escaped html.
1143 #
1144 # FIXME: Any need to watch out for <rdf:value> types?
1145 #
1146 0 ▶sub elt_subtext {
Subroutine elt_subtext: not called CC=3 SCAR=24.8
Pod undocumented
1147 0 my ($elt) = @_;
1148 0 ▶ defined $elt or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $elt or return undef 0 0 0
1149 0 ▶ if ($elt->is_text) { return $elt->text; }
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->is_text) 0 0 0
1150 0 return join ('', map {_elt_subtext_with_tags($_)} $elt->children);
1151 }
1152 0 ▶sub _elt_subtext_with_tags {
Subroutine _elt_subtext_with_tags: not called CC=3 SCAR=24.8
1153 0 my ($elt) = @_;
1154 0 ▶ defined $elt or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $elt or return undef 0 0 0
1155 0 ▶ if ($elt->is_text) { return $elt->text; }
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->is_text) 0 0 0
1156 return ($elt->start_tag
1157 0 . join ('', map {_elt_subtext_with_tags($_)} $elt->children)
1158 . $elt->end_tag);
1159 }
1160  
1161 # $elt contains xhtml <div> etc sub-elements. Return a plain html string.
1162 # Prefixes like <xhtml:b>Bold</xhtml:b> are turned into plain <b>.
1163 # This relies on the map_xmlns mapping to give prefix "xhtml:"
1164 #
1165 0 ▶sub elt_xhtml_to_html {
Subroutine elt_xhtml_to_html: not called CC=4 SCAR=30.0
Pod undocumented
1166 0 my ($elt) = @_;
1167  
1168 # could probably do it destructively, but just in case
1169 0 $elt = $elt->copy;
1170 0 App::RSS2Leafnode::XML::Twig::Other::elt_tree_strip_prefix ($elt, 'xhtml');
1171  
1172 # lose xmlns:xhtml="http://www.w3.org/1999/xhtml"
1173 0 $elt->strip_att('xmlns:xhtml');
1174  
1175 # something fishy turns "href" to "xhtml:href", drop any "xhtml:"
1176 # bare "href" also gets turned into atom:href as the default namespace,
1177 # drop any "atom:"
1178 0 foreach my $child ($elt->descendants) {
1179 0 foreach my $attname ($child->att_names) {
1180 0 ▶ if ($attname =~ /^(xhtml|atom):(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attname =~ /^(xhtml|atom):(.*)/) 0 0 0
1181 0 $child->change_att_name($attname, $2);
1182 }
1183 }
1184 }
1185  
1186 0 my $old_pretty = $elt->set_pretty_print ('none');
1187 ### $old_pretty
1188 0 my $ret = $elt->xml_string;
1189 0 $elt->set_pretty_print ($old_pretty);
1190 0 return $ret;
1191  
1192 }
1193  
1194 # elt_content_type() returns 'text', 'html', 'xhtml' or a mime type.
1195 # If no type="" attribute the default is 'text', except for RSS
1196 # <description> which is 'html'.
1197 #
1198 # RSS http://www.debian.org/News/weekly/dwn.en.rdf circa Feb 2010 had some
1199 # html in its <title>, but believe that's an error (mozilla shows it as
1200 # plain text) and that RSS is all plain text outside <description>.
1201 #
1202 # <dc:type>text</dc:type> probably refers only to the nature of the item,
1203 # not the formatting as html vs text.
1204 #
1205 2 @known{'/channel/item/dc:type'} = undef;
1206 #
1207 0 ▶sub elt_content_type {
Subroutine elt_content_type: not called CC=9 SCAR=45.0
Pod undocumented
1208 0 my ($elt) = @_;
1209 0 ▶ if (! defined $elt) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $elt) 0 0 0
1210  
1211 0 ▶ if (defined (my $type = ($elt->att('atom:type') // $elt->att('type')))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $type = $elt->att("atom:type") // $elt->att("type"))) 0 0 0
Condition0%0/3
$elt->att("atom:type") // $elt->att("type")
l!l&&r!l&&!r
000
MC/DC0%0/2
$elt->att("atom:type") // $elt->att("type")
$elt->att("atom:type") $elt->att("type")
Truth table0%0/3
A // B
A= $elt->att("atom:type")B= $elt->att("type")
ABresult
1X1
011
000
1212 # type="application/xhtml+xml" at http://xmltwig.com/blog/index.atom,
1213 # dunno if it should be just "xhtml", but recognise it anyway
1214 0 ▶ if ($type eq 'application/xhtml+xml') { return 'xhtml'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "application/xhtml+xml") 0 0 0
1215 0 return $type;
1216 }
1217 0 ▶ if ($elt->root->tag eq 'feed') {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->root->tag eq "feed") 0 0 0
1218 0 return 'text'; # Atom <feed> defaults to text
1219 }
1220 0 my $tag = $elt->tag;
1221 0 ▶ if ($tag =~ /^itunes:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^itunes:/) 0 0 0
1222 # itunes spec is for text-only, no html markup
1223 0 return 'text';
1224 }
1225 0 ▶ if ($tag eq 'description' # RSS <description> is encoded html
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "description" or $tag eq "content:encoded") 0 0 0
Condition0%0/3
$tag eq "description" or $tag eq "content:encoded"
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag eq "description" or $tag eq "content:encoded"
$tag eq "description" $tag eq "content:encoded"
Truth table0%0/3
A or B
A= $tag eq "description"B= $tag eq "content:encoded"
ABresult
1X1
011
000
1226 || $tag eq 'content:encoded') { # same in content:encoded
1227 0 return 'html';
1228 }
1229 # other RSS is text
1230 0 return 'text';
1231 }
1232  
1233 # $elt is an XML::Twig::Elt of an RSS or Atom text element.
1234 # Atom has a type="" attribute, RSS is html. Html or xhtml are rendered to
1235 # a single long line of plain text.
1236 #
1237 0 ▶sub elt_to_rendered_line {
Subroutine elt_to_rendered_line: not called CC=4 SCAR=30.0
Pod undocumented
1238 0 my ($elt) = @_;
1239 0 ▶ defined $elt or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $elt or return 0 0 0
1240  
1241 0 my $str;
1242 0 my $type = elt_content_type ($elt);
1243 0 ▶ if ($type eq 'xhtml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'xhtml') { } 0 0 0
1244 0 $str = elt_xhtml_to_html ($elt);
1245 0 $type = 'html';
1246 } else {
1247 0 $str = elt_subtext($elt);
1248 }
1249 0 ▶ if ($type eq 'html') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "html") 0 0 0
1250 0 $str = html_to_rendered_line($str);
1251 }
1252 # plain 'text' or anything unrecognised collapsed too
1253 0 return non_empty(collapse_whitespace($str));
1254 }
1255  
1256 0 ▶sub html_to_rendered_line {
Subroutine html_to_rendered_line: not called CC=1 SCAR=6.9
Pod undocumented
1257 0 my ($html) = @_;
1258 0 require HTML::FormatText;
1259 0 return collapse_whitespace
1260 (HTML::FormatText->format_string ($html,
1261 leftmargin => 0,
1262 rightmargin => 999));
1263 }
1264  
1265  
1266 #------------------------------------------------------------------------------
1267 # XML::RSS::Timing
1268  
1269 0 ▶sub twig_to_timingfields {
Subroutine twig_to_timingfields: not called CC=10 SCAR=47.0
Pod undocumented
1270 0 my ($self, $twig) = @_;
1271 0 ▶ return if ! defined $twig;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $twig 0 0 0
1272 0 my $root = $twig->root;
1273 0 my %timingfields;
1274  
1275 0 ▶ if (my $ttl = $root->first_descendant('ttl')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ttl = $root->first_descendant("ttl")) 0 0 0
1276 0 $timingfields{'ttl'} = $ttl->trimmed_text;
1277 }
1278 0 ▶ if (my $skipHours = $root->first_descendant('skipHours')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $skipHours = $root->first_descendant("skipHours")) 0 0 0
1279 0 $timingfields{'skipHours'} = [map {$_->trimmed_text} $skipHours->children('hour')];
1280 }
1281 0 ▶ if (my $skipDays = $root->first_descendant('skipDays')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $skipDays = $root->first_descendant("skipDays")) 0 0 0
1282 0 $timingfields{'skipDays'} = [map {$_->trimmed_text} $skipDays->children('day')];
1283 }
1284  
1285 # "syn:updatePeriod" etc
1286 0 foreach my $key (qw(updatePeriod updateFrequency updateBase)) {
1287 0 ▶ if (my $update = $root->first_descendant("syn:$key")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $update = $root->first_descendant("syn:$key")) 0 0 0
1288 0 $timingfields{$key} = $update->trimmed_text;
1289 }
1290 }
1291 0 ▶ if ($self->{'verbose'} >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} >= 2) 0 0 0
1292 0 require Data::Dumper;
1293 0 $self->verbose (2,
1294 Data::Dumper->new([\%timingfields],['timingfields'])
1295 ->Indent(1)->Sortkeys(1)->Dump);
1296 }
1297 0 ▶ if (! %timingfields) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%timingfields) 0 0 0
1298 0 return; # no info
1299 }
1300  
1301 # if XML::RSS::Timing doesn't like the values then don't record them
1302 0 ▶ return unless $self->timingfields_to_timing(\%timingfields);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->timingfields_to_timing(\%timingfields) 0 0 0
1303  
1304 0 return \%timingfields;
1305 }
1306 2 @known{qw(/channel/skipDays
1307 /channel/skipDays/day
1308 /channel/skipHours
1309 /channel/skipHours/hour
1310 /channel/ttl
1311 /channel/syn:updateBase
1312 /channel/syn:updatePeriod
1313 /channel/syn:updateFrequency)} = ();
1314  
1315 # return an XML::RSS::Timing object, or undef
1316 0 ▶sub timingfields_to_timing {
Subroutine timingfields_to_timing: not called CC=7 SCAR=40.3
Pod undocumented
1317 0 my ($self, $timingfields) = @_;
1318 0 ▶ $timingfields // return undef;
Condition0%0/2
$timingfields // (return undef)
l!l
00
MC/DC0%0/1
$timingfields // (return undef)
$timingfields
Truth table0%0/2
A
A= $timingfields
Aresult
11
00
1319  
1320 0 ▶ eval { require XML::RSS::Timing } || return undef;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require XML::RSS::Timing } } or return undef 0 0 0
1321 0 my $timing = XML::RSS::Timing->new;
1322 0 $timing->use_exceptions(0);
1323 0 ▶ while (my ($key, $value) = each %$timingfields) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$timingfields) 0 0 0
1324 0 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 0 0 0
1325 0 $timing->$key (@$value);
1326 } else {
1327 0 $timing->$key ($value);
1328 }
1329 }
1330 0 ▶ if (my @complaints = $timing->complaints) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@complaints) = $timing->complaints) 0 0 0
1331 say __x('XML::RSS::Timing complains about {url}',
1332 0 url => $self->{'uri'});
1333 0 foreach my $complaint (@complaints) {
1334 0 say " $complaint";
1335 }
1336 0 return undef;
1337 }
1338 0 return $timing;
1339 }
1340  
1341  
1342 #------------------------------------------------------------------------------
1343 # rss2leafnode.status file
1344  
1345 # $self->{'global_status'} is a hashref containing entries URL => STATUS,
1346 # where URL is a string and STATUS is a sub-hashref of information
1347  
1348 2 ▶use constant STATUS_EXPIRE_DAYS => 45;
Subroutine BEGIN: called CC=1 SCAR=0.0
1349  
1350 # read $status_filename into $self->{'global_status'}
1351 0 ▶sub status_read {
Subroutine status_read: not called CC=3 SCAR=24.8
Pod undocumented
1352 0 my ($self) = @_;
1353 0 $self->{'global_status'} = {};
1354 0 my $status_filename = $self->status_filename;
1355 0 $self->verbose (2, 'read status: ', $status_filename);
1356  
1357 0 $! = 0;
1358 0 my $global_status = do $status_filename;
1359 0 ▶ if (! defined $global_status) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $global_status) 0 0 0
1360 0 ▶ if ($! == POSIX::ENOENT()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! == 2) { } 0 0 0
1361 0 $self->verbose (2, "status file doesn't exist");
1362 } else {
1363 0 say "rss2leafnode: error in $status_filename\n$@";
1364 0 say "ignoring that file";
1365 }
1366 0 $global_status = {};
1367 }
1368 0 $self->{'global_status'} = $global_status;
1369 }
1370  
1371 # delete old entries from $self->{'global_status'}
1372 0 ▶sub status_prune {
Subroutine status_prune: not called CC=5 SCAR=34.0
Pod undocumented
1373 0 my ($self) = @_;
1374 0 ▶ my $global_status = $self->{'global_status'} // return;
Condition0%0/2
$self->{"global_status"} // (return)
l!l
00
MC/DC0%0/1
$self->{"global_status"} // (return)
$self->{"global_status"}
Truth table0%0/2
A
A= $self->{"global_status"}
Aresult
11
00
1375 0 my $pruned = 0;
1376 0 my $old_time = time() - STATUS_EXPIRE_DAYS * 86400;
1377 0 foreach my $key (keys %$global_status) {
1378 0 ▶ if ($global_status->{$key}->{'status-time'} < $old_time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($global_status->{$key}{"status-time"} < $old_time) 0 0 0
1379 0 $self->verbose (2, __x("discard old status {url}\n", url => $key));
1380 0 delete $global_status->{$key};
1381 0 $pruned++;
1382 }
1383 }
1384 0 ▶ if ($pruned) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pruned) 0 0 0
1385 0 $self->verbose (1, __xn("discard {count} old status entry\n",
1386 "discard {count} old status entries\n",
1387 $pruned,
1388 count => $pruned));
1389 }
1390 }
1391  
1392 # save $self->{'global_status'} into the $status_filename
1393 0 ▶sub status_save {
Subroutine status_save: not called CC=5 SCAR=34.0
Pod undocumented
1394 0 my ($self, $status) = @_;
1395 0 $status->{'status-time'} = time();
1396 0 ▶ if ($status->{'timingfields'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status->{"timingfields"}) 0 0 0
1397 0 $status->{'timingfields'}->{'lastPolled'} = $status->{'status-time'};
1398 }
1399  
1400 0 $self->status_prune;
1401  
1402 0 require Data::Dumper;
1403 0 my $str = Data::Dumper->new([$self->{'global_status'}],['global_status'])
1404 ->Indent(1)->Sortkeys(1)->Terse(1)->Useqq(1)->Dump;
1405 0 $str = <<"HERE";
1406 # rss2leafnode status file -- automatically generated -- DO NOT EDIT
1407 #
1408 # (If there seems to be something very wrong then you can delete this file
1409 # and it'll be started afresh on the next run.)
1410  
1411 $str
1412  
1413  
1414 # Local variables:
1415 # mode: perl-mode
1416 # End:
1417 HERE
1418  
1419 0 my $status_filename = $self->status_filename;
1420 0 my $out;
1421 0 ▶ (open $out, '>', $status_filename
Branch: 1 branch
BranchTrueFalseTotal
open $out, ">", $status_filename and print $out $str and close $out or croak("rss2leafnode: cannot write to ${status_filename}: $!\n") 0 0 0
Condition0%0/6
open $out, ">", $status_filename and print $out $str and close $out
!ll&&!rl&&r
000
open $out, ">", $status_filename and print $out $str
!ll&&!rl&&r
000
MC/DC0%0/3
open $out, ">", $status_filename and print $out $str and close $out
open $out, ">", $status_filename print $out $str close $out
Truth table0%0/4
A and B and C
A= open $out, ">", $status_filenameB= print $out $strC= close $out
ABCresult
0XX0
10X0
1100
1111
1422 and print $out $str
1423 and close $out)
1424 or croak "rss2leafnode: cannot write to $status_filename: $!\n";
1425 }
1426  
1427 # return a hashref which has status information about $url, or undef if
1428 # nothing recorded about $url
1429 0 ▶sub status_geturl {
Subroutine status_geturl: not called CC=3 SCAR=24.8
Pod undocumented
1430 0 my ($self, $url) = @_;
1431 0 ▶ $self->status_read if ! $self->{'global_status'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"global_status"} 0 0 0
1432 0 ▶ if (! $self->{'global_status'}->{$url}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"global_status"}{$url}) 0 0 0
1433 0 $self->{'global_status'}->{$url} = { 'status-time' => time() };
1434 }
1435 0 return $self->{'global_status'}->{$url};
1436 }
1437  
1438 # $resp is a HTTP::Response object from retrieving $url.
1439 # Optional $twig is an XML::Twig.
1440 # Record against $url any ETag, Last-Modified and ttl from $resp and $twig.
1441 # If $resp is an error return, or is undef, then do nothing.
1442 0 ▶sub status_etagmod_resp {
Subroutine status_etagmod_resp: not called CC=9 SCAR=45.0
Pod undocumented
1443 0 my ($self, $url, $resp, $twig) = @_;
1444 0 ▶ if ($resp && $resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp and $resp->is_success) 0 0 0
Condition0%0/3
$resp and $resp->is_success
!ll&&!rl&&r
000
MC/DC0%0/2
$resp and $resp->is_success
$resp $resp->is_success
Truth table0%0/3
A and B
A= $respB= $resp->is_success
ABresult
0X0
100
111
1445 0 my $status = $self->status_geturl ($url);
1446 0 $status->{'Last-Modified'} = $resp->header('Last-Modified');
1447 0 $status->{'ETag'} = $resp->header('ETag');
1448 0 $status->{'timingfields'} = $self->twig_to_timingfields ($twig);
1449  
1450 0 ▶ if (! defined $status->{'ETag'} && ! defined $status->{'Last-Modified'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $status->{"ETag"} or defined $status->{"Last-Modified"}) 0 0 0
Condition0%0/3
defined $status->{"ETag"} or defined $status->{"Last-Modified"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $status->{"ETag"} or defined $status->{"Last-Modified"}
defined $status->{"ETag"} defined $status->{"Last-Modified"}
Truth table0%0/3
A or B
A= defined $status->{"ETag"}B= defined $status->{"Last-Modified"}
ABresult
1X1
011
000
1451 0 $self->verbose (1, " no ETag or Last-Modified");
1452 }
1453 0 ▶ if (defined (my $comments_count = $self->{'comments_count'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $comments_count = $self->{"comments_count"})) 0 0 0
1454 0 $status->{'comments_count'} = $comments_count;
1455 }
1456  
1457 0 ▶ if ($twig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($twig) 0 0 0
1458 # record previously applied newest option
1459 0 $status->{'rss_newest_only'} = $self->{'rss_newest_only'};
1460
1461 # if (rss_newest_cmp($self,$status) > 0) {
1462 # # the newest number increases
1463 # }
1464 }
1465 0 foreach my $key (keys %$status) {
1466 0 ▶ if (! defined $status->{$key}) { delete $status->{$key} }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $status->{$key}) 0 0 0
1467 }
1468 0 $self->status_save($status);
1469 }
1470 }
1471  
1472 # update recorded status for a $url with unchanged contents
1473 0 ▶sub status_unchanged {
Subroutine status_unchanged: not called CC=1 SCAR=6.9
Pod undocumented
1474 0 my ($self, $url) = @_;
1475 0 $self->verbose (1, ' ', __('unchanged'));
1476 0 $self->status_save ($self->status_geturl ($url));
1477 }
1478  
1479 # $req is a HTTP::Request object.
1480 # Add "If-None-Match" and/or "If-Modified-Since" headers to it based on what
1481 # the status file has recorded from when we last fetched the url in $req.
1482 # Return 1 to download, 0 if nothing expected yet by RSS timing fields
1483 #
1484 0 ▶sub status_etagmod_req {
Subroutine status_etagmod_req: not called CC=11 SCAR=48.8
Pod undocumented
1485 0 my ($self, $req, $for_rss) = @_;
1486 0 ▶ $self->{'global_status'} or $self->status_read;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"global_status"} or $self->status_read 0 0 0
1487  
1488 0 my $url = $req->uri->as_string;
1489 my $status = $self->{'global_status'}->{$url}
1490 0 ▶ // do {
Condition0%0/3
$self->{"global_status"}{$url} // do { $self->verbose(2, &__x("no status info for {url}\n", "url", $url)); return 1 }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"global_status"}{$url} // do { $self->verbose(2, &__x("no status info for {url}\n", "url", $url)); return 1 }
$self->{"global_status"}{$url} do { $self->verbose(2, &__x("no status info for {url}\n", "url", $url)); return 1 }
Truth table0%0/3
A // B
A= $self->{"global_status"}{$url}B= do { $self->verbose(2, &__x("no status info for {url}\n", "url", $url)); return 1 }
ABresult
1X1
011
000
1491 0 $self->verbose (2, __x("no status info for {url}\n", url => $url));
1492 0 return 1; # want download
1493 };
1494  
1495 0 ▶ if ($for_rss) {
Branch: 1 branch
BranchTrueFalseTotal
if ($for_rss) 0 0 0
1496 # if status says the last download was for only a certain number of
1497 # newest, then force a re-download if that option now different
1498 0 ▶ if (! str_equal($self->{'rss_newest_only'},
Branch: 1 branch
BranchTrueFalseTotal
unless (str_equal($self->{"rss_newest_only"}, $status->{"rss_newest_only"})) 0 0 0
1499 $status->{'rss_newest_only'})) {
1500 0 return 1; # want download
1501 }
1502 }
1503  
1504 0 ▶ if (my $timing = $self->timingfields_to_timing ($status->{'timingfields'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $timing = $self->timingfields_to_timing($status->{"timingfields"})) 0 0 0
1505 0 my $next = $timing->nextUpdate;
1506 0 my $now = time();
1507 0 ▶ if ($next > $now) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next > $now) 0 0 0
1508 0 $self->verbose (1, ' ',
1509 __x('timing: next update {time} (local time)',
1510 time => POSIX::strftime ("%H:%M:%S %a %d %b %Y",
1511 localtime($next))));
1512 0 ▶ if (eval 'use Time::Duration::Locale; 1'
Branch: 1 branch
BranchTrueFalseTotal
if (eval "use Time::Duration::Locale; 1" or eval "use Time::Duration; 1") 0 0 0
Condition0%0/3
eval "use Time::Duration::Locale; 1" or eval "use Time::Duration; 1"
l!l&&r!l&&!r
000
MC/DC0%0/2
eval "use Time::Duration::Locale; 1" or eval "use Time::Duration; 1"
eval "use Time::Duration::Locale; 1" eval "use Time::Duration; 1"
Truth table0%0/3
A or B
A= eval "use Time::Duration::Locale; 1"B= eval "use Time::Duration; 1"
ABresult
1X1
011
000
1513 || eval 'use Time::Duration; 1') {
1514 0 $self->verbose (1, ' ', __x('which is {duration} from now',
1515 duration => duration($next-$now)));
1516 }
1517 0 return 0; # no update yet
1518 }
1519 }
1520 0 ▶ if (defined (my $lastmod = $status->{'Last-Modified'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $lastmod = $status->{"Last-Modified"})) 0 0 0
1521 0 $req->header('If-Modified-Since' => $lastmod);
1522 }
1523 0 ▶ if (defined (my $etag = $status->{'ETag'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $etag = $status->{"ETag"})) 0 0 0
1524 0 $req->header('If-None-Match' => $etag);
1525 }
1526 0 return 1;
1527 }
1528  
1529 # return -1 if x<y, 0 if x==y, or 1 if x>1
1530 # sub rss_newest_cmp {
1531 # my ($x, $y) = @_;
1532 # if ($x->{'rss_newest_only'}) {
1533 # if (! $y->{'rss_newest_only'}) {
1534 # return -1; # x finite, y infinite
1535 # }
1536 # # x and y finite
1537 # return ($x->{'rss_newest_only'} <=> $y->{'rss_newest_only'});
1538 # } else {
1539 # # x infinite, so 1 if y finite, 0 if y infinite too
1540 # return !! $y->{'rss_newest_only'};
1541 # }
1542 # }
1543 0 ▶sub str_equal {
Subroutine str_equal: not called CC=5 SCAR=34.0
Pod undocumented
1544 0 my ($x, $y) = @_;
1545 0 ▶ return ((defined $x && defined $y && $x eq $y)
Condition0%0/12
defined $x && defined $y && $x eq $y || !(defined $x || defined $y)
l!l&&r!l&&!r
000
defined $x and defined $y and $x eq $y
!ll&&!rl&&r
000
defined $x and defined $y
!ll&&!rl&&r
000
defined $x || defined $y
l!l&&r!l&&!r
000
MC/DC0%0/5
defined $x && defined $y && $x eq $y || !(defined $x || defined $y)
defined $x defined $y $x eq $y defined $x defined $y
Truth table0%0/10
A and B and C || not(D || E)
A= defined $xB= defined $yC= $x eq $yD= defined $xE= defined $y
ABCDEresult
111XX1
0XX001
10X001
110001
0XX1X0
0XX010
10X1X0
10X010
1101X0
110010
1546 || (! defined $x && ! defined $y));
1547 }
1548  
1549 #------------------------------------------------------------------------------
1550 # render html
1551  
1552 # $content_type is a string like "text/html" or "text/plain".
1553 # $content is data as raw bytes.
1554 # $charset is the character set of those bytes, eg. "utf-8".
1555 #
1556 # If the $render option is set, and $content_type is 'text/html', then
1557 # render $content down to 'text/plain', using either HTML::FormatText or
1558 # Lynx.
1559 # The return is a new triplet ($content, $content_type, $charset).
1560 #
1561 0 ▶sub render_maybe {
Subroutine render_maybe: not called CC=5 SCAR=34.0
Pod undocumented
1562 0 my ($self, $content, $content_type, $charset, $base_url) = @_;
1563 0 my $rendered = 0;
1564 0 ▶ if ($self->{'render'} && $content_type eq 'text/html') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"render"} and $content_type eq "text/html") 0 0 0
Condition0%0/3
$self->{"render"} and $content_type eq "text/html"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"render"} and $content_type eq "text/html"
$self->{"render"} $content_type eq "text/html"
Truth table0%0/3
A and B
A= $self->{"render"}B= $content_type eq "text/html"
ABresult
0X0
100
111
1565  
1566 0 my $class = $self->{'render'};
1567 0 ▶ if ($class !~ /^HTML::/) { $class = "HTML::FormatText::\u$class"; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /^HTML::/) 0 0 0
1568 0 $class =~ s/::1$//; # "::1" is $render=1 for plain HTML::FormatText
1569 0 require Module::Load;
1570 0 Module::Load::load ($class);
1571  
1572 # decode() can error out on bad charset.
1573 0 ▶ unless (eval { $content = Encode::decode ($charset, $content); 1; }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $content = &Encode::decode($charset, $content); 1 } }) 0 0 0
1574 0 print __x(" oops, cannot decode {charset}: {error}\n",
1575 charset => $charset,
1576 error => $@);
1577 }
1578  
1579 # HTML::FormatText (as of version 2.04) doesn't do anything about input
1580 # or output charsets but putting wide chars through gives reasonable
1581 # results. Likewise HTML::FormatText::WithLinks (as of its version
1582 # 0.11). The HTML::FormatExternal modules version 23 up have wide char
1583 # input and output.
1584 {
1585 0 local $SIG{'__WARN__'} = \&_warn_suppress_unknown_configure_option;
1586 $content = $class->format_string
1587 ($content,
1588 base => $base_url,
1589 doc_overrides_base => 1, # for HTML::FormatText::WithLinks
1590 leftmargin => 0,
1591 0 rightmargin => $self->{'render_width'});
1592 }
1593 # $content is wide chars, go to utf-8 bytes
1594  
1595 0 $content = Encode::encode_utf8 ($content);
1596 0 $charset = 'UTF-8';
1597 0 $content_type = 'text/plain';
1598 0 $rendered = 1;
1599 }
1600 0 return ($content, $content_type, $charset, $rendered);
1601 }
1602 # HTML::FormatText emits "Unknown configure option" for an option key it
1603 # doesn't know. Would probably prefer it to quietly ignore.
1604 0 ▶sub _warn_suppress_unknown_configure_option {
Subroutine _warn_suppress_unknown_configure_option: not called CC=2 SCAR=17.9
1605 0 my ($msg) = @_;
1606 0 ▶ $msg =~ /^Unknown configure option/
Branch: 1 branch
BranchTrueFalseTotal
$msg =~ /^Unknown configure option/ or warn $msg 0 0 0
1607 or warn $msg;
1608 }
1609  
1610 # $str is a wide-char string of text
1611 0 ▶sub text_wrap {
Subroutine text_wrap: not called CC=3 SCAR=24.8
Pod undocumented
1612 0 my ($self, $str, $prefix) = @_;
1613 0 ▶ if (! defined $prefix) { $prefix = ''; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $prefix) 0 0 0
1614 0 require Text::WrapI18N;
1615 0 local $Text::WrapI18N::columns = $self->{'render_width'} + 1;
1616 0 local $Text::WrapI18N::unexpand = 0; # no tabs in output
1617 0 local $Text::WrapI18N::huge = 'overflow'; # don't break long words
1618 0 $str =~ tr/\n/ /;
1619 0 ▶ my $second_prefix = (length($prefix) ? ' 'x(length($prefix)+2) : '');
Branch: 1 branch
BranchTrueFalseTotal
length $prefix ? : 0 0 0
1620 0 return Text::WrapI18N::wrap($prefix, $second_prefix, $str);
1621 }
1622  
1623 #------------------------------------------------------------------------------
1624 # Face icons
1625  
1626 # $item is an XML::Twig::Elt of an RSS or Atom item
1627 # return a string value for the Face: header, or undef if no icon
1628 0 ▶sub item_to_face {
Subroutine item_to_face: not called CC=4 SCAR=30.0
Pod undocumented
1629 0 my ($self, $item) = @_;
1630 0 ▶ $self->{'get_icon'} || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"get_icon"} or return 0 0 0
1631 0 ▶ my ($uri, $width, $height) = $self->item_image_uwh ($item)
Branch: 1 branch
BranchTrueFalseTotal
() = $self->item_image_uwh($item) or return 0 0 0
1632 or return;
1633 0 ▶ $self->face_wh_ok ($width, $height) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->face_wh_ok($width, $height) or return 0 0 0
1634 0 return $self->download_face ($uri, $width, $height);
1635 }
1636  
1637 # $item is an XML::Twig::Elt of an RSS or Atom item
1638 # return values ($uri, $width, $height) of the <image> etc from it
1639 #
1640 0 ▶sub item_image_uwh {
Subroutine item_image_uwh: not called CC=49 SCAR=78.0
Pod undocumented
1641 0 my ($self, $item) = @_;
1642 ### item_image_uwh() ...
1643  
1644 0 foreach my $where ($item,
1645 elt_to_channel($item)) {
1646 ### image text: $where->first_child_text('image')
1647  
1648 # identi.ca
1649 0 ▶ if (my $actor = $where->first_child('activity:actor')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $actor = $where->first_child("activity:actor")) 0 0 0
1650 0 my ($url, $width, $height);
1651 0 foreach my $link_elt ($actor->children('link')) {
1652 0 ▶ ($link_elt->att('rel')||$link_elt->att('atom:rel')||'')
Branch: 1 branch
BranchTrueFalseTotal
($link_elt->att("rel") || $link_elt->att("atom:rel") || "") eq "avatar" or next 0 0 0
Condition0%0/5
$link_elt->att('rel') || $link_elt->att('atom:rel') || ''
l!l
00
$link_elt->att("rel") or $link_elt->att("atom:rel")
l!l&&r!l&&!r
000
MC/DC0%0/2
$link_elt->att('rel') || $link_elt->att('atom:rel') || ''
$link_elt->att("rel") $link_elt->att("atom:rel")
Truth table0%0/3
A or B
A= $link_elt->att("rel")B= $link_elt->att("atom:rel")
ABresult
1X1
011
000
1653 eq 'avatar' or next;
1654 0 ▶ $url = $link_elt->att('href') // $link_elt->att('atom:href') // next;
Condition0%0/5
($link_elt->att("href") // $link_elt->att("atom:href")) // (next)
l!l
00
$link_elt->att("href") // $link_elt->att("atom:href")
l!l&&r!l&&!r
000
MC/DC0%0/2
($link_elt->att("href") // $link_elt->att("atom:href")) // (next)
$link_elt->att("href") $link_elt->att("atom:href")
Truth table0%0/3
A // B
A= $link_elt->att("href")B= $link_elt->att("atom:href")
ABresult
1X1
011
000
1655 0 my $this_width = $link_elt->att('media:width');
1656 0 ▶ next if (defined $width
Branch: 1 branch
BranchTrueFalseTotal
if defined $width and defined $this_width and $width < $this_width 0 0 0
Condition0%0/6
defined $width and defined $this_width and $width < $this_width
!ll&&!rl&&r
000
defined $width and defined $this_width
!ll&&!rl&&r
000
MC/DC0%0/3
defined $width and defined $this_width and $width < $this_width
defined $width defined $this_width $width < $this_width
Truth table0%0/4
A and B and C
A= defined $widthB= defined $this_widthC= $width < $this_width
ABCresult
0XX0
10X0
1100
1111
1657 && defined $this_width
1658 && $width < $this_width); # prefer smallest
1659 0 $url = App::RSS2Leafnode::XML::Twig::Other::elt_xml_based_uri ($link_elt, $url);
1660 0 ▶ $width = ($this_width || 0);
Condition0%0/2
$this_width || 0
l!l
00
MC/DC0%0/1
$this_width || 0
$this_width
Truth table0%0/2
A
A= $this_width
Aresult
11
00
1661 0 ▶ $height = ($link_elt->att('media:height') || 0);
Condition0%0/2
$link_elt->att('media:height') || 0
l!l
00
MC/DC0%0/1
$link_elt->att('media:height') || 0
$link_elt->att('media:height')
Truth table0%0/2
A
A= $link_elt->att('media:height')
Aresult
11
00
1662 ### $url
1663 ### $width
1664 ### $height
1665 }
1666 0 ▶ if (defined $url) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url) 0 0 0
1667 0 return ($url, $width, $height);
1668 }
1669 }
1670  
1671 # RSS
1672 # <image>
1673 # <url>foo.png</url>
1674 # <width>...</width> optional
1675 # <height>...</height> optional
1676 # </image>
1677 0 ▶ if (my $image_elt = $where->first_child('image')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $image_elt = $where->first_child("image")) 0 0 0
1678 0 my $url_elt; # XML::Twig::Elt where the url came from
1679 my $url; # url string
1680 0 ▶ if ($url_elt = $image_elt->first_child('url')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url_elt = $image_elt->first_child('url')) { } 0 0 0
1681 0 $url = $url_elt->trimmed_text;
1682 } else {
1683 # Cooper Hewitt museum http://blog.cooperhewitt.org/rss/?limit=10
1684 # item <image> as html text like
1685 # <image>
1686 # <![CDATA[<img src="http://blog.cooperhewitt.org/images/277t.jpg" alt="" />]]>
1687 # </image>
1688 # don't want to encourage dodginess like this, but picking it out
1689 # isn't too hard
1690 0 ▶ if ($image_elt->text =~ /<img[^>]*\ssrc="([^"]*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($image_elt->text =~ /<img[^>]*\ssrc="([^"]*)/) 0 0 0
1691 ### image from html: $1
1692 0 $url_elt = $image_elt;
1693 0 $url = $1;
1694 }
1695 }
1696 0 ▶ if (is_non_empty ($url)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty($url)) 0 0 0
1697 0 my $width = $image_elt->first_child_text('width');
1698 0 ▶ unless (Scalar::Util::looks_like_number($width) && $width > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Scalar::Util::looks_like_number($width) and $width > 0) 0 0 0
Condition0%0/3
&Scalar::Util::looks_like_number($width) and $width > 0
!ll&&!rl&&r
000
MC/DC0%0/2
&Scalar::Util::looks_like_number($width) and $width > 0
&Scalar::Util::looks_like_number($width) $width > 0
Truth table0%0/3
A and B
A= &Scalar::Util::looks_like_number($width)B= $width > 0
ABresult
0X0
100
111
1699 0 $width = 0;
1700 }
1701 0 my $height = $image_elt->first_child_text('height');
1702 0 ▶ unless (Scalar::Util::looks_like_number($height) && $height > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Scalar::Util::looks_like_number($height) and $height > 0) 0 0 0
Condition0%0/3
&Scalar::Util::looks_like_number($height) and $height > 0
!ll&&!rl&&r
000
MC/DC0%0/2
&Scalar::Util::looks_like_number($height) and $height > 0
&Scalar::Util::looks_like_number($height) $height > 0
Truth table0%0/3
A and B
A= &Scalar::Util::looks_like_number($height)B= $height > 0
ABresult
0X0
100
111
1703 0 $height = 0;
1704 }
1705 ### item_image_uwh() RSS: $url
1706 0 return (App::RSS2Leafnode::XML::Twig::Other::elt_xml_based_uri ($url_elt, $url),
1707 $width, $height);
1708 }
1709 }
1710  
1711 # Atom channel <icon>foo.png</icon> should be square
1712 # or channel <logo>foo.png</logo> bigger form, rectangle 2*K x K
1713 #
1714 # <itunes:image href="http://..."> in item or channel. Supposedly this
1715 # is bigger than the RSS 48x48, so would probably need shrinking. Rate
1716 # it below <icon> or <logo> for that reason.
1717 #
1718 # <media:thumbnail href="" width="" height=""> snapshot of movie etc
1719 # Is it better to show the channel icon, being the From person?
1720 {
1721 0 my $elt;
1722 0 my ($width, $height);
1723 my $url = ((($elt = $where->first_child('icon'))
1724 && non_empty ($elt->text))
1725 || (($elt = $where->first_child('logo'))
1726 && non_empty ($elt->text))
1727 || (($elt = $where->first_child('itunes:image'))
1728 && non_empty ($elt->att('href')))
1729 || (($elt = $where->first_child('media:thumbnail'))
1730 && is_non_empty ($elt->att('url'))
1731 && do {
1732 0 $width = $elt->att('width');
1733 0 $height = $elt->att('height');
1734 0 ▶ $elt->att('url') })
Condition0%0/6
$elt = $where->first_child("media:thumbnail") and is_non_empty($elt->att("atom:url")) and do { $width = $elt->att("width"); $height = $elt->att("height"); $elt->att("atom:url") }
!ll&&!rl&&r
000
$elt = $where->first_child("media:thumbnail") and is_non_empty($elt->att("atom:url"))
!ll&&!rl&&r
000
MC/DC0%0/3
$elt = $where->first_child("media:thumbnail") and is_non_empty($elt->att("atom:url")) and do { $width = $elt->att("width"); $height = $elt->att("height"); $elt->att("atom:url") }
$elt = $where->first_child("media:thumbnail") is_non_empty($elt->att("atom:url")) do { $width = $elt->att("width"); $height = $elt->att("height"); $elt->att("atom:url") }
Truth table0%0/4
A and B and C
A= $elt = $where->first_child("media:thumbnail")B= is_non_empty($elt->att("atom:url"))C= do { $width = $elt->att("width"); $height = $elt->att("height"); $elt->att("atom:url") }
ABCresult
0XX0
10X0
1100
1111
1735 # seen att('atom:url' rather than plain 'url' ...
1736 || (($elt = $where->first_child('media:thumbnail'))
1737 && is_non_empty ($elt->att('atom:url'))
1738 0 ▶ && do {
Condition0%0/27
($elt = $where->first_child('icon')) && non_empty($elt->text) || ($elt = $where->first_child('logo')) && non_empty($elt->text) || ($elt = $where->first_child('itunes:image')) && non_empty($elt->att('href')) || ($elt = $where->first_child('media:thumbnail')) && is_non_empty($elt->att('url')) && do { $width = $elt->att('width'); $height = $elt->att('height'); $elt->att('url') } || ($elt = $where->first_child('media:thumbnail')) && is_non_empty($elt->att('atom:url')) && do { $width = $elt->att('width'); $height = $elt->att('height'); $elt->att('atom:url') }
l!l&&r!l&&!r
000
$elt = $where->first_child("icon") and non_empty($elt->text) or $elt = $where->first_child("logo") and non_empty($elt->text) or $elt = $where->first_child("itunes:image") and non_empty($elt->att("href")) or $elt = $where->first_child("media:thumbnail") and is_non_empty($elt->att("url")) and do { $width = $elt->att("width"); $height = $elt->att("height"); $elt->att("url") }
l!l&&r!l&&!r
000
$elt = $where->first_child("icon") and non_empty($elt->text) or $elt = $where->first_child("logo") and non_empty($elt->text) or $elt = $where->first_child("itunes:image") and non_empty($elt->att("href"))
l!l&&r!l&&!r
000
$elt = $where->first_child("icon") and non_empty($elt->text) or $elt = $where->first_child("logo") and non_empty($elt->text)
l!l&&r!l&&!r
000
$elt = $where->first_child("icon") and non_empty($elt->text)
!ll&&!rl&&r
000
$elt = $where->first_child("logo") and non_empty($elt->text)
!ll&&!rl&&r
000
$elt = $where->first_child("itunes:image") and non_empty($elt->att("href"))
!ll&&!rl&&r
000
$elt = $where->first_child("media:thumbnail") and is_non_empty($elt->att("url")) and do { $width = $elt->att("width"); $height = $elt->att("height"); $elt->att("url") }
!ll&&!rl&&r
000
$elt = $where->first_child("media:thumbnail") and is_non_empty($elt->att("url"))
!ll&&!rl&&r
000
MC/DC0%0/10
($elt = $where->first_child('icon')) && non_empty($elt->text) || ($elt = $where->first_child('logo')) && non_empty($elt->text) || ($elt = $where->first_child('itunes:image')) && non_empty($elt->att('href')) || ($elt = $where->first_child('media:thumbnail')) && is_non_empty($elt->att('url')) && do { $width = $elt->att('width'); $height = $elt->att('height'); $elt->att('url') } || ($elt = $where->first_child('media:thumbnail')) && is_non_empty($elt->att('atom:url')) && do { $width = $elt->att('width'); $height = $elt->att('height'); $elt->att('atom:url') }
$elt = $where->first_child("icon") non_empty($elt->text) $elt = $where->first_child("logo") non_empty($elt->text) $elt = $where->first_child("itunes:image") non_empty($elt->att("href")) $elt = $where->first_child("media:thumbnail") is_non_empty($elt->att("url")) do { $width = $elt->att("width"); $height = $elt->att("height"); $elt->att("url") } ($elt = $where->first_child('media:thumbnail')) && is_non_empty($elt->att('atom:url')) && do { $width = $elt->att('width'); $height = $elt->att('height'); $elt->att('atom:url') }
Truth table0%0/63
A and B or C and D or E and F or G and H and I || J
A= $elt = $where->first_child("icon")B= non_empty($elt->text)C= $elt = $where->first_child("logo")D= non_empty($elt->text)E= $elt = $where->first_child("itunes:image")F= non_empty($elt->att("href"))G= $elt = $where->first_child("media:thumbnail")H= is_non_empty($elt->att("url"))I= do { $width = $elt->att("width"); $height = $elt->att("height"); $elt->att("url") }J= ($elt = $where->first_child('media:thumbnail')) && is_non_empty($elt->att('atom:url')) && do { $width = $elt->att('width'); $height = $elt->att('height'); $elt->att('atom:url') }
ABCDEFGHIJresult
11XXXXXXXX1
0X11XXXXXX1
1011XXXXXX1
0X0X11XXXX1
0X1011XXXX1
100X11XXXX1
101011XXXX1
0X0X0X111X1
0X0X10111X1
0X100X111X1
0X1010111X1
100X0X111X1
100X10111X1
10100X111X1
101010111X1
0X0X0X0XX11
0X0X0X10X11
0X0X0X11011
0X0X100XX11
0X0X1010X11
0X0X1011011
0X100X0XX11
0X100X10X11
0X100X11011
0X10100XX11
0X101010X11
0X101011011
100X0X0XX11
100X0X10X11
100X0X11011
100X100XX11
100X1010X11
100X1011011
10100X0XX11
10100X10X11
10100X11011
1010100XX11
10101010X11
10101011011
0X0X0X0XX00
0X0X0X10X00
0X0X0X11000
0X0X100XX00
0X0X1010X00
0X0X1011000
0X100X0XX00
0X100X10X00
0X100X11000
0X10100XX00
0X101010X00
0X101011000
100X0X0XX00
100X0X10X00
100X0X11000
100X100XX00
100X1010X00
100X1011000
10100X0XX00
10100X10X00
10100X11000
1010100XX00
10101010X00
10101011000
1739 0 $width = $elt->att('width');
1740 0 $height = $elt->att('height');
1741 0 $elt->att('atom:url') }));
1742 ### $url
1743 0 ▶ if ($url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url) 0 0 0
1744 0 ▶ unless (Scalar::Util::looks_like_number($width) && $width > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Scalar::Util::looks_like_number($width) and $width > 0) 0 0 0
Condition0%0/3
&Scalar::Util::looks_like_number($width) and $width > 0
!ll&&!rl&&r
000
MC/DC0%0/2
&Scalar::Util::looks_like_number($width) and $width > 0
&Scalar::Util::looks_like_number($width) $width > 0
Truth table0%0/3
A and B
A= &Scalar::Util::looks_like_number($width)B= $width > 0
ABresult
0X0
100
111
1745 0 $width = 0;
1746 }
1747 0 ▶ unless (Scalar::Util::looks_like_number($height) && $height > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Scalar::Util::looks_like_number($height) and $height > 0) 0 0 0
Condition0%0/3
&Scalar::Util::looks_like_number($height) and $height > 0
!ll&&!rl&&r
000
MC/DC0%0/2
&Scalar::Util::looks_like_number($height) and $height > 0
&Scalar::Util::looks_like_number($height) $height > 0
Truth table0%0/3
A and B
A= &Scalar::Util::looks_like_number($height)B= $height > 0
ABresult
0X0
100
111
1748 0 $height = 0;
1749 }
1750 0 return (App::RSS2Leafnode::XML::Twig::Other::elt_xml_based_uri ($elt, $url),
1751 $width,
1752 $height);
1753 }
1754 }
1755  
1756 # status.net for rss 1.0
1757 # <statusnet:postIcon rdf:resource="http://avatar.identi.ca/..."></statusnet:postIcon>
1758 0 ▶ if (my $elt = $where->first_child('statusnet:postIcon')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $elt = $where->first_child("statusnet:postIcon")) 0 0 0
1759 0 ▶ if (is_non_empty (my $url = $elt->att('rdf:resource'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty(my $url = $elt->att("rdf:resource"))) 0 0 0
1760 0 return (App::RSS2Leafnode::XML::Twig::Other::elt_xml_based_uri ($elt, $url),
1761 0, 0); # unknown size
1762 }
1763 }
1764  
1765 # <author><gd:image ...>
1766 # eg. from blogger.com
1767 # <gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/>
1768 {
1769 0 my $elt;
1770 0 ▶ if (($elt = $where->first_child('author'))
Branch: 1 branch
BranchTrueFalseTotal
if ($elt = $where->first_child("author") and $elt = $elt->first_child("gd:image") and is_non_empty(my $url = $elt->att("src") // $elt->att("atom:src"))) 0 0 0
Condition0%0/9
$elt = $where->first_child("author") and $elt = $elt->first_child("gd:image") and is_non_empty(my $url = $elt->att("src") // $elt->att("atom:src"))
!ll&&!rl&&r
000
$elt = $where->first_child("author") and $elt = $elt->first_child("gd:image")
!ll&&!rl&&r
000
$elt->att("src") // $elt->att("atom:src")
l!l&&r!l&&!r
000
MC/DC0%0/3
$elt = $where->first_child("author") and $elt = $elt->first_child("gd:image") and is_non_empty(my $url = $elt->att("src") // $elt->att("atom:src"))
$elt = $where->first_child("author") $elt = $elt->first_child("gd:image") is_non_empty(my $url = $elt->att("src") // $elt->att("atom:src"))
MC/DC0%0/2
$elt->att("src") // $elt->att("atom:src")
$elt->att("src") $elt->att("atom:src")
Truth table0%0/4
A and B and C
A= $elt = $where->first_child("author")B= $elt = $elt->first_child("gd:image")C= is_non_empty(my $url = $elt->att("src") // $elt->att("atom:src"))
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A // B
A= $elt->att("src")B= $elt->att("atom:src")
ABresult
1X1
011
000
1771 && ($elt = $elt->first_child('gd:image'))
1772 && (is_non_empty (my $url = $elt->att('src') // $elt->att('atom:src')))) {
1773 ### $url
1774 0 ▶ return (App::RSS2Leafnode::XML::Twig::Other::elt_xml_based_uri ($elt, $url),
Condition0%0/10
$elt->att('width') || $elt->att('atom:width') || 0
l!l
00
$elt->att("width") or $elt->att("atom:width")
l!l&&r!l&&!r
000
$elt->att('height') || $elt->att('atom:height') || 0
l!l
00
$elt->att("height") or $elt->att("atom:height")
l!l&&r!l&&!r
000
MC/DC0%0/2
$elt->att('width') || $elt->att('atom:width') || 0
$elt->att("width") $elt->att("atom:width")
MC/DC0%0/2
$elt->att('height') || $elt->att('atom:height') || 0
$elt->att("height") $elt->att("atom:height")
Truth table0%0/3
A or B
A= $elt->att("width")B= $elt->att("atom:width")
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $elt->att("height")B= $elt->att("atom:height")
ABresult
1X1
011
000
1775 $elt->att('width') || $elt->att('atom:width') || 0,
1776 $elt->att('height') || $elt->att('atom:height') || 0);
1777 }
1778 }
1779 }
1780 0 return;
1781 }
1782 2 @known{qw(/channel/logo
1783 /channel/icon
1784 /channel/image
1785 /channel/image/url
1786 /channel/image/width
1787 /channel/image/height
1788 /channel/image/title
1789 /channel/image/link
1790 /channel/image/description
1791 /channel/itunes:image
1792 /channel/statusnet:postIcon
1793  
1794 /channel/item/image
1795 /channel/item/media:thumbnail
1796 /channel/item/statusnet:postIcon
1797 )} = ();
1798  
1799 # $resp is a HTTP::Response
1800 # return a string value for the Face: header, or undef if no icon
1801 0 ▶sub http_resp_to_face {
Subroutine http_resp_to_face: not called CC=3 SCAR=24.8
Pod undocumented
1802 0 my ($self, $resp) = @_;
1803 0 ▶ $self->{'get_icon'} || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"get_icon"} or return 0 0 0
1804  
1805 0 ▶ my $uri = http_resp_favicon_uri($resp) || return;
Condition0%0/2
http_resp_favicon_uri($resp) || (return)
l!l
00
MC/DC0%0/1
http_resp_favicon_uri($resp) || (return)
http_resp_favicon_uri($resp)
Truth table0%0/2
A
A= http_resp_favicon_uri($resp)
Aresult
11
00
1806 0 $self->verbose (2, ' response favicon URI: ', $uri);
1807 0 return $self->download_face ($uri, 0, 0);
1808 }
1809  
1810 # $resp is a HTTP::Response
1811 # if it's a html with a favicon link return a URI object of that image
1812 #
1813 # http://www.w3.org/2005/10/howto-favicon
1814 #
1815 0 ▶sub http_resp_favicon_uri {
Subroutine http_resp_favicon_uri: not called CC=3 SCAR=24.8
Pod undocumented
1816 0 my ($resp) = @_;
1817 0 ▶ $resp->headers->content_is_html || return;
Branch: 1 branch
BranchTrueFalseTotal
$resp->headers->content_is_html or return 0 0 0
1818 0 require HTML::Parser;
1819 0 my $href;
1820 my $p;
1821 $p = HTML::Parser->new (api_version => 3,
1822 0 ▶ start_h => [ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1823 0 my ($tagname, $attr) = @_;
1824 0 ▶ if ($tagname eq 'link'
Branch: 1 branch
BranchTrueFalseTotal
if ($tagname eq "link" and $attr->{"rel"} eq "icon") 0 0 0
Condition0%0/3
$tagname eq "link" and $attr->{"rel"} eq "icon"
!ll&&!rl&&r
000
MC/DC0%0/2
$tagname eq "link" and $attr->{"rel"} eq "icon"
$tagname eq "link" $attr->{"rel"} eq "icon"
Truth table0%0/3
A and B
A= $tagname eq "link"B= $attr->{"rel"} eq "icon"
ABresult
0X0
100
111
1825 && $attr->{'rel'} eq 'icon') {
1826 0 $href = $attr->{'href'};
1827 0 $p->eof;
1828 }
1829 0 }, "tagname, attr"]);
1830 0 $resp->decode;
1831 0 $p->parse ($resp->content);
1832 0 ▶ return $href && URI->new_abs ($href, $resp->base);
Condition0%0/3
$href && 'URI'->new_abs($href, $resp->base)
!ll&&!rl&&r
000
MC/DC0%0/2
$href && 'URI'->new_abs($href, $resp->base)
$href 'URI'->new_abs($href, $resp->base)
Truth table0%0/3
A && B
A= $hrefB= 'URI'->new_abs($href, $resp->base)
ABresult
0X0
100
111
1833 }
1834  
1835 # return base64 string value for "Face:" header
1836 # $width and $height are from attributes if known, or 0 if not
1837 0 ▶sub download_face {
Subroutine download_face: not called CC=2 SCAR=17.9
Pod undocumented
1838 0 my ($self, $uri, $width, $height) = @_;
1839 0 my $key = $uri->canonical->as_string;
1840 0 ▶ if (! exists $self->{'download_face'}->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"download_face"}{$key}) 0 0 0
1841 0 $self->{'download_face'}->{$key}
1842 = $self->download_face_uncached ($uri, $width, $height);
1843 }
1844 0 return $self->{'download_face'}->{$key};
1845 }
1846 0 ▶sub download_face_uncached {
Subroutine download_face_uncached: not called CC=11 SCAR=48.8
Pod undocumented
1847 0 my ($self, $url, $width, $height) = @_;
1848  
1849 0 $self->{'download_face_uncached'} = $url;
1850 0 $self->verbose (1, ' image download: ', $url);
1851  
1852 0 require HTTP::Request;
1853 0 my $req = HTTP::Request->new (GET => $url);
1854 0 my $resp = $self->ua->request($req);
1855 0 ▶ if (! $resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
1856 0 print __x(" no image: {status}\n",
1857 status => $resp->status_line);
1858 0 return;
1859 }
1860  
1861 0 my $type = $resp->content_type;
1862 ### $type
1863 # FIXME: is mime=>$type the right way? could give it a look at the url
1864 # basename or server's suggested filename too, for Read() to use the
1865 # extension.
1866 0 ▶ if ($type eq 'image/vnd.microsoft.icon' || $type eq 'image/x-icon') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'image/vnd.microsoft.icon' or $type eq 'image/x-icon') { } 0 0 0
elsif ($type =~ m[^image/(.*)$]i) { } 0 0 0
Condition0%0/3
$type eq "image/vnd.microsoft.icon" or $type eq "image/x-icon"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "image/vnd.microsoft.icon" or $type eq "image/x-icon"
$type eq "image/vnd.microsoft.icon" $type eq "image/x-icon"
Truth table0%0/3
A or B
A= $type eq "image/vnd.microsoft.icon"B= $type eq "image/x-icon"
ABresult
1X1
011
000
1867 # mime.xml of imagemagick 6.6.0 only has "image/x-ico", and nothing for
1868 # ico in magic.xml
1869 0 $type = 'ico';
1870 } elsif ($type =~ m{^image/(.*)$}i) {
1871 0 $type = $1;
1872 } else {
1873 0 $self->verbose (2, 'ignore non-image icon type: ',$type);
1874 0 return;
1875 }
1876  
1877 0 $resp->decode;
1878 0 my $data = $resp->content;
1879 0 ▶ if ($type ne 'png'
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "png" or $width == 0 or $height == 0 or $width > 48 or $height > 48) 0 0 0
Condition0%0/12
$type ne "png" or $width == 0 or $height == 0 or $width > 48 or $height > 48
l!l&&r!l&&!r
000
$type ne "png" or $width == 0 or $height == 0 or $width > 48
l!l&&r!l&&!r
000
$type ne "png" or $width == 0 or $height == 0
l!l&&r!l&&!r
000
$type ne "png" or $width == 0
l!l&&r!l&&!r
000
MC/DC0%0/5
$type ne "png" or $width == 0 or $height == 0 or $width > 48 or $height > 48
$type ne "png" $width == 0 $height == 0 $width > 48 $height > 48
Truth table0%0/6
A or B or C or D or E
A= $type ne "png"B= $width == 0C= $height == 0D= $width > 48E= $height > 48
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1880 || $width == 0 || $height == 0
1881 || $width > 48 || $height > 48) {
1882 0 ▶ $data = $self->imagemagick_to_png($type,$data) // return;
Condition0%0/2
$self->imagemagick_to_png($type, $data) // (return)
l!l
00
MC/DC0%0/1
$self->imagemagick_to_png($type, $data) // (return)
$self->imagemagick_to_png($type, $data)
Truth table0%0/2
A
A= $self->imagemagick_to_png($type, $data)
Aresult
11
00
1883 }
1884 0 $self->verbose (2, " image for Face ",length($data)," bytes");
1885  
1886 # use a space as a separator since MIME::Entity will collapse out a
1887 # newline and make an enormous long word which then can't be split across
1888 # header lines and will likely exceed the nntp 998 char single-line limit
1889 0 require MIME::Base64;
1890 0 $data = MIME::Base64::encode_base64($data, " ");
1891 ### $data
1892  
1893 0 return $data;
1894 }
1895  
1896 0 ▶sub face_wh_ok {
Subroutine face_wh_ok: not called CC=3 SCAR=24.8
Pod undocumented
1897 0 my ($self, $width, $height) = @_;
1898  
1899 0 ▶ if ($width > 0 && $width > 2*$height) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width > 0 and $width > 2 * $height) 0 0 0
Condition0%0/3
$width > 0 and $width > 2 * $height
!ll&&!rl&&r
000
MC/DC0%0/2
$width > 0 and $width > 2 * $height
$width > 0 $width > 2 * $height
Truth table0%0/3
A and B
A= $width > 0B= $width > 2 * $height
ABresult
0X0
100
111
1900 # some obnoxious banner
1901 0 $self->verbose (1, ' ',
1902 __x('image is a banner ({width}x{height}), ignore',
1903 width => $width, height => $height));
1904 0 return 0;
1905 }
1906 0 return 1;
1907 }
1908  
1909 #------------------------------------------------------------------------------
1910 # ImageMagick bits
1911  
1912 # $type is "gif", "ico" etc, $data is an image in a byte string
1913 # return a byte string of png, or undef if $data unrecognised
1914 0 ▶sub imagemagick_to_png {
Subroutine imagemagick_to_png: not called CC=12 SCAR=50.5
Pod undocumented
1915 0 my ($self, $type, $data) = @_;
1916 ### $type
1917 0 ▶ my $image = $self->imagemagick_from_data($type,$data) // return;
Condition0%0/2
$self->imagemagick_from_data($type, $data) // (return)
l!l
00
MC/DC0%0/1
$self->imagemagick_from_data($type, $data) // (return)
$self->imagemagick_from_data($type, $data)
Truth table0%0/2
A
A= $self->imagemagick_from_data($type, $data)
Aresult
11
00
1918  
1919 0 my $width = $image->Get('width');
1920 0 my $height = $image->Get('height');
1921 ### compress: $image->Get('compression')
1922 0 $self->verbose (2, " image ${width}x${height}");
1923 0 ▶ if ($width == 0 || $height == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width == 0 or $height == 0) 0 0 0
Condition0%0/3
$width == 0 or $height == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$width == 0 or $height == 0
$width == 0 $height == 0
Truth table0%0/3
A or B
A= $width == 0B= $height == 0
ABresult
1X1
011
000
1924 0 return;
1925 }
1926 0 ▶ if ($width <= 48 && $height <= 48 && $type eq 'png') {
Branch: 1 branch
BranchTrueFalseTotal
if ($width <= 48 and $height <= 48 and $type eq "png") 0 0 0
Condition0%0/6
$width <= 48 and $height <= 48 and $type eq "png"
!ll&&!rl&&r
000
$width <= 48 and $height <= 48
!ll&&!rl&&r
000
MC/DC0%0/3
$width <= 48 and $height <= 48 and $type eq "png"
$width <= 48 $height <= 48 $type eq "png"
Truth table0%0/4
A and B and C
A= $width <= 48B= $height <= 48C= $type eq "png"
ABCresult
0XX0
10X0
1100
1111
1927 0 return $data;
1928 }
1929  
1930 # having downloaded the image is it better to keep a banner but shrink it,
1931 # or discard as no good?
1932 #
1933 # $self->face_wh_ok ($width, $height) || return;
1934  
1935 0 ▶ if ($width > 48 || $height > 48) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width > 48 or $height > 48) 0 0 0
Condition0%0/3
$width > 48 or $height > 48
l!l&&r!l&&!r
000
MC/DC0%0/2
$width > 48 or $height > 48
$width > 48 $height > 48
Truth table0%0/3
A or B
A= $width > 48B= $height > 48
ABresult
1X1
011
000
1936 0 my $factor;
1937 0 ▶ if ($width <= 2*48 && $height <= 2*48) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width <= 96 and $height <= 96) { } 0 0 0
Condition0%0/3
$width <= 96 and $height <= 96
!ll&&!rl&&r
000
MC/DC0%0/2
$width <= 96 and $height <= 96
$width <= 96 $height <= 96
Truth table0%0/3
A and B
A= $width <= 96B= $height <= 96
ABresult
0X0
100
111
1938 0 $factor = 0.5;
1939 } else {
1940 0 $factor = min (48 / $width, 48 / $height);
1941 }
1942 0 $width = POSIX::ceil ($width * $factor);
1943 0 $height = POSIX::ceil ($height * $factor);
1944 0 $self->verbose (2, " image shrink by $factor to ${width}x${height}");
1945 # cf LiquidResize() or plain Resize()
1946 0 $image->AdaptiveResize (width => $width, height => $height);
1947 }
1948  
1949 0 my $ret = $image->Set (magick => 'PNG8');
1950 ### ret: "$ret"
1951 ### ret: $ret+0
1952 0 ▶ if ($ret != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret != 0) 0 0 0
1953 0 print "oops, imagemagick doesn't like PNG8: $ret\n";
1954 0 return;
1955 }
1956 ### compress: $image->Get('compression')
1957  
1958 # $image->Write ('/tmp/x.png');
1959 0 ($data) = $image->ImageToBlob ();
1960 0 return $data;
1961 }
1962  
1963  
1964 # $type is "png", "ico" etc, $data is an image in a byte string
1965 # return a Image::Magick object, or undef if Perl-Magick not available
1966 0 ▶sub imagemagick_from_data {
Subroutine imagemagick_from_data: not called CC=4 SCAR=30.0
Pod undocumented
1967 0 my ($self, $type, $data) = @_;
1968 ### imagemagick_from_data(): $type
1969 0 ▶ eval { require Image::Magick } or return;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Image::Magick } } or return 0 0 0
1970  
1971 0 my $image = Image::Magick->new (magick=>$type);
1972 # $image->Set(debug=>'All');
1973 0 my $ret = $image->BlobToImage ($data);
1974 ### ret: "$ret"
1975 ### ret: $ret+0
1976 0 ▶ if ($ret == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret == 1) 0 0 0
1977 0 return $image;
1978 }
1979  
1980 # try again without the $type forced, in case bad Content-Type from http
1981 0 $image = Image::Magick->new;
1982 # $image->Set(debug=>'All');
1983 0 $ret = $image->BlobToImage ($data);
1984 ### ret: "$ret"
1985 ### ret: $ret+0
1986 0 ▶ if ($ret == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret == 1) 0 0 0
1987 0 return $image;
1988 }
1989  
1990 print __x(" imagemagick doesn't like image data ({length} bytes) from {url}: {error}\n",
1991 length => length($data),
1992 0 url => $self->{'download_face_uncached'},
1993 error => $ret);
1994 0 return undef;
1995 }
1996  
1997  
1998 #------------------------------------------------------------------------------
1999 # XML::Liberal
2000  
2001 2 ▶use constant::defer have_xml_liberal => sub {
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine __ANON__: not called CC=2 SCAR=17.9
2002 0 my ($self) = @_;
2003 0 ▶ if (eval { require XML::Liberal; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require XML::Liberal; 1 } }) 0 0 0
2004 0 return 1;
2005 }
2006 0 $self->verbose (3, __x('XML::Liberal not available: {error}', error => $@));
2007 0 return 0;
2008 2 };
2009  
2010 # try to correct $xmlstr
2011 # if successful return a new xml string, otherwise return undef
2012 0 ▶sub xml_liberal_correction {
Subroutine xml_liberal_correction: not called CC=3 SCAR=24.8
Pod undocumented
2013 0 my ($self, $xmlstr) = @_;
2014 0 ▶ $self->have_xml_liberal or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->have_xml_liberal or return 0 0 0
2015  
2016 ### try XML-Liberal ...
2017 0 my $liberal = XML::Liberal->new('LibXML');
2018 0 ▶ if (my $doc = eval { $liberal->parse_string($xmlstr) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $doc = eval { do { $liberal->parse_string($xmlstr) } }) { } 0 0 0
2019 0 return $doc->toString;
2020 } else {
2021 0 $self->verbose (2, __x('XML::Liberal parse error: {error}', error => $@));
2022 0 return undef;
2023 }
2024 }
2025  
2026  
2027 #------------------------------------------------------------------------------
2028 # error as news message
2029  
2030 0 ▶sub error_message {
Subroutine error_message: not called CC=3 SCAR=24.8
Pod undocumented
2031 0 my ($self, $subject, $message, $attach_bytes) = @_;
2032  
2033 0 require Encode;
2034 0 my $charset = 'utf-8';
2035 0 $message = str_ensure_newline ($message);
2036 0 $message = Encode::encode ($charset, $message, Encode::FB_DEFAULT());
2037  
2038 0 my $date = rfc822_time_now();
2039 0 require Digest::MD5;
2040 0 my $msgid = $self->url_to_msgid
2041 ('http://localhost',
2042 Digest::MD5::md5_base64 ($date.$subject.$message));
2043  
2044 my $top = $self->mime_build
2045 ({
2046 'Path:' => 'localhost',
2047 0 'Newsgroups:' => $self->{'nntp_group'},
2048 From => __('RSS2Leafnode').' <nobody@localhost>',
2049 Subject => $subject,
2050 Date => $date,
2051 'Message-ID' => $msgid,
2052 },
2053 Top => 1,
2054 Type => 'text/plain',
2055 Charset => $charset,
2056 Data => $message);
2057  
2058 0 ▶ if (defined $attach_bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attach_bytes) 0 0 0
2059 0 $top->make_multipart;
2060 0 my $part = $self->mime_build
2061 ({},
2062 Charset => 'none',
2063 Type => 'application/octet-stream',
2064 Data => $attach_bytes);
2065 0 $top->add_part ($part);
2066 }
2067  
2068 0 mime_entity_lines($top);
2069 0 ▶ $self->nntp_post($top) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->nntp_post($top) or return 0 0 0
2070 0 say __x('{group} 1 new article', group => $self->{'nntp_group'});
2071 }
2072  
2073  
2074 #------------------------------------------------------------------------------
2075 # fetch HTML
2076  
2077 0 ▶sub http_resp_to_from {
Subroutine http_resp_to_from: not called CC=2 SCAR=17.9
Pod undocumented
2078 0 my ($self, $resp) = @_;
2079 ### http_resp_to_from()
2080 0 ▶ return $self->http_resp_exiftool_author($resp)
Condition0%0/2
$self->http_resp_exiftool_author($resp) // 'nobody@' . $self->uri_to_host
l!l
00
MC/DC0%0/1
$self->http_resp_exiftool_author($resp) // 'nobody@' . $self->uri_to_host
$self->http_resp_exiftool_author($resp)
Truth table0%0/2
A
A= $self->http_resp_exiftool_author($resp)
Aresult
11
00
2081 // 'nobody@'.$self->uri_to_host;
2082 }
2083 0 ▶sub http_resp_exiftool_author {
Subroutine http_resp_exiftool_author: not called CC=2 SCAR=17.9
Pod undocumented
2084 0 my ($self, $resp) = @_;
2085 # PNG Author field, or HTML <meta> author
2086 0 ▶ my $author = resp_exiftool_info($resp)->{'Author'} // return;
Condition0%0/2
resp_exiftool_info($resp)->{"Author"} // (return)
l!l
00
MC/DC0%0/1
resp_exiftool_info($resp)->{"Author"} // (return)
resp_exiftool_info($resp)->{"Author"}
Truth table0%0/2
A
A= resp_exiftool_info($resp)->{"Author"}
Aresult
11
00
2087 0 return $self->email_format_maybe (Encode::decode_utf8($author), '', undef);
2088 }
2089  
2090 0 ▶sub http_resp_to_copyright {
Subroutine http_resp_to_copyright: not called CC=2 SCAR=17.9
Pod undocumented
2091 0 my ($self, $resp) = @_;
2092 ### http_http_resp_to_copyright() ...
2093  
2094 0 my @copyrights = non_empty($resp->header('X-Meta-Copyright'));
2095 0 ▶ unless ($resp->content_type =~ m{^text/}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->content_type =~ m[^text/]) 0 0 0
2096 # PNG Copyright field, perhaps other formats
2097 0 push @copyrights, non_empty(resp_exiftool_info($resp)->{'Copyright'});
2098 }
2099 0 return \@copyrights;
2100 }
2101  
2102 # return a "Keywords:" string, or undef if nothing
2103 0 ▶sub http_resp_to_keywords {
Subroutine http_resp_to_keywords: not called CC=2 SCAR=17.9
Pod undocumented
2104 0 my ($self, $resp) = @_;
2105 ### http_resp_to_keywords() ...
2106  
2107 0 my @keywords = $resp->header('X-Meta-Keywords');
2108  
2109 0 ▶ if ($resp->headers->content_is_html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->headers->content_is_html) 0 0 0
2110 0 $resp->decode;
2111 0 require HTML::Parser;
2112 my $p = HTML::Parser->new
2113 (api_version => 3,
2114 report_tags => ['meta'],
2115 0 ▶ start_h => [ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
2116 0 my ($tagname, $attr) = @_;
2117 # <meta rel="og:type" content="sport"> facebook thing
2118 0 ▶ if ($tagname eq 'meta'
Branch: 1 branch
BranchTrueFalseTotal
if ($tagname eq "meta" and lc($attr->{"property"} || "") eq "og:type") 0 0 0
Condition0%0/5
$tagname eq "meta" and lc($attr->{"property"} || "") eq "og:type"
!ll&&!rl&&r
000
$attr->{'property'} || ''
l!l
00
MC/DC0%0/2
$tagname eq "meta" and lc($attr->{"property"} || "") eq "og:type"
$tagname eq "meta" $attr->{'property'}
Truth table0%0/3
A and B
A= $tagname eq "meta"B= $attr->{'property'}
ABresult
0X0
100
111
2119 && lc($attr->{'property'}||'') eq 'og:type') {
2120 0 push @keywords, $attr->{'content'};
2121 }
2122  
2123 0 }, "tagname, attr" ]);
2124 0 $p->parse ($resp->decoded_content);
2125 }
2126 ### @keywords
2127  
2128 return join_non_empty
2129 0 (', ', List::MoreUtils::uniq(map {collapse_whitespace($_)}
2130 @keywords));
2131 }
2132  
2133 0 ▶sub fetch_html {
Subroutine fetch_html: not called CC=10 SCAR=47.0
Pod documented
2134 0 my ($self, $group, $url, %options) = @_;
2135 ### fetch_html() ...
2136  
2137 0 local @{$self}{keys %options} = values %options; # hash slice
2138 0 $self->verbose (1, __x('page: {url}', url => $url));
2139  
2140 0 my $group_uri = URI->new($group,'news');
2141 0 local $self->{'nntp_host'} = uri_to_nntp_host ($group_uri);
2142 0 local $self->{'nntp_group'} = $group = $group_uri->group;
2143 0 ▶ $self->nntp_group_check($group) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->nntp_group_check($group) or return 0 0 0
2144  
2145 0 require HTTP::Request;
2146 0 my $req = HTTP::Request->new (GET => $url);
2147 0 $self->status_etagmod_req ($req);
2148 0 my $resp = $self->ua->request($req);
2149 0 ▶ if ($resp->code == 304) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->code == 304) 0 0 0
2150 0 $self->status_unchanged ($url);
2151 0 return;
2152 }
2153 0 ▶ if (! $resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
2154 0 print __x("rss2leafnode: {url}\n {status}\n",
2155 url => $url,
2156 status => $resp->status_line);
2157 0 return;
2158 }
2159 0 $self->verbose (2, $resp->headers->as_string);
2160 0 $self->enforce_html_charset_from_content ($resp);
2161  
2162 # message id is either the etag if present, or an md5 of the content if not
2163 my $msgid = $self->url_to_msgid
2164 ($url,
2165 0 ▶ $resp->header('ETag') // do {
Condition0%0/3
$resp->header("ETag") // do { require Digest::MD5; $resp->decode; my $content = $resp->content; Digest::MD5::md5_base64($content) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$resp->header("ETag") // do { require Digest::MD5; $resp->decode; my $content = $resp->content; Digest::MD5::md5_base64($content) }
$resp->header("ETag") do { require Digest::MD5; $resp->decode; my $content = $resp->content; Digest::MD5::md5_base64($content) }
Truth table0%0/3
A // B
A= $resp->header("ETag")B= do { require Digest::MD5; $resp->decode; my $content = $resp->content; Digest::MD5::md5_base64($content) }
ABresult
1X1
011
000
2166 0 require Digest::MD5;
2167 0 $resp->decode;
2168 0 my $content = $resp->content;
2169 0 Digest::MD5::md5_base64($content)
2170 });
2171 0 ▶ return 0 if $self->nntp_message_id_exists ($msgid);
Branch: 1 branch
BranchTrueFalseTotal
if $self->nntp_message_id_exists($msgid) 0 0 0
2172  
2173 0 ▶ my $subject = (html_title($resp)
Condition0%0/6
(html_title($resp) // $resp->filename) // &__x("RSS2Leafnode {url}", "url", $url)
l!l&&r!l&&!r
000
html_title($resp) // $resp->filename
l!l&&r!l&&!r
000
MC/DC0%0/3
(html_title($resp) // $resp->filename) // &__x("RSS2Leafnode {url}", "url", $url)
html_title($resp) $resp->filename &__x("RSS2Leafnode {url}", "url", $url)
Truth table0%0/4
A // B // C
A= html_title($resp)B= $resp->filenameC= &__x("RSS2Leafnode {url}", "url", $url)
ABCresult
1XX1
01X1
0011
0000
2174 // $resp->filename
2175 # show original url in subject, not anywhere redirected
2176 // __x('RSS2Leafnode {url}', url => $url));
2177  
2178 0 my $from = $self->http_resp_to_from($resp);
2179 0 my $date = $resp->header('Last-Modified');
2180 0 my $face = $self->http_resp_to_face($resp);
2181 0 my $copyright = $self->http_resp_to_copyright($resp);
2182 0 my $keywords = $self->http_resp_to_keywords($resp);
2183  
2184 0 my $part = $self->http_resp_extract_main($resp);
2185  
2186 0 my $top = $self->mime_part_from_response
2187 ($resp,
2188 Top => 1,
2189 'Path:' => scalar($self->uri_to_host),
2190 'Newsgroups:' => $group,
2191 From => $from,
2192 Subject => $subject,
2193 Date => $date,
2194 'Message-ID' => $msgid,
2195 Keywords => $keywords,
2196 'Face:' => $face,
2197 'X-Copyright:' => $copyright);
2198 0 ▶ if ($part) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part) 0 0 0
2199 ### attach full part ...
2200 0 $top->make_multipart;
2201 0 $top->add_part ($part);
2202 }
2203  
2204 0 mime_entity_lines($top);
2205 0 ▶ $self->nntp_post($top) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->nntp_post($top) or return 0 0 0
2206 0 $self->status_etagmod_resp ($url, $resp);
2207 0 say __x("{group} 1 new article", group => $group);
2208 }
2209  
2210 # $resp is a HTTP::Response
2211 # If the $self->{'html_extract_main'} option is true and $resp is html then
2212 # resplace the $resp content with HTML::ExtractMain extracted part.
2213 #
2214 0 ▶sub http_resp_extract_main {
Subroutine http_resp_extract_main: not called CC=6 SCAR=37.4
Pod undocumented
2215 0 my ($self, $resp) = @_;
2216  
2217 0 ▶ $self->{'html_extract_main'} or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"html_extract_main"} or return 0 0 0
2218 0 ▶ $resp->headers->content_is_html() or return;
Branch: 1 branch
BranchTrueFalseTotal
$resp->headers->content_is_html or return 0 0 0
2219  
2220 my $full_part
2221 = (defined $self->{'html_extract_main'}
2222 0 ▶ && $self->{'html_extract_main'} eq 'attach_full'
Condition0%0/6
defined $self->{'html_extract_main'} && $self->{'html_extract_main'} eq 'attach_full' && $self->mime_part_from_response($resp, 'Disposition', 'attachment')
!ll&&!rl&&r
000
defined $self->{"html_extract_main"} and $self->{"html_extract_main"} eq "attach_full"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{'html_extract_main'} && $self->{'html_extract_main'} eq 'attach_full' && $self->mime_part_from_response($resp, 'Disposition', 'attachment')
defined $self->{"html_extract_main"} $self->{"html_extract_main"} eq "attach_full" $self->mime_part_from_response($resp, 'Disposition', 'attachment')
Truth table0%0/4
A and B && C
A= defined $self->{"html_extract_main"}B= $self->{"html_extract_main"} eq "attach_full"C= $self->mime_part_from_response($resp, 'Disposition', 'attachment')
ABCresult
0XX0
10X0
1100
1111
2223 && $self->mime_part_from_response($resp,
2224 Disposition => "attachment"));
2225  
2226 0 require HTML::ExtractMain;
2227 0 HTML::ExtractMain->VERSION(0.63); # for output_type=>'html'
2228 0 $resp->decode; # expand any compression
2229 0 my $content = $resp->decoded_content; # as wide-chars
2230  
2231 # Output type 'html' differs from the default xhtml by a few entities, in
2232 # particular it avoids &apos; which is an xml-ism not in the html standards.
2233 # Various browsers support &apos anyway, but not for example by w3m.
2234 0 $content = HTML::ExtractMain::extract_main_html($content,
2235 output_type => 'html');
2236 0 ▶ if (! defined $content) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content) 0 0 0
2237 0 $self->verbose(1, __(" HTML::ExtractMain no main part found, posting whole"));
2238 0 return;
2239 }
2240 ### main extracted: $content
2241 0 $resp->remove_header('Content-MD5'); # since changed content
2242 0 my $charset = $resp->content_charset;
2243 0 $content = Encode::encode ($charset, $content);
2244 0 $resp->content($content);
2245  
2246 0 return $full_part;
2247 }
2248  
2249 #------------------------------------------------------------------------------
2250 # RSS hacks
2251  
2252 # This is a hack for Yahoo Finance feed uniqification.
2253 # $item is a feed hashref. If it has 'link' field with a yahoo.com
2254 # redirection like
2255 #
2256 # http://au.rd.yahoo.com/finance/news/rss/financenews/*http://au.biz.yahoo.com/071003/30/1fdvx.html
2257 #
2258 # then return the last target url part. Otherwise return false.
2259 #
2260 # This allows the item to be identified by its final target link, so as to
2261 # avoid duplication when the item appears in multiple yahoo feeds with a
2262 # different leading part. (There's no guid in yahoo feeds, as of Oct 2007.)
2263 #
2264 0 ▶sub item_yahoo_permalink {
Subroutine item_yahoo_permalink: not called CC=3 SCAR=24.8
Pod undocumented
2265 0 my ($item) = @_;
2266 0 ▶ my $url = $item->first_child_text('link')
Condition0%0/2
$item->first_child_text("link") // (return undef)
l!l
00
MC/DC0%0/1
$item->first_child_text("link") // (return undef)
$item->first_child_text("link")
Truth table0%0/2
A
A= $item->first_child_text("link")
Aresult
11
00
2267 // return undef;
2268 0 ▶ $url =~ m{^http://[^/]*yahoo\.com/.*\*(http://.*yahoo\.com.*)$}
Branch: 1 branch
BranchTrueFalseTotal
$url =~ m[^http://[^/]*yahoo\.com/.*\*(http://.*yahoo\.com.*)$] or return undef 0 0 0
2269 or return undef;
2270 0 return $1;
2271 }
2272  
2273 # This is a special case for Google Groups RSS feeds.
2274 # The arguments are link elements [$name,$uri]. If there's a google groups
2275 # like "http://groups.google.com/group/cfcdev/msg/445d4ccfdabf086b" then
2276 # return a mailing list address like "cfcdev@googlegroups.com". If not in
2277 # that form then return undef.
2278 #
2279 0 ▶sub googlegroups_link_email {
Subroutine googlegroups_link_email: not called CC=4 SCAR=30.0
Pod undocumented
2280 ## no critic (RequireInterpolationOfMetachars)
2281 0 foreach my $l (@_) {
2282 0 ▶ if ($l->{'uri'}
Branch: 1 branch
BranchTrueFalseTotal
if ($l->{"uri"} and $l->{"uri"}->canonical =~ m[^http://groups\.google\.com/group/([^/]+)/]) 0 0 0
Condition0%0/3
$l->{"uri"} and $l->{"uri"}->canonical =~ m[^http://groups\.google\.com/group/([^/]+)/]
!ll&&!rl&&r
000
MC/DC0%0/2
$l->{"uri"} and $l->{"uri"}->canonical =~ m[^http://groups\.google\.com/group/([^/]+)/]
$l->{"uri"} $l->{"uri"}->canonical =~ m[^http://groups\.google\.com/group/([^/]+)/]
Truth table0%0/3
A and B
A= $l->{"uri"}B= $l->{"uri"}->canonical =~ m[^http://groups\.google\.com/group/([^/]+)/]
ABresult
0X0
100
111
2283 && $l->{'uri'}->canonical =~ m{^http://groups\.google\.com/group/([^/]+)/}) {
2284 0 return ($1 . '@googlegroups.com');
2285 }
2286 }
2287 0 return undef;
2288 }
2289  
2290 # This is a nasty hack for http://www.aireview.com.au/rss.php
2291 # $url is a link url string just fetched, $resp is a HTTP::Response. The
2292 # return is a possibly new HTTP::Response object.
2293 #
2294 # The first fetch of an item link from aireview gives back content like
2295 #
2296 # <META HTTP-EQUIV="Refresh" CONTENT="0; URL=?zz=1&&checkForCookies=1">
2297 #
2298 # plus some cookies in the headers. The URL "zz=1" in that line seems very
2299 # dodgy, it ends up going to the home page with mozilla. In any case a
2300 # fresh fetch of the link url with the cookies provided is enough to get the
2301 # actual content.
2302 #
2303 # The LWP::UserAgent::FramesReady module on cpan has a similar match of a
2304 # Refresh, for use with frames. It works by turning the response into a
2305 # "302 Moved temporarily" for LWP to follow. urlcheck.pl at
2306 # http://www.cpan.org/authors/id/P/PH/PHILMI/urlcheck-1.00.pl likewise
2307 # follows. But alas both obey the URL given in the <META>, which is no good
2308 # here.
2309 #
2310 0 ▶sub aireview_follow {
Subroutine aireview_follow: not called CC=3 SCAR=24.8
Pod undocumented
2311 0 my ($self, $url, $resp) = @_;
2312  
2313 0 ▶ if ($resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->is_success) 0 0 0
2314 0 $resp->decode;
2315 0 my $content = $resp->content;
2316 0 ▶ if ($content =~ /<META[^>]*Refresh[^>]*checkForCookies/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /<META[^>]*Refresh[^>]*checkForCookies/i) 0 0 0
2317 0 $self->verbose (1, ' following aireview META Refresh with cookies');
2318 0 require HTTP::Request;
2319 0 my $req = HTTP::Request->new (GET => $url);
2320 0 $resp = $self->ua->request($req);
2321 }
2322 }
2323 0 return $resp;
2324 }
2325  
2326  
2327 #------------------------------------------------------------------------------
2328 # RSS links
2329  
2330  
2331 # WordPress (http://wordpress.org/) pre 2.5 had a bug
2332 # http://core.trac.wordpress.org/ticket/6579 where it gave
2333 # type="appication/atom+xml" missing the "l" in "application/".
2334 # Don't want to workaround every bad generator, but this one is GPL
2335 # free and the past versions still found for instance in the
2336 # language log http://languagelog.ldc.upenn.edu/nll/ in Feb 2011
2337 #
2338 0 ▶sub mime_type_is_rss {
Subroutine mime_type_is_rss: not called CC=1 SCAR=6.9
Pod undocumented
2339 0 my ($self, $type) = @_;
2340 0 return ($type =~ m{^appl?ication/atom\+xml$});
2341 }
2342 0 ▶sub atom_link_is_rss {
Subroutine atom_link_is_rss: not called CC=3 SCAR=24.8
Pod undocumented
2343 0 my ($self, $elt) = @_;
2344 0 ▶ my $type = $elt->att('atom:type') // $elt->att('type') // return 0;
Condition0%0/5
($elt->att("atom:type") // $elt->att("type")) // (return 0)
l!l
00
$elt->att("atom:type") // $elt->att("type")
l!l&&r!l&&!r
000
MC/DC0%0/2
($elt->att("atom:type") // $elt->att("type")) // (return 0)
$elt->att("atom:type") $elt->att("type")
Truth table0%0/3
A // B
A= $elt->att("atom:type")B= $elt->att("type")
ABresult
1X1
011
000
2345 0 return $self->mime_type_is_rss($type);
2346 }
2347  
2348 # $str is a string like "doi:10.1000/182" or "10.1000/182".
2349 # Return a url string like "http://doi.org/10.1000/182".
2350 2 ▶sub doi_to_uri {
Subroutine doi_to_uri: called CC=1 SCAR=0.0
Pod undocumented
2351 2 my ($str) = @_;
2352 2 $str =~ s/^doi://;
2353  
2354 # DOI numbers can potentially include URI reserved characters, let URI.pm
2355 # percent encode them when necessary.
2356 2 my $uri = URI->new('http://doi.org/');
2357 2 $uri->path($str);
2358 2 return $uri;
2359 }
2360  
2361 # return list of hashrefs, each being
2362 # { name => $str,
2363 # uri => $uri_object,
2364 # download => $boolean,
2365 # priority => $number,
2366 # }
2367 #
2368 # Links are listed from highest to lowest priority. The current priority
2369 # levels are
2370 # 0 plain links
2371 # -10 comment RSS
2372 # -20 author home page
2373 # -100 geo location text-only
2374 # -101 statusnet geo location
2375 # -200 <source>, <media:credit>, <itunes:explicit>
2376 #
2377 0 ▶sub item_to_links {
Subroutine item_to_links: not called CC=83 SCAR=88.5
Pod undocumented
2378 0 my ($self, $item) = @_;
2379  
2380 # <feedburner:origLink> or <feedburner:origEnclosureLink> is when
2381 # something has been expanded into the item, or should it be shown?
2382  
2383 # FIXME: <media:content> can be a link, but have seen it just duplicating
2384 # <enclosure> without a length. Would probably skip medium="image".
2385 # Can have a <media:title> sub-element.
2386 #
2387 # ENHANCE-ME: <media:content> can have a file size and duration.
2388 #
2389 # FIXME: <media:group> is a collection of <media:content> in different
2390 # formats etc. Have seen this from archive.org just duplicating
2391 # <enclosure>.
2392 #
2393 # <wfw:commentRss> appeared in the spec page as wfw:commentRSS, so ignore
2394 # case.
2395 #
2396 0 my @elts = $item->children (qr/^(link
2397 |enclosure
2398 |content
2399 |wiki:diff
2400 |wiki:history
2401 |comments
2402 |wfw:comment
2403 |wfw:commentRss
2404 |foaf:maker
2405 |sioc:has_creator
2406 |sioc:has_discussion
2407 |sioc:links_to
2408 |sioc:reply_of
2409 |statusnet:origin
2410 |dc:source
2411 |prism:url
2412 )$/ix);
2413 ### link elts: "@elts"
2414  
2415 0 my @links;
2416 0 foreach my $elt (@elts) {
2417 0 ▶ if ($self->{'verbose'} >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} >= 2) 0 0 0
2418 0 require Text::Wrap;
2419 0 local $Text::Wrap::huge = 'overflow'; # don't break long URLs etc
2420 0 $self->verbose (2, "link\n", Text::Trim::trim($elt->sprint));
2421 }
2422  
2423 0 my $tag = lc($elt->tag);
2424 ### $tag
2425 0 ▶ if ($tag eq 'content' && atom_content_flavour($elt) ne 'link') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "content" and atom_content_flavour($elt) ne "link") 0 0 0
Condition0%0/3
$tag eq "content" and atom_content_flavour($elt) ne "link"
!ll&&!rl&&r
000
MC/DC0%0/2
$tag eq "content" and atom_content_flavour($elt) ne "link"
$tag eq "content" atom_content_flavour($elt) ne "link"
Truth table0%0/3
A and B
A= $tag eq "content"B= atom_content_flavour($elt) ne "link"
ABresult
0X0
100
111
2426 0 next;
2427 }
2428 0 my $l = { download => 1 };
2429  
2430 0 foreach my $name ('hreflang', 'title', 'type') {
2431 0 ▶ $l->{$name} = ($elt->att("atom:$name") // $elt->att($name));
Condition0%0/3
$elt->att("atom:$name") // $elt->att($name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$elt->att("atom:$name") // $elt->att($name)
$elt->att("atom:$name") $elt->att($name)
Truth table0%0/3
A // B
A= $elt->att("atom:$name")B= $elt->att($name)
ABresult
1X1
011
000
2432 }
2433  
2434 0 ▶ my $rel = non_empty($elt->att('atom:rel') // $elt->att('rel'));
Condition0%0/3
$elt->att("atom:rel") // $elt->att("rel")
l!l&&r!l&&!r
000
MC/DC0%0/2
$elt->att("atom:rel") // $elt->att("rel")
$elt->att("atom:rel") $elt->att("rel")
Truth table0%0/3
A // B
A= $elt->att("atom:rel")B= $elt->att("rel")
ABresult
1X1
011
000
2435 0 ▶ if (defined $rel) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rel) { } 0 0 0
2436 # Atom rel="..."
2437 # Maybe: if ($rel eq 'next') ... # not sure about "next" link
2438  
2439 0 ▶ if ($rel eq 'self' # the feed itself (in the channel normally)
Branch: 1 branch
BranchTrueFalseTotal
if ($rel eq "self" or $rel eq "edit" or $rel eq "service.edit" or $rel eq "license") 0 0 0
Condition0%0/9
$rel eq "self" or $rel eq "edit" or $rel eq "service.edit" or $rel eq "license"
l!l&&r!l&&!r
000
$rel eq "self" or $rel eq "edit" or $rel eq "service.edit"
l!l&&r!l&&!r
000
$rel eq "self" or $rel eq "edit"
l!l&&r!l&&!r
000
MC/DC0%0/4
$rel eq "self" or $rel eq "edit" or $rel eq "service.edit" or $rel eq "license"
$rel eq "self" $rel eq "edit" $rel eq "service.edit" $rel eq "license"
Truth table0%0/5
A or B or C or D
A= $rel eq "self"B= $rel eq "edit"C= $rel eq "service.edit"D= $rel eq "license"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
2440 || $rel eq 'edit' # to edit the item, maybe
2441 || $rel eq 'service.edit' # to edit the item
2442 || $rel eq 'license' # probably only in the channel part normally
2443 ) {
2444 0 $self->verbose (1, ' ', __x('skip link "{type}"', type => $rel));
2445 0 next;
2446 }
2447 0 ▶ if ($rel eq 'alternate') {
Branch: 8 branches
BranchTrueFalseTotal
if ($rel eq 'alternate') { } 0 0 0
elsif ($rel eq 'enclosure') { } 0 0 0
elsif ($rel eq 'ostatus:conversation') { } 0 0 0
elsif ($rel eq 'ostatus:attention') { } 0 0 0
elsif ($rel eq 'related') { } 0 0 0
elsif ($rel eq 'replies') { } 0 0 0
elsif ($rel eq 'service.post') { } 0 0 0
elsif ($rel eq 'via') { } 0 0 0
2448 # "alternate" is supposed to be the content as the entry, but in a
2449 # web page or something. Not sure that's always quite true, so show
2450 # it as a plain link. If no <content> then an "alternate" is
2451 # supposed to be mandatory.
2452  
2453 } elsif ($rel eq 'enclosure') {
2454 0 $l->{'name'} = __('Encl');
2455  
2456 } elsif ($rel eq 'ostatus:conversation') {
2457 0 $l->{'name'} = __('Conversation');
2458 0 $l->{'download'} = 0;
2459  
2460 } elsif ($rel eq 'ostatus:attention') {
2461 0 $l->{'name'} = __('Attention');
2462 0 $l->{'download'} = 0;
2463  
2464 } elsif ($rel eq 'related') {
2465 0 $l->{'name'} = __('Related');
2466  
2467 } elsif ($rel eq 'replies') {
2468 # Atom <link rel="replies" per RFC 4685 "thr:" spec
2469 0 my $count = $self->item_elt_comments_count($item,$elt);
2470 0 ▶ if ($self->atom_link_is_rss($elt)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->atom_link_is_rss($elt)) { } 0 0 0
2471 0 ▶ $l->{'name'} = (defined $count
Branch: 1 branch
BranchTrueFalseTotal
defined $count ? : 0 0 0
2472 ? __x('RSS Replies({count})', count => $count)
2473 : __('RSS Replies'));
2474 0 $l->{'priority'} = -10;
2475 } else {
2476 0 ▶ $l->{'name'} = (defined $count
Branch: 1 branch
BranchTrueFalseTotal
defined $count ? : 0 0 0
2477 ? __x('Replies({count})', count => $count)
2478 : __('Replies'));
2479 }
2480 0 $l->{'download'} = 0;
2481  
2482 } elsif ($rel eq 'service.post') {
2483 0 $l->{'name'} = __('Comments');
2484 0 $l->{'download'} = 0;
2485  
2486 } elsif ($rel eq 'via') {
2487 0 $l->{'name'} = __('Via');
2488 0 $l->{'download'} = 0;
2489  
2490 } else {
2491 0 $l->{'name'} = __x('{linkrel}', linkrel => $rel);
2492 }
2493  
2494 } else { # ! defined $rel
2495 # tags without rel="" attribute
2496 #
2497 0 ▶ if ($tag eq 'enclosure') {
Branch: 9 branches
BranchTrueFalseTotal
if ($tag eq 'enclosure') { } 0 0 0
elsif ($tag eq 'dc:source') { } 0 0 0
elsif ($tag eq 'wiki:diff') { } 0 0 0
elsif ($tag eq 'wiki:history') { } 0 0 0
elsif ($tag =~ /foaf:maker|sioc:has_creator/) { } 0 0 0
elsif ($tag eq 'statusnet:origin') { } 0 0 0
elsif ($tag eq 'sioc:has_discussion') { } 0 0 0
elsif ($tag eq 'wfw:commentrss') { } 0 0 0
elsif ($tag =~ /comment/) { } 0 0 0
2498 0 $l->{'name'} = __('Encl');
2499  
2500 } elsif ($tag eq 'dc:source') {
2501 # might be free form text or might be url or other formal system
2502 0 $l->{'name'} = __('Source');
2503 0 $l->{'download'} = 0;
2504 0 $l->{'maybe_text'} = 1;
2505 0 $l->{'priority'} = -10;
2506  
2507 } elsif ($tag eq 'wiki:diff') {
2508 0 $l->{'name'} = __('Diff');
2509  
2510 } elsif ($tag eq 'wiki:history') {
2511 0 $l->{'name'} = __('History');
2512 0 $l->{'download'} = 0;
2513  
2514 } elsif ($tag =~ /foaf:maker|sioc:has_creator/) {
2515 0 $l->{'name'} = __('Author');
2516 0 $l->{'download'} = 0;
2517 0 $l->{'priority'} = -20; # low
2518  
2519 } elsif ($tag eq 'statusnet:origin') {
2520 0 $l->{'name'} = __('Geo location');
2521 0 $l->{'download'} = 0;
2522 0 $l->{'priority'} = -101; # just after Geo location
2523  
2524 } elsif ($tag eq 'sioc:has_discussion') {
2525 0 $l->{'name'} = __('Discussion');
2526 0 $l->{'download'} = 0;
2527  
2528 } elsif ($tag eq 'wfw:commentrss') {
2529 0 ▶ if (defined (my $count = $self->item_elt_comments_count($item,$elt))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $count = $self->item_elt_comments_count($item, $elt))) { } 0 0 0
2530 0 $l->{'name'} = __x('RSS Comments({count})', count => $count);
2531 } else {
2532 0 $l->{'name'} = __('RSS Comments');
2533 }
2534 0 $l->{'download'} = 0;
2535 0 $l->{'priority'} = -10;
2536  
2537 } elsif ($tag =~ /comment/) { # <comments> or <wfw:comment>
2538 0 ▶ if (defined (my $count = $self->item_elt_comments_count($item,$elt))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $count = $self->item_elt_comments_count($item, $elt))) { } 0 0 0
2539 0 $l->{'name'} = __x('Comments({count})', count => $count);
2540 } else {
2541 0 $l->{'name'} = __('Comments');
2542 }
2543 0 $l->{'download'} = 0;
2544 }
2545 }
2546  
2547 # Atom <link href="http:.."/>
2548 # RSS <link>http:..</link>
2549 # RSS <enclosure url="http:..">
2550 0 ▶ $l->{'uri'} //= (non_empty ($elt->att('atom:href')) # Atom <link>
Condition0%0/18
$l->{"uri"} //= ((((non_empty($elt->att("atom:href")) // non_empty($elt->att("href"))) // non_empty($elt->att("atom:src"))) // non_empty($elt->att("src"))) // non_empty($elt->att("url"))) // non_empty($elt->att("rdf:resource"))
l!l&&r!l&&!r
000
((((non_empty($elt->att("atom:href")) // non_empty($elt->att("href"))) // non_empty($elt->att("atom:src"))) // non_empty($elt->att("src"))) // non_empty($elt->att("url"))) // non_empty($elt->att("rdf:resource"))
l!l&&r!l&&!r
000
(((non_empty($elt->att("atom:href")) // non_empty($elt->att("href"))) // non_empty($elt->att("atom:src"))) // non_empty($elt->att("src"))) // non_empty($elt->att("url"))
l!l&&r!l&&!r
000
((non_empty($elt->att("atom:href")) // non_empty($elt->att("href"))) // non_empty($elt->att("atom:src"))) // non_empty($elt->att("src"))
l!l&&r!l&&!r
000
(non_empty($elt->att("atom:href")) // non_empty($elt->att("href"))) // non_empty($elt->att("atom:src"))
l!l&&r!l&&!r
000
non_empty($elt->att("atom:href")) // non_empty($elt->att("href"))
l!l&&r!l&&!r
000
MC/DC0%0/7
$l->{"uri"} //= ((((non_empty($elt->att("atom:href")) // non_empty($elt->att("href"))) // non_empty($elt->att("atom:src"))) // non_empty($elt->att("src"))) // non_empty($elt->att("url"))) // non_empty($elt->att("rdf:resource"))
$l->{"uri"} non_empty($elt->att("atom:href")) non_empty($elt->att("href")) non_empty($elt->att("atom:src")) non_empty($elt->att("src")) non_empty($elt->att("url")) non_empty($elt->att("rdf:resource"))
Truth table0%0/8
A //= B // C // D // E // F // G
A= $l->{"uri"}B= non_empty($elt->att("atom:href"))C= non_empty($elt->att("href"))D= non_empty($elt->att("atom:src"))E= non_empty($elt->att("src"))F= non_empty($elt->att("url"))G= non_empty($elt->att("rdf:resource"))
ABCDEFGresult
1XXXXXX1
01XXXXX1
001XXXX1
0001XXX1
00001XX1
000001X1
00000011
00000000
2551 // non_empty ($elt->att('href')) # Atom <link>
2552 // non_empty ($elt->att('atom:src')) # Atom <content>
2553 // non_empty ($elt->att('src')) # Atom <content>
2554 // non_empty ($elt->att('url')) # RSS <enclosure>
2555 # <foaf:maker>, <statusnet:origin> rdf:resource=""
2556 // non_empty ($elt->att('rdf:resource')));
2557 0 ▶ if (defined $l->{'ur'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $l->{"ur"}) 0 0 0
2558 0 $l->{'maybe_text'} = 0; # above are definite urls
2559 }
2560 0 ▶ $l->{'uri'} //= (non_empty ($elt->trimmed_text) # RSS <link>
Condition0%0/4
$l->{"uri"} //= non_empty($elt->trimmed_text) // (next)
l!l
00
non_empty($elt->trimmed_text) // (next)
l!l
00
MC/DC0%0/1
$l->{"uri"} //= non_empty($elt->trimmed_text) // (next)
$l->{"uri"}
Truth table0%0/2
A
A= $l->{"uri"}
Aresult
11
00
2561 // next); # no contents
2562 0 ▶ if ($l->{'maybe_text'} && $l->{'uri'} !~ m{^[a-z]+://}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l->{'maybe_text'} and not $l->{'uri'} =~ m[^[a-z]+://]) { } 0 0 0
Condition0%0/3
$l->{"maybe_text"} and not $l->{"uri"} =~ m[^[a-z]+://]
!ll&&!rl&&r
000
MC/DC0%0/2
$l->{"maybe_text"} and not $l->{"uri"} =~ m[^[a-z]+://]
$l->{"maybe_text"} not $l->{"uri"} =~ m[^[a-z]+://]
Truth table0%0/3
A and not(B)
A= $l->{"maybe_text"}B= not $l->{"uri"} =~ m[^[a-z]+://]
ABresult
0X0
100
111
2563 0 $l->{'name'} .= ': ' . delete $l->{'uri'};
2564 } else {
2565 0 $l->{'uri'} = App::RSS2Leafnode::XML::Twig::Other::elt_xml_based_uri ($elt, $l->{'uri'});
2566 }
2567  
2568 0 ▶ $l->{'name'} //= __('Link');
Condition0%0/3
$l->{"name"} //= &__("Link")
l!l&&r!l&&!r
000
MC/DC0%0/2
$l->{"name"} //= &__("Link")
$l->{"name"} &__("Link")
Truth table0%0/3
A //= B
A= $l->{"name"}B= &__("Link")
ABresult
1X1
011
000
2569  
2570 0 my @paren;
2571 # show length if biggish, often provided on enclosures but not plain
2572 # links
2573 0 ▶ if (defined (my $length = ($elt->att('atom:length')
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $length = $elt->att("atom:length") // $elt->att("length"))) 0 0 0
Condition0%0/3
$elt->att("atom:length") // $elt->att("length")
l!l&&r!l&&!r
000
MC/DC0%0/2
$elt->att("atom:length") // $elt->att("length")
$elt->att("atom:length") $elt->att("length")
Truth table0%0/3
A // B
A= $elt->att("atom:length")B= $elt->att("length")
ABresult
1X1
011
000
2574 // $elt->att('length')))) {
2575 0 push @paren, $self->format_size_in_bytes($length);
2576 }
2577 # <itunes:duration> applies to <enclosure>. Just a number means
2578 # seconds, otherwise MM:SS or HH:MM:SS.
2579 0 ▶ if ($tag eq 'enclosure'
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "enclosure" and defined(my $duration = non_empty($item->first_child_text("itunes:duration")))) 0 0 0
Condition0%0/3
$tag eq "enclosure" and defined(my $duration = non_empty($item->first_child_text("itunes:duration")))
!ll&&!rl&&r
000
MC/DC0%0/2
$tag eq "enclosure" and defined(my $duration = non_empty($item->first_child_text("itunes:duration")))
$tag eq "enclosure" defined(my $duration = non_empty($item->first_child_text("itunes:duration")))
Truth table0%0/3
A and B
A= $tag eq "enclosure"B= defined(my $duration = non_empty($item->first_child_text("itunes:duration")))
ABresult
0X0
100
111
2580 && defined (my $duration = non_empty ($item->first_child_text('itunes:duration')))) {
2581 0 ▶ if ($duration !~ /:/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($duration =~ /:/) 0 0 0
2582 0 $duration = __px('s-for-seconds', '{duration}s',
2583 duration => $duration);
2584 }
2585 0 push @paren, collapse_whitespace($duration);
2586 }
2587 0 ▶ if (@paren) {
Branch: 1 branch
BranchTrueFalseTotal
if (@paren) 0 0 0
2588 0 $l->{'name'} .= '('.join(', ',@paren). ')';
2589 }
2590  
2591 ### push link: $l
2592 0 push @links, $l;
2593 }
2594  
2595 0 ▶ if (! $item->first_child('prism:url')
Branch: 1 branch
BranchTrueFalseTotal
if (not $item->first_child("prism:url") and my $elt = $item->first_child("prism:doi")) 0 0 0
Condition0%0/3
not $item->first_child("prism:url") and my $elt = $item->first_child("prism:doi")
!ll&&!rl&&r
000
MC/DC0%0/2
not $item->first_child("prism:url") and my $elt = $item->first_child("prism:doi")
not $item->first_child("prism:url") my $elt = $item->first_child("prism:doi")
Truth table0%0/3
not(A) and B
A= not $item->first_child("prism:url")B= my $elt = $item->first_child("prism:doi")
ABresult
0X0
100
111
2596 && (my $elt = $item->first_child('prism:doi'))) {
2597 # Eg. http://www.nature.com/nature/current_issue/rss
2598 # which also has dc:identifier as the same DOI
2599 0 push @links, { name => __('DOI'),
2600 uri => doi_to_uri($elt->trimmed_text),
2601 };
2602 }
2603  
2604 # eg. RSS <source url="http://foo.org/feed.rss">other feed name</source>
2605 # Atom <source>
2606 # <id>...url...</id>
2607 # <title>Feed Name</title>
2608 # <link rel="self" type="application/atom+xml" href="...feed-url..."/>
2609 # <icon>...image-url...</icon>
2610 # <link rel="license" href="http://creativecommons.org/licenses/by/3.0/"/>
2611 # </source>
2612 #
2613 0 foreach my $elt ($item->children('source')) {
2614 0 ▶ my $str = non_empty (elt_to_rendered_line($elt->first_child('title')))
Condition0%0/3
non_empty(elt_to_rendered_line($elt->first_child("title"))) // non_empty($elt->trimmed_text)
l!l&&r!l&&!r
000
MC/DC0%0/2
non_empty(elt_to_rendered_line($elt->first_child("title"))) // non_empty($elt->trimmed_text)
non_empty(elt_to_rendered_line($elt->first_child("title"))) non_empty($elt->trimmed_text)
Truth table0%0/3
A // B
A= non_empty(elt_to_rendered_line($elt->first_child("title")))B= non_empty($elt->trimmed_text)
ABresult
1X1
011
000
2615 // non_empty ($elt->trimmed_text);
2616 0 ▶ if (defined $str) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str) 0 0 0
2617 ### source: $str
2618 0 push @links, { name => __('Source') . ": $str",
2619 download => 0,
2620 priority => -200,
2621 };
2622 }
2623 0 foreach my $subelt
2624 ($elt,
2625 0 grep {$self->atom_link_is_rss($_)} $elt->children('link')
2626 ) {
2627 0 ▶ if (defined $subelt
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subelt and defined(my $url = (non_empty($subelt->att("url")) // non_empty($subelt->att("href"))) // non_empty($subelt->att("atom:href")))) 0 0 0
Condition0%0/9
defined $subelt and defined(my $url = (non_empty($subelt->att("url")) // non_empty($subelt->att("href"))) // non_empty($subelt->att("atom:href")))
!ll&&!rl&&r
000
(non_empty($subelt->att("url")) // non_empty($subelt->att("href"))) // non_empty($subelt->att("atom:href"))
l!l&&r!l&&!r
000
non_empty($subelt->att("url")) // non_empty($subelt->att("href"))
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $subelt and defined(my $url = (non_empty($subelt->att("url")) // non_empty($subelt->att("href"))) // non_empty($subelt->att("atom:href")))
defined $subelt non_empty($subelt->att("url")) non_empty($subelt->att("href")) non_empty($subelt->att("atom:href"))
Truth table0%0/5
A and B // C // D
A= defined $subeltB= non_empty($subelt->att("url"))C= non_empty($subelt->att("href"))D= non_empty($subelt->att("atom:href"))
ABCDresult
0XXX0
10000
11XX1
101X1
10011
2628 && defined (my $url = non_empty ($subelt->att('url'))
2629 // non_empty ($subelt->att('href'))
2630 // non_empty ($subelt->att('atom:href')))) {
2631 0 push @links, { name => __('Source RSS'),
2632 uri => App::RSS2Leafnode::XML::Twig::Other::elt_xml_based_uri($subelt,$url),
2633 download => 0,
2634 priority => -200,
2635 };
2636 }
2637 }
2638 }
2639  
2640 # Merge together duplicate urls, so as not to download two copies as
2641 # attachments, and so as to make it clear when there's only one
2642 # destination for two things.
2643 #
2644 # Have seen same url under <link> and <comments> from sourceforge
2645 # http://sourceforge.net/export/rss2_keepsake.php?group_id=203650
2646 # or same url under <link> and <enclosure>
2647 # http://abc.net.au/rn/podcast/feeds/sci.xml
2648 {
2649 0 my %seen;
2650 @links = grep {
2651 0 my $l = $_;
2652 0 my $want = 1;
2653 0 ▶ if (my $uri = $l->{'uri'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $uri = $l->{"uri"}) 0 0 0
2654 0 my $canonical = $uri->canonical;
2655 0 $canonical->fragment(undef); # ignore #foo anchor for uniqueness
2656 0 ▶ if (my $prev_l = $seen{$canonical}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prev_l = $seen{$canonical}) 0 0 0
2657 0 $want = 0;
2658 0 ▶ $prev_l->{'download'} ||= $l->{'download'};
Condition0%0/3
$prev_l->{"download"} ||= $l->{"download"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$prev_l->{"download"} ||= $l->{"download"}
$prev_l->{"download"} $l->{"download"}
Truth table0%0/3
A ||= B
A= $prev_l->{"download"}B= $l->{"download"}
ABresult
1X1
011
000
2659 $l->{'priority'} = max ($l->{'priority'}||0,
2660 0 ▶ $prev_l->{'priority'}||0);
Condition0%0/4
$l->{'priority'} || 0
l!l
00
$prev_l->{'priority'} || 0
l!l
00
MC/DC0%0/1
$l->{'priority'} || 0
$l->{'priority'}
MC/DC0%0/1
$prev_l->{'priority'} || 0
$prev_l->{'priority'}
Truth table0%0/2
A
A= $l->{'priority'}
Aresult
11
00
Truth table0%0/2
A
A= $prev_l->{'priority'}
Aresult
11
00
2661  
2662 # prefer no anchor if have both with and without
2663 0 ▶ if (is_empty($l->{'uri'}->fragment)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_empty($l->{"uri"}->fragment)) 0 0 0
2664 0 $prev_l->{'uri'} = $l->{'uri'};
2665 }
2666  
2667 0 ▶ if ($prev_l->{'name'} eq __('Link')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($prev_l->{'name'} eq &__('Link')) { } 0 0 0
elsif ($l->{'name'} eq &__('Link')) { } 0 0 0
elsif ($l->{'name'} eq $prev_l->{'name'}) { } 0 0 0
2668 # name "Link" doesn't say much, prefer the other over "Link"
2669 0 $prev_l->{'name'} = $l->{'name'};
2670 } elsif ($l->{'name'} eq __('Link')) {
2671 # don't append "Link" to the previous
2672 } elsif ($l->{'name'} eq $prev_l->{'name'}) {
2673 # don't double the same name
2674 } else {
2675 0 $prev_l->{'name'} .= ", $l->{'name'}";
2676 }
2677 }
2678 0 $seen{$canonical} = $l;
2679 }
2680 $want
2681 0 } @links;
2682 }
2683 0 foreach my $l (@links) {
2684 0 ▶ if ($l->{'uri'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l->{"uri"}) 0 0 0
2685 0 $l->{'name'} .= ':';
2686 }
2687 }
2688  
2689 0 ▶ if (my $elt = $item->first_child('hlxcd:helex-company-data')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $elt = $item->first_child("hlxcd:helex-company-data")) 0 0 0
2690 # Eg. http://www.helex.gr/rss-feeds
2691 # http://www.helex.gr/web/guest/rss-feeds/-/asset_publisher/companiesrss/custom-rss
2692 0 my $str = join_non_empty
2693 (' ',
2694 $elt->first_child_text('hlxcd:company-ticker-symbol'),
2695 $elt->first_child_text('hlxcd:company-name'));
2696 0 ▶ if (is_non_empty($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty($str)) 0 0 0
2697 0 push @links, { name => __('Company:').' '.$str,
2698 download => 0,
2699 priority => -100,
2700 };
2701 }
2702 }
2703  
2704 0 ▶ if (defined (my $str = $self->item_to_lat_long_alt_str ($item))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $str = $self->item_to_lat_long_alt_str($item))) 0 0 0
2705 0 push @links, { name => $str,
2706 download => 0,
2707 priority => -100, # lat/long low priority
2708 };
2709 }
2710  
2711 # re:rank as for example from stackexchange.com
2712 # What does label="" usually show? Are parens like this good?
2713 0 foreach my $elt ($item->children('re:rank')) {
2714 0 my $label = $elt->att('label');
2715 0 my $value = elt_to_rendered_line($elt);
2716 0 ▶ push @links, { name => (defined $label
Branch: 1 branch
BranchTrueFalseTotal
defined $label ? : 0 0 0
2717 ? __x('Rank: {value} ({label})', value => $value, label => $label)
2718 : __x('Rank: {value}', value => $value)),
2719 download => 0,
2720 priority => -200, # low priority
2721 };
2722 }
2723  
2724 # eg. <media:credit role="publishing company">AFP</media:credit>
2725 # is there any value in the role="" part?
2726 0 foreach my $elt ($item->children('media:credit')) {
2727 0 push @links, { name => __x('Credit: {who}',
2728 who => scalar(elt_to_rendered_line($elt))),
2729 download => 0,
2730 priority => -200, # very low priority
2731 };
2732 }
2733  
2734 # <itunes:explicit>no</itunes:explicit>
2735 #
2736 # Allow for empty <itunes:explicit/> as found
2737 # http://abc.net.au/rn/podcast/feeds/sci.xml
2738 #
2739 0 foreach my $elt ($item->children('itunes:explicit')) {
2740 0 ▶ my $line = elt_to_rendered_line($elt)
Condition0%0/2
elt_to_rendered_line($elt) // (next)
l!l
00
MC/DC0%0/1
elt_to_rendered_line($elt) // (next)
elt_to_rendered_line($elt)
Truth table0%0/2
A
A= elt_to_rendered_line($elt)
Aresult
11
00
2741 // next; # skip empty <itunes:explicit/>
2742 0 push @links, { name => __x('Explicit: {value}', value => $line),
2743 download => 0,
2744 priority => -200, # very low priority
2745 };
2746 }
2747  
2748 # <slash:department>blasting-it-into-the-sun-is-not-a-viable-option</slash:department>
2749 # a fun kind of commentary thing
2750 0 foreach my $elt ($item->children('slash:department')) {
2751 0 push @links, { name => __x('Department: {department}',
2752 department => scalar(elt_to_rendered_line($elt))),
2753 download => 0,
2754 priority => -200, # very low priority
2755 };
2756 }
2757  
2758 0 return @links;
2759 }
2760 2 @known{qw(
2761 /channel/item/pheedo:origLink
2762 /channel/item/feedburner:origLink
2763  
2764 /channel/item/link
2765 /channel/item/enclosure
2766 /channel/item/dc:source
2767 /channel/item/dc:identifier
2768 /channel/item/comments
2769 /channel/item/wfw:comment
2770 /channel/item/wfw:commentRss
2771 /channel/item/slash:comments
2772 /channel/item/slash:hit_parade
2773 /channel/item/slash:department
2774 /channel/item/thr:total
2775 /channel/item/content --atom
2776 /channel/item/wiki:diff
2777 /channel/item/itunes:duration
2778 /channel/item/re:rank
2779  
2780 /channel/wiki:interwiki
2781 /channel/wiki:interwiki/rdf:Description
2782 /channel/wiki:interwiki/rdf:Description/rdf:value
2783 /channel/item/wiki:version
2784 /channel/item/wiki:status
2785 /channel/item/wiki:history
2786 /channel/item/foaf:maker
2787 /channel/item/sioc:has_creator
2788 /channel/item/sioc:has_discussion
2789 /channel/item/sioc:links_to
2790 /channel/item/sioc:reply_of
2791 /channel/item/media:credit
2792 /channel/item/itunes:explicit
2793 /channel/item/itunes:block
2794 /channel/item/hlxcd:helex-company-data
2795  
2796 --believed-to-be-duplicate-of-description
2797 /channel/item/media:content
2798 /channel/item/media:text
2799  
2800 /channel/item/prism:doi
2801 /channel/item/prism:publicationName
2802 /channel/item/prism:publicationDate
2803 /channel/item/prism:url
2804 /channel/item/prism:volume
2805 /channel/item/prism:number
2806 /channel/item/prism:section
2807 /channel/item/prism:startingPage
2808 /channel/item/prism:endingPage
2809 )} = ();
2810  
2811 # sub any_link_replies_nonfeed {
2812 # foreach my $elt (@_) {
2813 # # ### any_link_replies_nonfeed(): ref $elt, "$elt", $elt->tag
2814 # # my $rel = ($elt->att('atom:rel') // $elt->att('rel') // '');
2815 # # my $type = ($elt->att('atom:type') // $elt->att('type') // '');
2816 # # ### $rel
2817 # # ### $type
2818 # if ($elt->tag eq 'link'
2819 # && (($elt->att('atom:rel') // $elt->att('rel') // '')
2820 # eq 'replies')
2821 # && (($elt->atom_link_is_rss($elt))) {
2822 # return 1;
2823 # }
2824 # }
2825 # return 0;
2826 # }
2827  
2828 # Return a string which is the latitude, longitude and possibly altitude
2829 # from the item. If no location in the item then return undef.
2830 #
2831 0 ▶sub item_to_lat_long_alt_str {
Subroutine item_to_lat_long_alt_str: not called CC=7 SCAR=40.3
Pod undocumented
2832 0 my ($self, $item) = @_;
2833 0 ▶ my ($lat, $long, $alt) = $self->item_to_lat_long_alt_values ($item)
Branch: 1 branch
BranchTrueFalseTotal
() = $self->item_to_lat_long_alt_values($item) or return 0 0 0
2834 or return;
2835 ### $lat
2836 ### $long
2837 ### $alt
2838  
2839 0 ▶ if (Scalar::Util::looks_like_number($lat)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($lat)) 0 0 0
2840 0 ▶ $lat = ($lat >= 0
Branch: 1 branch
BranchTrueFalseTotal
$lat >= 0 ? : 0 0 0
2841 # TRANSLATORS: the latin1/unicode degree symbol can be used here
2842 # instead of " deg", if it will be recognised in translation,
2843 # etc.
2844 ? __x('{latitude} deg N', latitude => $lat)
2845 : __x('{latitude} deg S', latitude => -$lat));
2846 }
2847 0 ▶ if (Scalar::Util::looks_like_number($long)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($long)) 0 0 0
2848 0 ▶ $long = ($long >= 0
Branch: 1 branch
BranchTrueFalseTotal
$long >= 0 ? : 0 0 0
2849 ? __x('{longitude} deg E', longitude => $long)
2850 : __x('{longitude} deg W', longitude => -$long));
2851 }
2852  
2853 0 ▶ if (is_non_empty ($alt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty($alt)) { } 0 0 0
2854 0 return __x('Geo location: {latitude}, {longitude}, alt {altitude}m',
2855 latitude => $lat,
2856 longitude => $long,
2857 altitude => $alt);
2858 } else {
2859 0 return __x('Geo location: {latitude}, {longitude}',
2860 latitude => $lat,
2861 longitude => $long);
2862 }
2863 }
2864  
2865 # Return a list of values which are the latitude, longitude and possibly
2866 # altitude extracted from $item.
2867 #
2868 # ($latitude, $longitude, $altitude)
2869 # ($latitude, $longitude)
2870 # ()
2871 #
2872 # If no location then return an empty list. Some of the values returned
2873 # might be empty strings if say there's a <geo:lat> but missing <geo:long>.
2874 #
2875 # Latitude is degrees North, or negative for South. Longitude is degrees
2876 # East, or negative for West. Both possibly with decimal places.
2877 #
2878 0 ▶sub item_to_lat_long_alt_values {
Subroutine item_to_lat_long_alt_values: not called CC=6 SCAR=37.4
Pod undocumented
2879 0 my ($self, $item) = @_;
2880  
2881 # per-item <geo:lat>, <geo:long> eg. USGS earthquakes
2882 # http://earthquake.usgs.gov/eqcenter/recenteqsww/catalogs/eqs7day-M5.xml
2883 # <item>
2884 # <geo:lat>11</geo:lat>
2885 # <geo:long>22</geo:long>
2886 #
2887 # or under geo:Point, maybe, eg. http://www.gdacs.org/xml/RSSTC.xml
2888 # <item>
2889 # <geo:Point>
2890 # <geo:lat>11</geo:lat>
2891 # <geo:long>22</geo:long>
2892 #
2893 0 foreach my $elt ($item, $item->children(qr/^geo:point$/i)) {
2894 0 my $lat = $elt->first_child_trimmed_text('geo:lat');
2895 0 ▶ if (is_non_empty ($lat)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty($lat)) 0 0 0
2896 0 return ($lat,
2897 $elt->first_child_trimmed_text('geo:long'),
2898 non_empty ($elt->first_child_trimmed_text('geo:alt')));
2899 }
2900 }
2901  
2902 # <item>
2903 # <georss:point>46.183 -123.816</georss:point>
2904 # space separator per http://www.georss.org/Encodings
2905 {
2906 0 my $str = $item->first_child_trimmed_text ('georss:point');
2907 0 ▶ if (is_non_empty ($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty($str)) 0 0 0
2908 0 return split(/\s+/, $str, 2); # no altitude
2909 }
2910 }
2911  
2912 # <item>
2913 # <statusnet:origin geo:lat="53.38297" geo:long="-1.4659"
2914 # rdf:resource="http://sws.geonames.org/2638077/">
2915 # </statusnet:origin>
2916 0 ▶ if (my $elt = $item->first_child ('statusnet:origin')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $elt = $item->first_child("statusnet:origin")) 0 0 0
2917 0 ▶ if (defined (my $lat = $elt->att('geo:lat'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $lat = $elt->att("geo:lat"))) 0 0 0
2918 0 my $long = $elt->att('geo:long');
2919 0 return ($lat, $long);
2920 }
2921 }
2922  
2923 0 return; # not found
2924 }
2925 2 @known{qw(/channel/item/geo:lat
2926 /channel/item/geo:long
2927 /channel/item/geo:alt
2928 /channel/item/geo:Point
2929 /channel/item/geo:Point/geo:lat
2930 /channel/item/geo:Point/geo:long
2931 /channel/item/georss:point
2932 /channel/item/statusnet:origin
2933 )} = ();
2934  
2935  
2936 0 ▶sub links_to_html {
Subroutine links_to_html: not called CC=6 SCAR=37.4
Pod undocumented
2937 0 ▶ @_ or return '';
Branch: 1 branch
BranchTrueFalseTotal
@_ or return "" 0 0 0
2938  
2939 # <nobr> on link lines to try to prevent the displayed URL being chopped
2940 # up by a line-wrap, which can make it hard to cut and paste. <pre> can
2941 # prevent a line wrap, but it ends up treated as starting a paragraph,
2942 # separate from the 'name' part.
2943 #
2944 0 my $str = '';
2945 0 my $sep = "\n\n<p>\n";
2946 0 foreach my $l (@_) {
2947 0 $str .= "$sep<nobr>$Entitize{$l->{'name'}}";
2948 0 $sep = "<br>\n";
2949  
2950 0 ▶ if (defined (my $uri = $l->{'uri'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $uri = $l->{"uri"})) 0 0 0
2951 0 $str .= "&nbsp;<a";
2952 0 ▶ if (defined (my $hreflang = $l->{'hreflang'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $hreflang = $l->{"hreflang"})) 0 0 0
2953 0 $str .= " hreflang=\"$Entitize{$hreflang}\"";
2954 }
2955 0 ▶ if (defined (my $type = $l->{'type'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $type = $l->{"type"})) 0 0 0
2956 0 $str .= " type=\"$Entitize{$type}\"";
2957 }
2958 0 $uri = $Entitize{$uri};
2959 0 $str .= " href=\"$uri\">$uri</a>";
2960 }
2961 0 $str .= "</nobr>\n";
2962 }
2963 0 return "$str</p>\n";
2964 }
2965  
2966 0 ▶sub links_to_text {
Subroutine links_to_text: not called CC=1 SCAR=6.9
Pod undocumented
2967 0 return join ('', map { join_non_empty (' ',
2968 $_->{'name'},
2969 0 $_->{'uri'}) . "\n" } @_);
2970 }
2971  
2972  
2973 #------------------------------------------------------------------------------
2974 # "From:" and email addresses
2975  
2976 2 ▶use constant DUMMY_EMAIL_ADDRESS => 'nobody@rss2leafnode.dummy';
Subroutine BEGIN: called CC=1 SCAR=0.0
2977  
2978 {
2979 2 my %tag_to_link_name
2980 = (author => __('Author:'),
2981 creator => __('Creator:'),
2982 contributor => __('Contributor:'),
2983 managingEditor => __('Managing Editor:'),
2984 webMaster => __('Webmaster:'),
2985 publisher => __('Publisher:'),
2986 owner => __('Owner:'),
2987 username => __('User:'),
2988 );
2989  
2990 # Return ($from, $linkhash,$linkhash,...).
2991 # $from is a string like "foo@example.com".
2992 # Multiple authors are for example "foo@example.com, quux@example.com" as
2993 # per RFC5322 email, though currently no Sender: is picked out from among
2994 # them.
2995 #
2996 # Eg. <dc:creator> appears multiple times in Nature magazine, once for
2997 # each author of an article http://www.nature.com/nature/current_issue/rss
2998 #
2999 0 ▶ sub item_to_from {
Subroutine item_to_from: not called CC=13 SCAR=52.0
Pod undocumented
3000 0 my ($self, $item) = @_;
3001 ### item_to_from() ...
3002 0 my $channel = elt_to_channel($item);
3003  
3004 # <author> is supposed to be an email address whereas <dc:creator> is
3005 # looser. The RSS recommendation is <author> when revealing an email
3006 # and <dc:creator> when hiding it.
3007 #
3008 # <slate:author> is ahead of <dc:creator> since <slate:author> has a url
3009 # attribute.
3010 #
3011 # <dc:contributor> appears in wiki: feeds as the item's author.
3012 #
3013 # <contributor> can appear multiple times in Atom item. For now prefer
3014 # to show just the primary author or authors.
3015 #
3016 0 my @from;
3017 my @links;
3018 0 foreach my $try ([$item, 'author'],
3019 [$item, 'jf:author'],
3020 [$item, 'slate:author'],
3021 [$item, 'dc:creator'],
3022 [$item, 'dc:contributor'],
3023 [$item, 'wiki:username'],
3024 [$item, 'itunes:author'],
3025  
3026 [$channel, 'author'],
3027 [$channel, 'dc:creator'],
3028 [$channel, 'itunes:author'],
3029 [$channel, 'managingEditor'],
3030 [$channel, 'webMaster'],
3031  
3032 [$item, 'dc:publisher'],
3033 [$channel, 'dc:publisher'],
3034 [$channel, 'itunes:owner'],
3035 ) {
3036 0 my ($where, $tag) = @$try;
3037 ### $tag
3038  
3039 0 ▶ if (my @elts = $item->children($tag)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@elts) = $item->children($tag)) 0 0 0
3040 0 foreach my $elt (@elts) {
3041 ### elt for From: $elt->sprint
3042 0 push @from, $self->elt_to_email($elt);
3043  
3044 # author's home page etc as a link
3045 0 ▶ if (my $uri =
Branch: 1 branch
BranchTrueFalseTotal
if (my $uri = (non_empty($elt->first_child_text("uri")) // non_empty($elt->att("url"))) // non_empty(do { my $child; $child = $elt->first_child("rdf:Description") and $child->att("link") // $child->att("rss:link") })) 0 0 0
Condition0%0/6
(non_empty($elt->first_child_text("uri")) // non_empty($elt->att("url"))) // non_empty(do { my $child; $child = $elt->first_child("rdf:Description") and $child->att("link") // $child->att("rss:link") })
l!l&&r!l&&!r
000
non_empty($elt->first_child_text("uri")) // non_empty($elt->att("url"))
l!l&&r!l&&!r
000
MC/DC0%0/3
(non_empty($elt->first_child_text("uri")) // non_empty($elt->att("url"))) // non_empty(do { my $child; $child = $elt->first_child("rdf:Description") and $child->att("link") // $child->att("rss:link") })
non_empty($elt->first_child_text("uri")) non_empty($elt->att("url")) non_empty(do { my $child; $child = $elt->first_child("rdf:Description") and $child->att("link") // $child->att("rss:link") })
Truth table0%0/4
A // B // C
A= non_empty($elt->first_child_text("uri"))B= non_empty($elt->att("url"))C= non_empty(do { my $child; $child = $elt->first_child("rdf:Description") and $child->att("link") // $child->att("rss:link") })
ABCresult
1XX1
01X1
0011
0000
3046 (# Atom
3047 # <author>
3048 # <name>Foo Bar</name>
3049 # <uri>http://some.where</uri>
3050 # </author>
3051 #
3052 non_empty ($elt->first_child_text('uri'))
3053  
3054 # slate.com
3055 # <slate:author url="">Joe Bloggs</slate:author>
3056 // non_empty ($elt->att('url'))
3057  
3058 # ModWiki dc:contributor example
3059 # <rdf:Description link="http://openwiki.com/?FooBar">
3060 # <rdf:value>Foo Bar</rdf:value>
3061 # </rdf:Description>
3062 # The text shows rss:link= and the example just link=.
3063 #
3064 // non_empty (do {
3065 0 ▶ my $child; ($child = $elt->first_child('rdf:Description'))
Condition0%0/6
($child = $elt->first_child('rdf:Description')) && ($child->att('link') // $child->att('rss:link'))
!ll&&!rl&&r
000
$child->att("link") // $child->att("rss:link")
l!l&&r!l&&!r
000
MC/DC0%0/3
($child = $elt->first_child('rdf:Description')) && ($child->att('link') // $child->att('rss:link'))
($child = $elt->first_child('rdf:Description')) $child->att("link") $child->att("rss:link")
Truth table0%0/4
A && B // C
A= ($child = $elt->first_child('rdf:Description'))B= $child->att("link")C= $child->att("rss:link")
ABCresult
0XX0
1000
11X1
1011
3066 && ($child->att('link') // $child->att('rss:link'))
3067 }))) {
3068 0 my $tag = $elt->tag;
3069 0 $tag =~ s/.*?://;
3070 push @links, { uri => URI->new($uri),
3071 0 ▶ name => ($tag_to_link_name{$tag} // "\u$tag:"),
Condition0%0/2
$tag_to_link_name{$tag} // ucfirst $tag . ':'
l!l
00
MC/DC0%0/1
$tag_to_link_name{$tag} // ucfirst $tag . ':'
$tag_to_link_name{$tag}
Truth table0%0/2
A
A= $tag_to_link_name{$tag}
Aresult
11
00
3072 download => 0,
3073 priority => -20 };
3074 }
3075 }
3076 }
3077 0 ▶ last if @from;
Branch: 1 branch
BranchTrueFalseTotal
if @from 0 0 0
3078 }
3079 0 ▶ if (! @from) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@from) 0 0 0
3080 # Atom <title> can have type="html" etc in the usual way, so render.
3081 # Hope the channel title is different from the item title.
3082 0 @from = ($self->email_format (elt_to_rendered_line
3083 ($channel->first_child('title'))));
3084 }
3085 0 ▶ if (! @from) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@from) 0 0 0
3086 0 @from = ('nobody@'.$self->uri_to_host);
3087 }
3088  
3089 ### @from
3090 0 return (join(', ',@from),
3091 @links);
3092 }
3093 2 @known{qw(/channel/author
3094 /channel/author/name --atom
3095 /channel/author/uri --atom
3096 /channel/author/url --atom-typo-maybe
3097 /channel/author/email --atom
3098 /channel/managingEditor
3099 /channel/webMaster
3100 /channel/dc:publisher
3101 /channel/dc:creator
3102 /channel/itunes:author
3103  
3104 /channel/item/author
3105 /channel/item/author/name --atom
3106 /channel/item/author/uri --atom
3107 /channel/item/author/url --atom-typo-maybe
3108 /channel/item/author/email --atom
3109 /channel/item/author/gd:extendedProperty --good-dinner
3110 /channel/item/dc:creator
3111 /channel/item/dc:publisher
3112 /channel/item/wiki:username
3113 /channel/item/itunes:author
3114 /channel/item/dc:contributor
3115 /channel/item/dc:contributor/rdf:Description
3116 /channel/item/dc:contributor/rdf:Description/rdf:value
3117 /channel/item/jf:author
3118 /channel/item/slate:author
3119  
3120 /channel/item/contributor --atom
3121 /channel/item/contributor/name
3122 /channel/item/contributor/uri
3123 /channel/item/contributor/url --atom-typo-maybe
3124 /channel/item/contributor/email
3125  
3126 /channel/item/activity:actor
3127 /channel/item/activity:verb --usually-post-or-something
3128 /channel/item/activity:object-type --is-this-anything
3129 )} = ();
3130 }
3131  
3132 # $elt is an XML::Twig::Elt
3133 # Return an email address, either just the text part of $elt or Atom
3134 # sub-elements <name> and <email>.
3135 # If $elt is empty then return an empty list.
3136 #
3137 0 ▶sub elt_to_email {
Subroutine elt_to_email: not called CC=10 SCAR=47.0
Pod undocumented
3138 0 my ($self, $elt) = @_;
3139 ### elt_to_email(): "$elt"
3140 0 ▶ return unless defined $elt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elt 0 0 0
3141  
3142 # <email> - under Atom
3143 # <itunes:email> - under <itunes:owner>
3144 0 my $email = elt_to_rendered_line ($elt->first_child(qr/^(itunes:)?email$/));
3145  
3146 # <name> - under Atom
3147 # <itunes:name> - under <itunes:owner>
3148 0 ▶ my $display = elt_to_rendered_line ($elt->first_child(qr/^(itunes:)?name$/))
Condition0%0/2
elt_to_rendered_line($elt->first_child(qr/^(itunes:)?name$/)) // ""
l!l
00
MC/DC0%0/1
elt_to_rendered_line($elt->first_child(qr/^(itunes:)?name$/)) // ""
elt_to_rendered_line($elt->first_child(qr/^(itunes:)?name$/))
Truth table0%0/2
A
A= elt_to_rendered_line($elt->first_child(qr/^(itunes:)?name$/))
Aresult
11
00
3149 // '';
3150  
3151 ### $display
3152 ### $email
3153  
3154 my $maybe = join
3155 (' ',
3156 non_empty ($elt->text_only),
3157 0 non_empty (do {
3158 # <rdf:Description><rdf:value>...</></> under dc authors etc
3159 0 ▶ my $rdfdesc; ($rdfdesc = $elt->first_child('rdf:Description'))
Condition0%0/3
($rdfdesc = $elt->first_child('rdf:Description')) && $rdfdesc->first_child_text('rdf:value')
!ll&&!rl&&r
000
MC/DC0%0/2
($rdfdesc = $elt->first_child('rdf:Description')) && $rdfdesc->first_child_text('rdf:value')
($rdfdesc = $elt->first_child('rdf:Description')) $rdfdesc->first_child_text('rdf:value')
Truth table0%0/3
A && B
A= ($rdfdesc = $elt->first_child('rdf:Description'))B= $rdfdesc->first_child_text('rdf:value')
ABresult
0X0
100
111
3160 && $rdfdesc->first_child_text('rdf:value')
3161 }));
3162  
3163 # If item has a <name> but no <email> then see if the channel owner name
3164 # is the same and use an email from there.
3165 # Eg. Skeptoid.xml podcast circa Jan 2017.
3166 0 ▶ if (defined $display && ! defined $email) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $display and not defined $email) 0 0 0
Condition0%0/3
defined $display and not defined $email
!ll&&!rl&&r
000
MC/DC0%0/2
defined $display and not defined $email
defined $display not defined $email
Truth table0%0/3
A and not(B)
A= defined $displayB= not defined $email
ABresult
0X0
100
111
3167 0 my $channel = elt_to_channel($elt);
3168 0 my ($owner, $name);
3169 0 ▶ if (($owner = $channel->first_child(qr/(itunes:)?owner/))
Branch: 1 branch
BranchTrueFalseTotal
if ($owner = $channel->first_child(qr/(itunes:)?owner/) and defined($name = elt_to_rendered_line($owner->first_child(qr/^(itunes:)?name$/))) and $name eq $display || $name eq $maybe) 0 0 0
Condition0%0/9
$owner = $channel->first_child(qr/(itunes:)?owner/) and defined($name = elt_to_rendered_line($owner->first_child(qr/^(itunes:)?name$/))) and $name eq $display || $name eq $maybe
!ll&&!rl&&r
000
$owner = $channel->first_child(qr/(itunes:)?owner/) and defined($name = elt_to_rendered_line($owner->first_child(qr/^(itunes:)?name$/)))
!ll&&!rl&&r
000
$name eq $display or $name eq $maybe
l!l&&r!l&&!r
000
MC/DC0%0/4
$owner = $channel->first_child(qr/(itunes:)?owner/) and defined($name = elt_to_rendered_line($owner->first_child(qr/^(itunes:)?name$/))) and $name eq $display || $name eq $maybe
$owner = $channel->first_child(qr/(itunes:)?owner/) defined($name = elt_to_rendered_line($owner->first_child(qr/^(itunes:)?name$/))) $name eq $display $name eq $maybe
Truth table0%0/5
A and B and C or D
A= $owner = $channel->first_child(qr/(itunes:)?owner/)B= defined($name = elt_to_rendered_line($owner->first_child(qr/^(itunes:)?name$/)))C= $name eq $displayD= $name eq $maybe
ABCDresult
0XXX0
10XX0
11000
111X1
11011
3170 && defined($name = elt_to_rendered_line ($owner->first_child(qr/^(itunes:)?name$/)))
3171 && ($name eq $display || $name eq $maybe)) {
3172 0 $email = elt_to_rendered_line ($owner->first_child(qr/^(itunes:)?email$/));
3173 }
3174 ### channel: "$channel"
3175 ### owner: "$owner"
3176 ### $name
3177 ### $display
3178 }
3179  
3180 0 return $self->email_format_maybe ($maybe, $display, $email);
3181 }
3182  
3183 # $mailbox_re is a mailbox with domain, like "foo@example.com"
3184 # Allows no dots like "foo@localhost".
3185 # Allows dashes like "www-something@example.com".
3186 #
3187 # $mailbox_with_comment_re allows an optional paren comment part like
3188 # "foo@example.com (Foo)"
3189 #
3190 # cf Email::Address $addr_spec, but its version 1.890 loosened to allow a
3191 # domain-less bare "foo", which is no good
3192 #
3193 2 my $words_with_dots_re = qr/[[:word:]-]+(\.[[:word:]-]+)*/;
3194 2 my $mailbox_re = qr/$words_with_dots_re\@$words_with_dots_re/o;
3195 2 my $mailbox_with_comment_re = qr/$mailbox_re(\s*\([^\)]*\))?/os;
3196  
3197 # $maybe is some free-form author part possibly including a foo@example.com
3198 # $display is a display part for the email like "Foo", possibly empty ""
3199 # $email is a mailbox "foo@example.com", or undef
3200 # return an rfc822 "Foo <foo@example.com>"
3201 #
3202 0 ▶sub email_format_maybe {
Subroutine email_format_maybe: not called CC=9 SCAR=45.0
Pod undocumented
3203 0 my ($self, $maybe, $display, $email) = @_;
3204 ### email_format_maybe() start
3205 ### $maybe
3206 ### $display
3207 ### $email
3208  
3209 # look also at $display the same in case Atom no <email> but a <name>
3210 # which is a mailbox and can be corrected,
3211 # eg. http://www.weather.gov/alerts-beta/hi.php?x=0
3212 #
3213 # Or $maybe full email like
3214 0 ▶ if (is_empty($email)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_empty($email)) 0 0 0
3215 0 foreach ($maybe, $display) {
3216  
3217 0 ▶ if (/^\s*(mailto:)?($mailbox_with_comment_re)\s*$/o) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^\s*(mailto:)?($mailbox_with_comment_re)\s*$/o) { } 0 0 0
elsif (/(.*)\((mailto:)?($mailbox_re)\)\s*$/o or /(.*)<(mailto:)?($mailbox_re)>\s*$/o) { } 0 0 0
3218 ### maybe or display is a mailbox
3219 # "foo@example.com"
3220 # "mailto:foo@example.com"
3221 # "foo@example.com (Foo)"
3222 0 $email = $2;
3223 0 undef $_;
3224 0 last;
3225  
3226 ▶ } elsif (/(.*)\((mailto:)?($mailbox_re)\)\s*$/o
Condition0%0/3
/(.*)\((mailto:)?($mailbox_re)\)\s*$/o or /(.*)<(mailto:)?($mailbox_re)>\s*$/o
l!l&&r!l&&!r
000
MC/DC0%0/2
/(.*)\((mailto:)?($mailbox_re)\)\s*$/o or /(.*)<(mailto:)?($mailbox_re)>\s*$/o
/(.*)\((mailto:)?($mailbox_re)\)\s*$/o /(.*)<(mailto:)?($mailbox_re)>\s*$/o
Truth table0%0/3
A or B
A= /(.*)\((mailto:)?($mailbox_re)\)\s*$/oB= /(.*)<(mailto:)?($mailbox_re)>\s*$/o
ABresult
1X1
011
000
3227 || /(.*)<(mailto:)?($mailbox_re)>\s*$/o) {
3228 ### maybe or display part is display plus mailbox
3229 # "Foo (mailto:foo@example.com)"
3230 # "Foo (foo@example.com)"
3231 # "Foo <foo@example.com>"
3232 #
3233 0 $_ = $1;
3234 0 $email = $3;
3235 0 last;
3236 }
3237 }
3238 }
3239  
3240 0 ▶ $display .= ' '.($maybe//'');
Condition0%0/2
$maybe // ""
l!l
00
MC/DC0%0/1
$maybe // ""
$maybe
Truth table0%0/2
A
A= $maybe
Aresult
11
00
3241 0 my $ret;
3242 0 ▶ if (is_empty($email) && $display =~ /^$mailbox_re$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_empty($email) and $display =~ /^$mailbox_re$/o) { } 0 0 0
Condition0%0/3
is_empty($email) and $display =~ /^$mailbox_re$/o
!ll&&!rl&&r
000
MC/DC0%0/2
is_empty($email) and $display =~ /^$mailbox_re$/o
is_empty($email) $display =~ /^$mailbox_re$/o
Truth table0%0/3
A and B
A= is_empty($email)B= $display =~ /^$mailbox_re$/o
ABresult
0X0
100
111
3243 # display or maybe is a "foo@example.com" or "foo@example.com (Foo)",
3244 # return it as-is, in particular leave it in "(Foo)" style comment
3245 0 $ret = $display;
3246 } else {
3247 0 $ret = $self->email_format ($display, $email);
3248 }
3249  
3250 # Collapse whitespace against possible tabs and newlines in an <author> as
3251 # from googlegroups for instance. MIME::Entity seems to collapse
3252 # newlines, but not tabs.
3253 0 return non_empty (collapse_whitespace ($ret));
3254 }
3255  
3256 # $display is a display part for the email "Foo", possibly empty ""
3257 # $email is a mailbox "foo@example.com", or undef or empty ""
3258 # return an rfc822 "Foo <foo@example.com>"
3259 #
3260 0 ▶sub email_format {
Subroutine email_format: not called CC=4 SCAR=30.0
Pod undocumented
3261 0 my ($self, $display, $email) = @_;
3262 ### $display
3263 0 $display = Text::Trim::trim($display);
3264 0 $email = Text::Trim::trim($email);
3265 0 ▶ if (is_empty($display)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_empty($display)) 0 0 0
3266 0 ▶ if (is_empty($email)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_empty($email)) { } 0 0 0
3267 0 return;
3268 } else {
3269 0 return $email;
3270 }
3271 }
3272 0 ▶ if (is_empty($email)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_empty($email)) { } 0 0 0
3273 # think can't have empty <> or omitted, otherwise the quoted part is
3274 # still parsed as an address, certainly it's not rfc822 compliant to
3275 # omit
3276 0 $email = 'nobody@'.$self->uri_to_host;
3277 } else {
3278 0 $email = $email;
3279 }
3280 0 return email_phrase_quote_maybe($display) . " <$email>";
3281 }
3282  
3283 # return $str with quotes like "Foo Bar" if it needs them to go in an email
3284 # display part
3285 0 ▶sub email_phrase_quote_maybe {
Subroutine email_phrase_quote_maybe: not called CC=3 SCAR=24.8
Pod undocumented
3286 0 my ($str) = @_;
3287 0 ▶ return if ! defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 0 0
3288  
3289 # RFC2822 "atext" characters, with "-" last
3290 0 ▶ if ($str =~ m<[^[:alnum:][:space:]!#\$%&'*+/=?^_`{|}~-]>) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ m[[^[:alnum:][:space:]!#\$%&'*+/=?^_`{|}~-]]) { } 0 0 0
3291 # strange chars, need to quote
3292 0 return email_phrase_quote($str);
3293 } else {
3294 # alphanumeric and whitespace, no quotes
3295 0 return $str;
3296 }
3297 }
3298 0 ▶sub email_phrase_quote {
Subroutine email_phrase_quote: not called CC=2 SCAR=17.9
Pod undocumented
3299 0 my ($str) = @_;
3300 0 ▶ return if ! defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 0 0
3301 0 $str =~ s/^"(.*)"$/$1/; # strip existing quotes
3302 0 $str =~ s/(["\\])/\\$1/g; # escape internal quotes and backslashes
3303 0 return "\"$str\"";
3304 }
3305  
3306  
3307 #------------------------------------------------------------------------------
3308 # rss_newest_only
3309  
3310 {
3311 2 my %multiplier = (minute => 60,
3312 hour => 3600,
3313 day => 86400,
3314 week => 86400 * 7,
3315 month => 365.25 * 86400 / 12,
3316 year => 365.25 * 86400,
3317 );
3318 # return a target time_t, or undef
3319 0 ▶ sub rss_newest_only_timet {
Subroutine rss_newest_only_timet: not called CC=3 SCAR=24.8
Pod undocumented
3320 0 my ($self) = @_;
3321
3322 0 ▶ if (defined (my $str = $self->{'rss_newest_only'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $str = $self->{"rss_newest_only"})) 0 0 0
3323 0 ▶ if ($str =~ /^\s*(\d+)\s*(minute|hour|day|week|month|year)s?\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^\s*(\d+)\s*(minute|hour|day|week|month|year)s?\s*$/) 0 0 0
3324 0 return time() - $1*$multiplier{$2};
3325 }
3326 }
3327 0 return undef;
3328 }
3329 }
3330  
3331 # return a number, or undef
3332 2 ▶sub rss_newest_only_count {
Subroutine rss_newest_only_count: not called CC=3 SCAR=22.6
Pod undocumented
3333 0 my ($self) = @_;
3334 0 ▶ if (defined (my $str = $self->{'rss_newest_only'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $str = $self->{"rss_newest_only"})) 0 0 0
3335 0 ▶ if (Scalar::Util::looks_like_number($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($str)) 0 0 0
3336 ### rss_newest_only number: $str
3337 0 return $str;
3338 }
3339 }
3340 0 return undef;
3341 }
3342  
3343 # return @items restricted or filtered by rss_newest_only
3344 0 ▶sub rss_newest_only_items {
Subroutine rss_newest_only_items: not called CC=8 SCAR=42.8
Pod undocumented
3345 0 my ($self, @items) = @_;
3346  
3347 0 ▶ if (defined (my $count = $self->rss_newest_only_count)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $count = $self->rss_newest_only_count)) 0 0 0
3348 0 ▶ if ($count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 0) 0 0 0
3349 # rss_newest_only=>0 means don't apply a newest
3350 0 return @items;
3351 }
3352 0 my $before = scalar(@items);
3353 0 require Sort::Key::Top;
3354 0 ▶ @items = Sort::Key::Top::rnkeytop (sub { $self->item_to_timet($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
3355 0 $count, @items);
3356  
3357 0 my $after = scalar(@items);
3358 0 ▶ if ($before != $after) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before != $after) 0 0 0
3359 0 $self->verbose (1, " rss_newest_only reduce by count from $before items to $after items");
3360 }
3361 0 return @items;
3362 }
3363  
3364 0 ▶ if (defined (my $target_timet = $self->rss_newest_only_timet)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $target_timet = $self->rss_newest_only_timet)) 0 0 0
3365 0 my $before = scalar(@items);
3366 0 @items = grep { my $got_timet = $self->item_to_timet($_);
3367 0 ▶ ! defined $got_timet || $got_timet >= $target_timet }
Condition0%0/3
!defined($got_timet) || $got_timet >= $target_timet
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($got_timet) || $got_timet >= $target_timet
!defined($got_timet) $got_timet >= $target_timet
Truth table0%0/3
not(A) || B
A= !defined($got_timet)B= $got_timet >= $target_timet
ABresult
1X1
011
000
3368 @items;
3369 0 my $after = scalar(@items);
3370 0 ▶ if ($before != $after) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before != $after) 0 0 0
3371 0 $self->verbose (1, " rss_newest_only reduce by age from $before to $after items");
3372 }
3373 0 return @items;
3374 }
3375  
3376 0 ▶ if (defined (my $str = $self->{'rss_newest_only'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $str = $self->{"rss_newest_only"})) 0 0 0
3377 0 die "rss2leafnode: unrecognised rss_newest_only: ",$str;
3378 }
3379 0 return @items;
3380 }
3381  
3382  
3383 #------------------------------------------------------------------------------
3384 # fetch RSS
3385  
3386 2 my $map_xmlns
3387 = {
3388 'http://purl.org/rss/1.0/' => 'rss',
3389 'http://www.w3.org/2005/Atom' => 'atom',
3390 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',
3391 'http://purl.org/rss/1.0/modules/content/' => 'content',
3392 'http://purl.org/rss/1.0/modules/slash/' => 'slash',
3393 'http://purl.org/rss/1.0/modules/syndication/' => 'syn',
3394 'http://purl.org/syndication/thread/1.0' => 'thr',
3395 'http://wellformedweb.org/CommentAPI/' => 'wfw',
3396 'http://www.w3.org/1999/xhtml' => 'xhtml',
3397 'http://www.itunes.com/dtds/podcast-1.0.dtd' => 'itunes',
3398 'http://rssnamespace.org/feedburner/ext/1.0' => 'feedburner',
3399 'http://www.helex.gr/helex-schemas/xsd/CompanyDataAtomAttributes-v1.xsd'
3400 => 'hlxcd',
3401  
3402 # http://www.prismstandard.org/specifications/2.0/PRISM_prism_namespace_2.0.pdf
3403 'http://prismstandard.org/namespaces/basic/2.0/' => 'prism',
3404  
3405 # http://www.rssboard.org/media-rss
3406 'http://search.yahoo.com/mrss' => 'media',
3407  
3408 'http://www.w3.org/2003/01/geo/wgs84_pos#' => 'geo',
3409 'http://www.georss.org/georss' => 'georss',
3410 'http://www.pheedo.com/namespace/pheedo' => 'pheedo',
3411 'http://api.twitter.com' => 'twitter',
3412 'http://xmlns.com/foaf/0.1/' => 'foaf',
3413 'http://status.net/ont/' => 'statusnet',
3414 'http://rdfs.org/sioc/ns#' => 'sioc',
3415 'http://www.slate.com' => 'slate',
3416 'http://activitystrea.ms/spec/1.0/' => 'activity',
3417 'http://ostatus.org/schema/1.0' => 'ostatus',
3418  
3419 # http://tools.ietf.org/html/draft-snell-atompub-feed-index-10
3420 'http://purl.org/atompub/rank/1.0' => 're',
3421  
3422 # per http://docs.jivesoftware.com/latest/documentation/rss.html#output
3423 'http://www.jivesoftware.com/xmlns/jiveforums/rss' => 'jf',
3424  
3425 # these two are different, but treat the same for now
3426 'http://backend.userland.com/creativeCommonsRssModule'=>'creativeCommons',
3427 'http://creativecommons.org/ns#' =>'creativeCommons',
3428  
3429 # Common Alerts Protocol
3430 'urn:oasis:names:tc:emergency:cap:1.1' => 'cap',
3431  
3432 # central bank exchange rates format,
3433 # spec http://www.cbwiki.net/wiki/index.php/RSS-CBMain
3434 # eg. RBA http://www.rba.gov.au/rss/rss-cb-exchange-rates.xml
3435 'http://www.cbwiki.net/wiki/index.php/Specification_1.1' => 'cb',
3436  
3437 # earthquakes
3438 # eg. http://earthquake.usgs.gov/earthquakes/shakemap/rss.xml
3439 'http://earthquake.usgs.gov/rss/1.0/' => 'eq',
3440  
3441 'http://purl.org/dc/elements/1.1/' => 'dc',
3442 'http://purl.org/dc/terms/' => 'dcterms',
3443  
3444 # purl.org might be supposed to be the home for wiki:, but it's a 404
3445 # and usemod.com suggests its page instead
3446 # Spec at http://www.meatballwiki.org/wiki/ModWiki
3447 'http://purl.org/rss/1.0/modules/wiki/' => 'wiki',
3448 'http://www.usemod.com/cgi-bin/mb.pl?ModWiki' => 'wiki',
3449  
3450 # not sure if this is supposed to be necessary, but without it
3451 # "xml:lang" attributes are turned into "lang"
3452 'http://www.w3.org/XML/1998/namespace' => 'xml',
3453 };
3454  
3455 1 ▶sub twig_parse {
Subroutine twig_parse: called CC=12 SCAR=49.6
Pod undocumented
3456 1 my ($self, $xml) = @_;
3457 ### twig_parse() ...
3458  
3459 # default "discard_spaces" chucks leading and trailing space on content,
3460 # which is usually a good thing
3461 #
3462 1 require XML::Twig;
3463 0 XML::Twig->VERSION('3.34'); # for att_exists()
3464 0 my $twig = XML::Twig->new (map_xmlns => $map_xmlns,
3465 pretty_print => 'wrapped');
3466 0 $twig->safe_parse ($xml);
3467 0 my $err = $@;
3468 ### $err
3469  
3470 # Try to fix bad non-ascii chars by putting it through Encode::from_to().
3471 # Encode::FB_DEFAULT substitutes U+FFFD when going to unicode, or question
3472 # mark "?" going to non-unicode. Mozilla does some sort of similar
3473 # liberal byte interpretation so as to at least display something from a
3474 # dodgy feed.
3475 #
3476 0 ▶ if ($err && $err =~ /not well-formed \(invalid token\) at (line \d+, column \d+, byte (\d+))/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err and $err =~ /not well-formed \(invalid token\) at (line \d+, column \d+, byte (\d+))/) 0 0 0
Condition0%0/3
$err and $err =~ /not well-formed \(invalid token\) at (line \d+, column \d+, byte (\d+))/
!ll&&!rl&&r
000
MC/DC0%0/2
$err and $err =~ /not well-formed \(invalid token\) at (line \d+, column \d+, byte (\d+))/
$err $err =~ /not well-formed \(invalid token\) at (line \d+, column \d+, byte (\d+))/
Truth table0%0/3
A and B
A= $errB= $err =~ /not well-formed \(invalid token\) at (line \d+, column \d+, byte (\d+))/
ABresult
0X0
100
111
3477 0 my $where = $1;
3478 0 my $byte = ord(substr($xml,$2,1));
3479 0 ▶ if ($byte >= 128) {
Branch: 1 branch
BranchTrueFalseTotal
if ($byte >= 128) 0 0 0
3480 0 ▶ my $charset = $twig->encoding // 'utf-8';
Condition0%0/2
$twig->encoding // "utf-8"
l!l
00
MC/DC0%0/1
$twig->encoding // "utf-8"
$twig->encoding
Truth table0%0/2
A
A= $twig->encoding
Aresult
11
00
3481 0 $self->verbose (1, sprintf ("parse error, attempt re-code $charset for byte 0x%02X\n", $byte));
3482 0 require Encode;
3483 0 my $recoded_xml = $xml;
3484 0 Encode::from_to($recoded_xml, $charset, $charset, Encode::FB_DEFAULT());
3485  
3486 0 $twig = XML::Twig->new (map_xmlns => $map_xmlns);
3487 0 ▶ if ($twig->safe_parse ($recoded_xml)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($twig->safe_parse($recoded_xml)) 0 0 0
3488 0 $twig->root->set_att('rss2leafnode:fixup',
3489 "Recoded bad bytes to charset $charset");
3490 print __x("Feed {url}\n recoded {charset} to parse, expect substitutions for bad non-ascii\n ({where})\n",
3491 0 url => $self->{'uri'},
3492 charset => $charset,
3493 where => $where);
3494 0 undef $err;
3495 }
3496 }
3497 }
3498  
3499 # Or attempt to put it through XML::Liberal, if available.
3500 #
3501 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
3502 0 my $liberal_xml = $self->xml_liberal_correction($xml);
3503 0 ▶ if (defined $liberal_xml) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $liberal_xml) 0 0 0
3504 ### reparse xml liberal fixup with twig ...
3505 0 $twig = XML::Twig->new (map_xmlns => $map_xmlns);
3506 0 ▶ if ($twig->safe_parse ($liberal_xml)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($twig->safe_parse($liberal_xml)) 0 0 0
3507 ### now ok ...
3508 0 $err = Text::Trim::trim($err);
3509 0 $twig->root->set_att('rss2leafnode:fixup',
3510 "XML::Liberal fixed: {error}",
3511 error => $err);
3512 print __x("Feed {url}\n parse error: {error}\n continuing with repairs by XML::Liberal\n",
3513 0 url => $self->{'uri'},
3514 error => $err);
3515 0 undef $err;
3516 }
3517 }
3518 ### now err: $err
3519 }
3520  
3521 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
3522 # XML::Parser seems to stick some spurious leading whitespace on the error
3523 0 $err = Text::Trim::trim($err);
3524  
3525 $self->verbose (1, __x("Parse error on URL {url}\n{error}",
3526 0 url => $self->{'uri'},
3527 error => $err));
3528 0 return (undef, $err);
3529 }
3530  
3531 # Strip any explicit "rss:" or "atom:" namespace down to bare part.
3532 # Should be unambiguous and is easier than giving tag names both with and
3533 # without the namespace. Undocumented set_ns_as_default() might do this
3534 # ... or might not.
3535 #
3536 0 my $root = $twig->root;
3537 0 App::RSS2Leafnode::XML::Twig::Other::elt_tree_strip_prefix ($root, 'atom');
3538 0 App::RSS2Leafnode::XML::Twig::Other::elt_tree_strip_prefix ($root, 'rss');
3539  
3540 # somehow map_xmlns mangles default attributes like "decimals=...", prefer
3541 # to see them without rss: or atom: -- maybe
3542 # foreach my $child ($root->descendants_or_self) {
3543 # foreach my $attname ($child->att_names) {
3544 # if ($attname =~ /^(atom|rss):(.*)/) {
3545 # $child->change_att_name($attname, $2);
3546 # }
3547 # }
3548 # }
3549  
3550 ### add xml base
3551 0 ▶ if (defined $self->{'uri'} && ! $root->att_exists('xml:base')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"uri"} and not $root->att_exists("xml:base")) 0 0 0
Condition0%0/3
defined $self->{"uri"} and not $root->att_exists("xml:base")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"uri"} and not $root->att_exists("xml:base")
defined $self->{"uri"} not $root->att_exists("xml:base")
Truth table0%0/3
A and not(B)
A= defined $self->{"uri"}B= not $root->att_exists("xml:base")
ABresult
0X0
100
111
3552 0 $root->set_att ('xml:base', $self->{'uri'});
3553 }
3554  
3555 ### success
3556 0 return ($twig, undef);
3557 }
3558  
3559 0 ▶sub elt_to_channel {
Subroutine elt_to_channel: not called CC=3 SCAR=24.8
Pod undocumented
3560 0 my ($elt) = @_;
3561 # parent for RSS or Atom, but sibling "channel" for RDF
3562 0 ▶ while ($elt->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->parent) 0 0 0
3563 0 $elt = $elt->parent;
3564 }
3565 0 ▶ return ($elt->first_child('channel')
Condition0%0/3
$elt->first_child("channel") // $elt
l!l&&r!l&&!r
000
MC/DC0%0/2
$elt->first_child("channel") // $elt
$elt->first_child("channel") $elt
Truth table0%0/3
A // B
A= $elt->first_child("channel")B= $elt
ABresult
1X1
011
000
3566 // $elt);
3567 }
3568  
3569 # return a Message-ID string for this $item coming from $self->{'uri'}
3570 #
3571 0 ▶sub item_to_msgid {
Subroutine item_to_msgid: not called CC=8 SCAR=42.8
Pod undocumented
3572 0 my ($self, $item) = @_;
3573  
3574 0 ▶ if (is_non_empty (my $id = $item->first_child_text('id'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty(my $id = $item->first_child_text("id"))) 0 0 0
3575 # Atom <id> is supposed to be a url
3576 0 return $self->url_to_msgid ($id, $item->first_child_text('updated'));
3577 }
3578  
3579 0 my $guid;
3580 0 my $isPermaLink = 0;
3581 0 ▶ if (my $elt = $item->first_child('guid')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $elt = $item->first_child("guid")) 0 0 0
3582 # ignore empty <guid isPermaLink="false"/> seen once from
3583 # http://abc.net.au/rn/podcast/feeds/sci.xml
3584 0 ▶ if (is_non_empty (my $str = collapse_whitespace ($elt->text))) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty(my $str = collapse_whitespace($elt->text))) 0 0 0
3585 0 $guid = $str;
3586 0 ▶ $isPermaLink = (lc($elt->att('isPermaLink') // 'true') eq 'true');
Condition0%0/2
$elt->att("isPermaLink") // "true"
l!l
00
MC/DC0%0/1
$elt->att("isPermaLink") // "true"
$elt->att("isPermaLink")
Truth table0%0/2
A
A= $elt->att("isPermaLink")
Aresult
11
00
3587 }
3588 }
3589  
3590 0 ▶ if ($isPermaLink) { # <guid isPermaLink="true">
Branch: 1 branch
BranchTrueFalseTotal
if ($isPermaLink) 0 0 0
3591 0 return $self->url_to_msgid ($guid);
3592 }
3593 0 ▶ if (my $link = item_yahoo_permalink ($item)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $link = item_yahoo_permalink($item)) 0 0 0
3594 0 return $self->url_to_msgid ($link);
3595 }
3596 0 ▶ if (defined $guid) { # <guid isPermaLink="false">
Branch: 1 branch
BranchTrueFalseTotal
if (defined $guid) 0 0 0
3597 0 return $self->url_to_msgid ($self->{'uri'}, $guid);
3598 }
3599  
3600 # nothing in the item, use the feed url and MD5 of some fields which
3601 # will hopefully distinguish it from other items at this url
3602 0 $self->verbose (2, ' msgid from MD5');
3603 return $self->url_to_msgid
3604 ($self->{'uri'},
3605 md5_of_utf8 (join_non_empty ('',
3606 0 map {$item->first_child_text($_)}
3607 qw(title
3608 author
3609 dc:creator
3610 description
3611 content
3612 link
3613 pubDate
3614 published
3615 updated
3616 ))));
3617 }
3618 # FIXME: is <wordzilla:id> anything that can be used ?
3619 # <slate:id> not needed, its feed has a guid.
3620 2 @known{qw(/channel/item/guid
3621 /channel/item/id
3622 /channel/item/wordzilla:id
3623 /channel/item/slate:id
3624 )} = ();
3625  
3626 # Return an "In-Reply-To:" value for $item, being a space-separated list of
3627 # Message-ID strings including angles <>, or undef if nothing. The message
3628 # ids match up to an Atom <id> element in a parent item.
3629 #
3630 # RFC 4685 has <thr:in-reply-to>. There can be multiple such elements if a
3631 # reply to multiple originals.
3632 #
3633 # Eg. comment feeds under
3634 # http://wickedgooddinner.blogspot.com/feeds/posts/default
3635 #
3636 0 ▶sub item_to_in_reply_to {
Subroutine item_to_in_reply_to: not called CC=6 SCAR=37.4
Pod undocumented
3637 0 my ($self, $item) = @_;
3638  
3639 0 my @ids;
3640 0 foreach my $elt ($item->children('thr:in-reply-to')) {
3641 0 ▶ my $ref = ($elt->att('thr:ref')
Condition0%0/8
(($elt->att("thr:ref") // $elt->att("ref")) // $elt->att("atom:ref")) // (next)
l!l
00
($elt->att("thr:ref") // $elt->att("ref")) // $elt->att("atom:ref")
l!l&&r!l&&!r
000
$elt->att("thr:ref") // $elt->att("ref")
l!l&&r!l&&!r
000
MC/DC0%0/3
(($elt->att("thr:ref") // $elt->att("ref")) // $elt->att("atom:ref")) // (next)
$elt->att("thr:ref") $elt->att("ref") $elt->att("atom:ref")
Truth table0%0/4
A // B // C
A= $elt->att("thr:ref")B= $elt->att("ref")C= $elt->att("atom:ref")
ABCresult
1XX1
01X1
0011
0000
3642 // $elt->att('ref')
3643 // $elt->att('atom:ref') # comes out atom: under map_xmlns ...
3644 // next);
3645 # probably shouldn't be relative actually ...
3646 0 $ref = App::RSS2Leafnode::XML::Twig::Other::elt_xml_based_uri ($elt, $ref);
3647 0 push @ids, $self->url_to_msgid ($ref);
3648 }
3649 0 ▶ if (@ids) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ids) { } 0 0 0
3650 0 return join (' ', @ids);
3651 } else {
3652 0 return undef;
3653 }
3654 }
3655 2 @known{qw(/channel/item/thr:in-reply-to
3656 )} = ();
3657  
3658 # Return a string of comma separated keywords per RFC1036 and RFC2822.
3659 #
3660 # RSS <category>Foo</category> is often present with no other keywords, work
3661 # that in as a bit of a fallback, being better than nothing for
3662 # classification.
3663 #
3664 # Atom <category term="key" label="human readable"/> with the "label"
3665 # attribute being the displayable part. Have seen only the "term" attribute
3666 # though.
3667 #
3668 # <itunes:category> might be covered by <itunes:keywords> anyway, but work
3669 # it in for more classification for now. Can have child <itunes:category>
3670 # elements as sub-categories, but don't worry about them, haven't seen any
3671 # real ones, only the sample at
3672 # http://www.apple.com/itunes/podcasts/specs.html#example
3673 #
3674 # <slash:section> is slightly borderline. Sometimes it's a repeat of
3675 # <dc:subject>, which is fine. Sometimes it's just "news" which is not
3676 # particularly informative.
3677 #
3678 # <cap:category> is "Geo", "Met", "Safety", "Fire" etc. Not sure if it
3679 # should be in the keywords if it's also in the body text, but at least
3680 # offers a bit of classification in the headers.
3681 #
3682 # <dc:subject> is supposed to be from a "restricted vocabulary" so might
3683 # want a bit of decoding. Not much used, but for instance
3684 # http://www.gdacs.org/xml/RSSTC.xml
3685 # http://earthquake.usgs.gov/eqcenter/recenteqsww/catalogs/eqs7day-M5.xml
3686 #
3687 # How much value is there in the channel keywords?
3688 #
3689 {
3690 2 my $re = qr/^(category
3691 |itunes:category
3692 |cap:category
3693 |itunes:keywords
3694 |media:keywords
3695 |dc:subject
3696 |slash:section
3697 |slate:topic
3698 )$/x;
3699 0 ▶ sub item_to_keywords {
Subroutine item_to_keywords: not called CC=7 SCAR=40.3
Pod undocumented
3700 0 my ($self, $item) = @_;
3701 0 my $channel = elt_to_channel($item);
3702  
3703 return join_non_empty
3704 (', ',
3705 List::MoreUtils::uniq
3706 0 (map { collapse_whitespace($_) }
3707 0 map { split /,/ }
3708 0 ▶ map { ($_->att('text') # itunes:category
Condition0%0/18
((((($_->att("text") // $_->att("itunes:text")) // $_->att("atom:label")) // $_->att("label")) // $_->att("atom:term")) // $_->att("term")) // $_->text
l!l&&r!l&&!r
000
(((($_->att("text") // $_->att("itunes:text")) // $_->att("atom:label")) // $_->att("label")) // $_->att("atom:term")) // $_->att("term")
l!l&&r!l&&!r
000
((($_->att("text") // $_->att("itunes:text")) // $_->att("atom:label")) // $_->att("label")) // $_->att("atom:term")
l!l&&r!l&&!r
000
(($_->att("text") // $_->att("itunes:text")) // $_->att("atom:label")) // $_->att("label")
l!l&&r!l&&!r
000
($_->att("text") // $_->att("itunes:text")) // $_->att("atom:label")
l!l&&r!l&&!r
000
$_->att("text") // $_->att("itunes:text")
l!l&&r!l&&!r
000
MC/DC0%0/7
((((($_->att("text") // $_->att("itunes:text")) // $_->att("atom:label")) // $_->att("label")) // $_->att("atom:term")) // $_->att("term")) // $_->text
$_->att("text") $_->att("itunes:text") $_->att("atom:label") $_->att("label") $_->att("atom:term") $_->att("term") $_->text
Truth table0%0/8
A // B // C // D // E // F // G
A= $_->att("text")B= $_->att("itunes:text")C= $_->att("atom:label")D= $_->att("label")E= $_->att("atom:term")F= $_->att("term")G= $_->text
ABCDEFGresult
1XXXXXX1
01XXXXX1
001XXXX1
0001XXX1
00001XX1
000001X1
00000011
00000000
3709 // $_->att('itunes:text') # itunes:category
3710 // $_->att('atom:label') # atom <category>
3711 // $_->att('label') # atom <category>
3712 // $_->att('atom:term') # atom <category>, if no "label"
3713 // $_->att('term') # atom <category>, if no "label"
3714 // $_->text) } # other
3715 ($item->children($re),
3716 $channel->children($re),
3717 # <cb:news> etc sub-element <cb:category>
3718 0 map {$_->children('cb:keyword')} $item->children,
3719 )));
3720 }
3721 # maybe could show <slate:section> like "Health and Science" as a keyword
3722 # too, for now just omit
3723 2 @known{qw(/channel/category
3724 /channel/itunes:category
3725 /channel/itunes:category/itunes:category
3726  
3727 /channel/item/category
3728 /channel/item/itunes:keywords
3729 /channel/item/media:keywords
3730 /channel/item/slash:section
3731 /channel/item/slate:topic
3732 /channel/item/slate:section
3733 )} = ();
3734 }
3735  
3736 {
3737 # Feturn a string for the "Importance:" header of RFC 1911, RFC 2156
3738 # voice and X.400 messaging. Possible values 'high', 'normal', 'low'.
3739 # 'normal' is the header default, return undef in that case in the
3740 # interests of not junking up headers with defaults
3741 #
3742 2 my %cap_severity_high = (extreme => 1,
3743 severe => 1);
3744 2 my %cap_severity_normal = (moderate => 1);
3745 2 my %cap_severity_low = (minor => 1);
3746  
3747 0 ▶ sub item_to_importance {
Subroutine item_to_importance: not called CC=8 SCAR=42.8
Pod undocumented
3748 0 my ($self, $item) = @_;
3749  
3750 0 ▶ my $cap_severity = lc($item->first_child_trimmed_text('cap:severity')
Condition0%0/2
$item->first_child_trimmed_text("cap:severity") // ""
l!l
00
MC/DC0%0/1
$item->first_child_trimmed_text("cap:severity") // ""
$item->first_child_trimmed_text("cap:severity")
Truth table0%0/2
A
A= $item->first_child_trimmed_text("cap:severity")
Aresult
11
00
3751 // '');
3752 0 ▶ my $wiki_importance = ($item->first_child_trimmed_text('wiki:importance')
Condition0%0/2
$item->first_child_trimmed_text("wiki:importance") // ""
l!l
00
MC/DC0%0/1
$item->first_child_trimmed_text("wiki:importance") // ""
$item->first_child_trimmed_text("wiki:importance")
Truth table0%0/2
A
A= $item->first_child_trimmed_text("wiki:importance")
Aresult
11
00
3753 // '');
3754 0 ▶ if ($cap_severity) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cap_severity) 0 0 0
3755 0 $self->verbose (2, " CAP severity: ",$cap_severity);
3756 0 $self->verbose (2, " Wiki importance: ",$wiki_importance);
3757 }
3758  
3759 0 ▶ if ($cap_severity_high{$cap_severity}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cap_severity_high{$cap_severity}) 0 0 0
3760 0 return 'high';
3761 }
3762 0 ▶ if ($cap_severity_normal{$cap_severity}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cap_severity_normal{$cap_severity}) 0 0 0
3763 0 return undef; # default "normal"
3764 }
3765 0 ▶ if ($cap_severity_low{$cap_severity}
Branch: 1 branch
BranchTrueFalseTotal
if ($cap_severity_low{$cap_severity} or $wiki_importance eq "minor") 0 0 0
Condition0%0/3
$cap_severity_low{$cap_severity} or $wiki_importance eq "minor"
l!l&&r!l&&!r
000
MC/DC0%0/2
$cap_severity_low{$cap_severity} or $wiki_importance eq "minor"
$cap_severity_low{$cap_severity} $wiki_importance eq "minor"
Truth table0%0/3
A or B
A= $cap_severity_low{$cap_severity}B= $wiki_importance eq "minor"
ABresult
1X1
011
000
3766 || $wiki_importance eq 'minor') {
3767 0 return 'low';
3768 }
3769 0 return undef; # unknown
3770 }
3771 2 @known{qw(/channel/item/wiki:importance
3772 )} = ();
3773 }
3774 {
3775 # Return a string for the "Priority:" header of RFC 1327, RFC 2156.
3776 # Possible values 'urgent', 'normal', 'non-urgent'.
3777 # 'normal' is the header default, return undef in that case in the
3778 # interests of not junking up headers with defaults
3779 #
3780 # <cap:urgency> is "Immediate", "Expected", "Future", "Past", "Unknown",
3781 # for when response action should be taken. Is the <cap:severity> the
3782 # better indicator of transmission priority?
3783 #
3784 2 my %cap_severity_urgent = (extreme => 1,
3785 severe => 1);
3786 2 my %cap_severity_normal = (moderate => 1);
3787  
3788 0 ▶ sub item_to_priority {
Subroutine item_to_priority: not called CC=4 SCAR=30.0
Pod undocumented
3789 0 my ($self, $item) = @_;
3790  
3791 0 ▶ my $cap_severity = lc($item->first_child_trimmed_text('cap:severity')
Condition0%0/2
$item->first_child_trimmed_text("cap:severity") // ""
l!l
00
MC/DC0%0/1
$item->first_child_trimmed_text("cap:severity") // ""
$item->first_child_trimmed_text("cap:severity")
Truth table0%0/2
A
A= $item->first_child_trimmed_text("cap:severity")
Aresult
11
00
3792 // '');
3793  
3794 0 ▶ if ($cap_severity_urgent{$cap_severity}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cap_severity_urgent{$cap_severity}) 0 0 0
3795 0 return 'urgent';
3796 }
3797 0 ▶ if ($cap_severity_normal{$cap_severity}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cap_severity_normal{$cap_severity}) 0 0 0
3798 0 return undef; # default "normal"
3799 }
3800 0 if (0) { # nothing for this yet
3801 return 'non-urgent';
3802 }
3803 0 return undef; # unknown
3804 }
3805 }
3806  
3807 # return a string for the slightly unofficial "Precedence:" header
3808 # might be able to identify lists gatewayed to RSS and give "list" for them
3809 # maybe "bulk" would suit low priority stuff
3810 # for now nothing
3811 #
3812 # sub item_to_precedence {
3813 # my ($self, $item) = @_;
3814 # return undef; # nothing
3815 # }
3816  
3817 # return the host part of $self->{'uri'}, or "localhost" if none
3818 2 ▶sub uri_to_host {
Subroutine uri_to_host: not called CC=4 SCAR=27.9
Pod undocumented
3819 0 my ($self) = @_;
3820 0 my $uri = $self->{'uri'};
3821 ### uri_to_host(): $uri
3822 0 ▶ return (non_empty ($uri && $uri->can('host') && $uri->host)
Condition0%0/8
non_empty($uri && $uri->can("host") && $uri->host) // "localhost"
l!l
00
$uri && $uri->can('host') && $uri->host
!ll&&!rl&&r
000
$uri and $uri->can("host")
!ll&&!rl&&r
000
MC/DC0%0/1
non_empty($uri && $uri->can("host") && $uri->host) // "localhost"
non_empty($uri && $uri->can("host") && $uri->host)
MC/DC0%0/3
$uri && $uri->can('host') && $uri->host
$uri $uri->can("host") $uri->host
Truth table0%0/2
A
A= non_empty($uri && $uri->can("host") && $uri->host)
Aresult
11
00
Truth table0%0/4
A and B && C
A= $uriB= $uri->can("host")C= $uri->host
ABCresult
0XX0
10X0
1100
1111
3823 // 'localhost');
3824 }
3825  
3826 0 ▶sub item_to_subject {
Subroutine item_to_subject: not called CC=5 SCAR=34.0
Pod undocumented
3827 0 my ($self, $item) = @_;
3828  
3829 # Atom <title> can have type="html" etc in the usual way.
3830 return
3831 0 ▶ (elt_to_rendered_line ($item->first_child('title'))
Condition0%0/12
(((elt_to_rendered_line($item->first_child("title")) // elt_to_rendered_line($item->first_child("dc:title"))) // elt_to_rendered_line($item->first_child("media:title"))) // elt_to_rendered_line($item->first_child("dc:subject"))) // &__("no subject")
l!l&&r!l&&!r
000
((elt_to_rendered_line($item->first_child("title")) // elt_to_rendered_line($item->first_child("dc:title"))) // elt_to_rendered_line($item->first_child("media:title"))) // elt_to_rendered_line($item->first_child("dc:subject"))
l!l&&r!l&&!r
000
(elt_to_rendered_line($item->first_child("title")) // elt_to_rendered_line($item->first_child("dc:title"))) // elt_to_rendered_line($item->first_child("media:title"))
l!l&&r!l&&!r
000
elt_to_rendered_line($item->first_child("title")) // elt_to_rendered_line($item->first_child("dc:title"))
l!l&&r!l&&!r
000
MC/DC0%0/5
(((elt_to_rendered_line($item->first_child("title")) // elt_to_rendered_line($item->first_child("dc:title"))) // elt_to_rendered_line($item->first_child("media:title"))) // elt_to_rendered_line($item->first_child("dc:subject"))) // &__("no subject")
elt_to_rendered_line($item->first_child("title")) elt_to_rendered_line($item->first_child("dc:title")) elt_to_rendered_line($item->first_child("media:title")) elt_to_rendered_line($item->first_child("dc:subject")) &__("no subject")
Truth table0%0/6
A // B // C // D // E
A= elt_to_rendered_line($item->first_child("title"))B= elt_to_rendered_line($item->first_child("dc:title"))C= elt_to_rendered_line($item->first_child("media:title"))D= elt_to_rendered_line($item->first_child("dc:subject"))E= &__("no subject")
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
3832  
3833 # <dc:title> is probably pointless within an item, would it ever be
3834 # present without a plain <title>?
3835 #
3836 // elt_to_rendered_line ($item->first_child('dc:title'))
3837  
3838 # eg. https://archive.org/services/collection-rss.php has <media:title>
3839 # in addition to plain <title>. Probably would never have
3840 # <media:title> without plain <title>, but check anyway.
3841 #
3842 // elt_to_rendered_line ($item->first_child('media:title'))
3843  
3844 # <dc:subject> is supposed to be a keyword type thing, but might be
3845 # better than nothing. Not sure have ever actually seen <dc:subject>
3846 # without <title>, so perhaps this is pointless.
3847 #
3848 // elt_to_rendered_line ($item->first_child('dc:subject'))
3849  
3850 // __('no subject'));
3851 }
3852 2 @known{qw(/channel/title
3853 /channel/dc:subject
3854 /channel/subtitle
3855 /channel/itunes:subtitle
3856  
3857 /channel/item/dc:subject
3858 /channel/item/title
3859 /channel/item/media:title
3860 /channel/item/dc:title
3861 /channel/item/itunes:title
3862 /channel/item/itunes:subtitle --not-using-this-as-yet
3863 /channel/item/slate:menuline --copy-of-subject-it-seems
3864 /channel/item/slate:rubric --blog-title
3865 /channel/item/slate:blog --blog-title
3866 /channel/item/slate:legacy_url --same-as-link-it-seems
3867 )} = ();
3868  
3869  
3870 # return language code string for Content-Language, or undef
3871 # return is per RFC 1766, RFC 3066, RFC 4646
3872 #
3873 # xml:lang is defined to be per RFC 4646, no mangling needed
3874 # RSS <language> seems close enough http://www.rssboard.org/rss-language-codes
3875 # <dc:language> is recommended as RFC 4646
3876 # cf. I18N::LangTags if mangling might be needed one day
3877 #
3878 0 ▶sub item_to_language {
Subroutine item_to_language: not called CC=7 SCAR=40.3
Pod undocumented
3879 0 my ($self, $item) = @_;
3880 0 my $lang;
3881  
3882 0 ▶ if (my $elt = $item->first_child('content')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $elt = $item->first_child("content")) 0 0 0
3883 0 $lang = non_empty ($elt->att('xml:lang'));
3884 }
3885 # Either <language>, <dc:language>, <twitter:lang> sub-element or
3886 # xml:lang="" tag, in the item itself or in channel, and maybe xml:lang in
3887 # toplevel <feed>. $elt->inherit_att() is close, but looks only at
3888 # xml:lang, not a <language> subelement.
3889 0 ▶ for ( ; $item; $item = $item->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item) 0 0 0
3890 0 ▶ $lang //= (non_empty ($item->first_child_trimmed_text
Condition0%0/7
$lang //= (non_empty($item->first_child_trimmed_text(qr/^((dc:)?language|twitter:lang)$/)) // non_empty($item->att("xml:lang"))) // (next)
l!l
00
(non_empty($item->first_child_trimmed_text(qr/^((dc:)?language|twitter:lang)$/)) // non_empty($item->att("xml:lang"))) // (next)
l!l
00
non_empty($item->first_child_trimmed_text(qr/^((dc:)?language|twitter:lang)$/)) // non_empty($item->att("xml:lang"))
l!l&&r!l&&!r
000
MC/DC0%0/1
$lang //= (non_empty($item->first_child_trimmed_text(qr/^((dc:)?language|twitter:lang)$/)) // non_empty($item->att("xml:lang"))) // (next)
$lang
Truth table0%0/2
A
A= $lang
Aresult
11
00
3891 (qr/^((dc:)?language|twitter:lang)$/))
3892 // non_empty ($item->att('xml:lang'))
3893 // next);
3894 }
3895 0 ▶ return ($lang // $self->{'resp'}->content_language);
Condition0%0/3
$lang // $self->{"resp"}->content_language
l!l&&r!l&&!r
000
MC/DC0%0/2
$lang // $self->{"resp"}->content_language
$lang $self->{"resp"}->content_language
Truth table0%0/3
A // B
A= $langB= $self->{"resp"}->content_language
ABresult
1X1
011
000
3896 }
3897 2 @known{qw(/channel/language
3898 /channel/dc:language
3899 /channel/twitter:lang
3900 /channel/item/language
3901 /channel/item/dc:language
3902 /channel/item/twitter:lang
3903 )} = ();
3904  
3905 # return arrayref of copyright strings
3906 # Keep all of multiple rights/license/etc in the interests of preserving all
3907 # statements.
3908 0 ▶sub item_to_copyright {
Subroutine item_to_copyright: not called CC=7 SCAR=40.3
Pod undocumented
3909 0 my ($self, $item) = @_;
3910 0 my $channel = elt_to_channel($item);
3911  
3912 # <dcterms:license> supposedly supercedes <dc:rights>, maybe should
3913 # suppress the latter in the presence of the former (dcterms: collapsed to
3914 # dc: by the map_xmlns).
3915 #
3916 # Atom <rights> can be type="html" etc in its usual way, but think RSS is
3917 # always plain text
3918 #
3919 0 my $re = qr/^(rights # Atom
3920 |copyright # RSS, don't think entity-encoded html allowed there
3921 |dcterms:license
3922 |dc:rights
3923 |creativeCommons:licen[cs]e
3924 )$/x;
3925 # Atom sub-elem <source><rights>...</rights>
3926 0 my @parents = ($item, $channel, $item->children('source'));
3927  
3928 0 my @strings;
3929 0 foreach my $elt (map {$_->children($re)} @parents) {
3930 0 push @strings,
3931 join_non_empty(' ',
3932 elt_to_rendered_line($elt),
3933 # eg. <creativeCommons:licence rdf:resource="http://..."/>
3934 $elt->att('rdf:resource'));
3935 }
3936  
3937 # <link rel="license" href="...">
3938 0 foreach my $link (map {$_->children('link')} @parents) {
3939 ### link for copyright: $link->sprint
3940 0 ▶ if (($link->att('atom:rel')//$link->att('rel')//'') eq 'license') {
Branch: 1 branch
BranchTrueFalseTotal
if ((($link->att("atom:rel") // $link->att("rel")) // "") eq "license") 0 0 0
Condition0%0/5
($link->att("atom:rel") // $link->att("rel")) // ""
l!l
00
$link->att("atom:rel") // $link->att("rel")
l!l&&r!l&&!r
000
MC/DC0%0/2
($link->att("atom:rel") // $link->att("rel")) // ""
$link->att("atom:rel") $link->att("rel")
Truth table0%0/3
A // B
A= $link->att("atom:rel")B= $link->att("rel")
ABresult
1X1
011
000
3941 0 ▶ push @strings, $link->att('atom:href')//$link->att('href');
Condition0%0/3
$link->att("atom:href") // $link->att("href")
l!l&&r!l&&!r
000
MC/DC0%0/2
$link->att("atom:href") // $link->att("href")
$link->att("atom:href") $link->att("href")
Truth table0%0/3
A // B
A= $link->att("atom:href")B= $link->att("href")
ABresult
1X1
011
000
3942 }
3943 }
3944 ### @strings
3945 0 return [ List::MoreUtils::uniq(grep {defined} @strings) ];
3946 }
3947 2 @known{qw(/channel/copyright
3948 /channel/rights
3949 /channel/dc:rights
3950 /channel/dc:license
3951 /channel/creativeCommons:licence
3952 /channel/creativeCommons:license
3953 /channel/item/dc:rights
3954 /channel/item/dc:license
3955 /channel/item/creativeCommons:licence
3956 /channel/item/creativeCommons:license
3957 )} = ();
3958 # /channel/item/media:credit --nothing-much-in-this-one
3959  
3960  
3961 # return string or undef
3962 0 ▶sub item_to_generator {
Subroutine item_to_generator: not called CC=4 SCAR=30.0
Pod undocumented
3963 0 my ($self, $item) = @_;
3964 0 my $channel = elt_to_channel($item);
3965 0 my @strings;
3966  
3967 # both RSS and Atom use <generator>
3968 # Atom can include version="" and uri=""
3969 0 ▶ if (my $generator = $channel->first_child('generator')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $generator = $channel->first_child("generator")) 0 0 0
3970 0 push @strings, join_non_empty (' ',
3971 $generator->text,
3972 $generator->att('atom:version'),
3973 $generator->att('version'),
3974 $generator->att('atom:uri'),
3975 $generator->att('uri'));
3976 }
3977  
3978 # FIXME: is this bit right?
3979 # <statusnet:notice_info local_id="54790448"
3980 # source="&lt;a href=&quot;http://nongnu.org/identica-mode/&quot; rel=&quot;nofollow&quot;&gt;Emacs Identica-mode&lt;/a&gt;"
3981 # source_link="http://nongnu.org/identica-mode/"></statusnet:notice_info>
3982 #
3983 0 ▶ if (my $notice = $item->first_child('statusnet:notice_info')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $notice = $item->first_child("statusnet:notice_info")) 0 0 0
3984 0 ▶ if (defined (my $html = $notice->att('atom:source'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $html = $notice->att("atom:source"))) 0 0 0
3985 0 push @strings, join_non_empty (' ',
3986 html_to_rendered_line($html),
3987 $notice->att('atom:source_link'));
3988 }
3989 }
3990  
3991 0 return collapse_whitespace (join_non_empty (', ', @strings));
3992 }
3993 2 @known{qw(/channel/item/statusnet:notice_info
3994 )} = ();
3995  
3996 # return URL string or undef/empty
3997 0 ▶sub item_to_feedburner {
Subroutine item_to_feedburner: not called CC=3 SCAR=24.8
Pod undocumented
3998 0 my ($self, $item) = @_;
3999 0 my $channel = elt_to_channel($item);
4000 0 ▶ my $elt = $channel->first_child('feedburner:info') || return;
Condition0%0/2
$channel->first_child('feedburner:info') || (return)
l!l
00
MC/DC0%0/1
$channel->first_child('feedburner:info') || (return)
$channel->first_child('feedburner:info')
Truth table0%0/2
A
A= $channel->first_child('feedburner:info')
Aresult
11
00
4001 0 ▶ my $uri = $elt->att('uri') // return;
Condition0%0/2
$elt->att("uri") // (return)
l!l
00
MC/DC0%0/1
$elt->att("uri") // (return)
$elt->att("uri")
Truth table0%0/2
A
A= $elt->att("uri")
Aresult
11
00
4002 0 return URI->new_abs ($uri, 'http://feeds.feedburner.com/')->as_string;
4003 }
4004  
4005 # $elt is an Atom <content>
4006 0 ▶sub atom_content_flavour {
Subroutine atom_content_flavour: not called CC=10 SCAR=47.0
Pod undocumented
4007 0 my ($elt) = @_;
4008 0 ▶ if (! defined $elt) { return ''; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $elt) 0 0 0
4009 0 ▶ my $type = ($elt->att('atom:type') // $elt->att('type'));
Condition0%0/3
$elt->att("atom:type") // $elt->att("type")
l!l&&r!l&&!r
000
MC/DC0%0/2
$elt->att("atom:type") // $elt->att("type")
$elt->att("atom:type") $elt->att("type")
Truth table0%0/3
A // B
A= $elt->att("atom:type")B= $elt->att("type")
ABresult
1X1
011
000
4010 0 ▶ if ($elt->att('atom:src') || $elt->att('src')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->att("atom:src") or $elt->att("src")) 0 0 0
Condition0%0/3
$elt->att("atom:src") or $elt->att("src")
l!l&&r!l&&!r
000
MC/DC0%0/2
$elt->att("atom:src") or $elt->att("src")
$elt->att("atom:src") $elt->att("src")
Truth table0%0/3
A or B
A= $elt->att("atom:src")B= $elt->att("src")
ABresult
1X1
011
000
4011 # <content src=""> external
4012 0 return 'link';
4013 }
4014 0 ▶ if (! defined $type
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $type or $type eq "html" or $type eq "xhtml" or $type eq "application/xhtml+xml" or $type =~ m[^text/]) 0 0 0
Condition0%0/12
not defined $type or $type eq "html" or $type eq "xhtml" or $type eq "application/xhtml+xml" or $type =~ m[^text/]
l!l&&r!l&&!r
000
not defined $type or $type eq "html" or $type eq "xhtml" or $type eq "application/xhtml+xml"
l!l&&r!l&&!r
000
not defined $type or $type eq "html" or $type eq "xhtml"
l!l&&r!l&&!r
000
not defined $type or $type eq "html"
l!l&&r!l&&!r
000
MC/DC0%0/5
not defined $type or $type eq "html" or $type eq "xhtml" or $type eq "application/xhtml+xml" or $type =~ m[^text/]
not defined $type $type eq "html" $type eq "xhtml" $type eq "application/xhtml+xml" $type =~ m[^text/]
Truth table0%0/6
not(A) or B or C or D or E
A= not defined $typeB= $type eq "html"C= $type eq "xhtml"D= $type eq "application/xhtml+xml"E= $type =~ m[^text/]
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
4015 || $type eq 'html'
4016 || $type eq 'xhtml'
4017 || $type eq 'application/xhtml+xml'
4018 || $type =~ m{^text/}) {
4019 0 return 'body';
4020 }
4021 0 return 'attach';
4022 }
4023  
4024 0 ▶sub html_wrap_fragment {
Subroutine html_wrap_fragment: not called CC=4 SCAR=30.0
Pod undocumented
4025 0 my ($item, $fragment, $language) = @_;
4026 0 ▶ my $charset = (is_ascii($fragment) ? 'us-ascii' : 'utf-8');
Branch: 1 branch
BranchTrueFalseTotal
is_ascii($fragment) ? : 0 0 0
4027 0 my $base_uri = App::RSS2Leafnode::XML::Twig::Other::elt_xml_base($item);
4028 0 ▶ my $base_header = (defined $base_uri
Branch: 1 branch
BranchTrueFalseTotal
defined $base_uri ? : 0 0 0
4029 ? " <base href=\"$Entitize{$base_uri}\">\n"
4030 : '');
4031 0 ▶ if (is_non_empty ($language)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty($language)) { } 0 0 0
4032 0 $language = " lang=\"$Entitize{$language}\"";
4033 } else {
4034 0 $language = '';
4035 }
4036 0 return (<<"HERE", $charset);
4037 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4038 <html$language>
4039 <head>
4040 <meta http-equiv=Content-Type content="text/html; charset=$charset">
4041 $base_header</head>
4042 <body>
4043 $fragment
4044 </body></html>
4045 HERE
4046 }
4047  
4048 # $self->{'rss_charset_override'}, if set, means the bytes are actually in
4049 # that charset. Enforce this by replacing the "<?xml encoding=" in the
4050 # bytes. Do a decode() and re-encode() to cope with non-ascii like say
4051 # utf-16.
4052 #
4053 # XML::RSS::LibXML has an "encoding" option on its new(), but that's for
4054 # feed creation or something, a parse() still follows the <?xml> tag.
4055 #
4056 0 ▶sub enforce_rss_charset_override {
Subroutine enforce_rss_charset_override: not called CC=4 SCAR=30.0
Pod undocumented
4057 0 my ($self, $xml) = @_;
4058 0 ▶ if (my $charset = $self->{'rss_charset_override'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $charset = $self->{"rss_charset_override"}) 0 0 0
4059 0 $xml = Encode::decode ($charset, $xml);
4060 0 ▶ if ($xml =~ s/(<\?xml[^>]*encoding="?)([^">]+)/$1$charset/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($xml =~ s/(<\?xml[^>]*encoding="?)([^">]+)/$1$charset/i) { } 0 0 0
elsif ($xml =~ s/(<\?xml[^?>]*)/$1 encoding="$charset"/i) { } 0 0 0
4061 0 $self->verbose (2, "replace encoding=$2 tag with encoding=$charset");
4062 } elsif ($xml =~ s/(<\?xml[^?>]*)/$1 encoding="$charset"/i) {
4063 0 $self->verbose (2, "insert encoding=\"$charset\"");
4064 } else {
4065 0 my $str = "<?xml version=\"1.0\" encoding=\"$charset\"?>\n";
4066 0 $self->verbose (2, "insert $str");
4067 0 $xml = $str . $xml;
4068 }
4069 0 $self->verbose (3, "xml now:\n$xml\n");
4070 0 $xml = Encode::encode ($charset, $xml);
4071 }
4072 0 return $xml;
4073 }
4074  
4075 # slightly experimental extract of "cap" fields as from
4076 # http://www.nws.noaa.gov/alerts-beta/
4077 # http://www.weather.gov/alerts-beta/ca.php?x=0
4078 0 ▶sub item_common_alert_protocol {
Subroutine item_common_alert_protocol: not called CC=7 SCAR=40.3
Pod undocumented
4079 0 my ($self, $item, $want_html) = @_;
4080 0 my @fields;
4081 0 foreach my $elt ($item->children(qr/^cap:/)) {
4082 0 (my $field = $elt->name) =~ s/^cap://;
4083 0 ▶ if ($field eq 'geocode' || $field eq 'parameter') {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "geocode" or $field eq "parameter") 0 0 0
Condition0%0/3
$field eq "geocode" or $field eq "parameter"
l!l&&r!l&&!r
000
MC/DC0%0/2
$field eq "geocode" or $field eq "parameter"
$field eq "geocode" $field eq "parameter"
Truth table0%0/3
A or B
A= $field eq "geocode"B= $field eq "parameter"
ABresult
1X1
011
000
4084 # dunno how to show these yet ...
4085 0 next;
4086 }
4087 0 $known{'/channel/item/'.$elt->name} = undef;
4088  
4089 0 my $value = elt_to_rendered_line ($elt);
4090 0 $value = Text::Trim::trim ($value);
4091 0 ▶ if (is_non_empty ($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty($value)) 0 0 0
4092 0 push @fields, [ "\u$field: ", $value ];
4093 }
4094 }
4095 0 ▶ if (! @fields) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@fields) 0 0 0
4096 0 return '';
4097 }
4098 # FIXME: This $width padding doesn't come out in html, only in text. The
4099 # NOAA is Atom plain text, so that one is ok at least.
4100 0 my $width = max(map {length $_->[0]} @fields);
4101 0 @fields = map { my $field = $_->[0];
4102 0 my $value = $_->[1];
4103 0 $field = sprintf ('%-*s', $width, $field);
4104 0 $self->text_wrap ($value, $field)
4105 } @fields;
4106 0 ▶ if ($want_html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_html) { } 0 0 0
4107 return "<p>\n"
4108 0 . join("<br>\n", map {$Entitize{$_}} @fields)
4109 . "\n</p>\n";
4110 } else {
4111 0 return "\n"
4112 . join("\n", @fields)
4113 . "\n";
4114 }
4115 }
4116  
4117 0 ▶sub item_unknowns {
Subroutine item_unknowns: not called CC=10 SCAR=47.0
Pod undocumented
4118 0 my ($self, $item, $want_html) = @_;
4119 ### item_unknowns() ...
4120  
4121 0 my $xml = '';
4122 0 ▶ foreach my $elt (map {$_->tag eq 'media:group' # descend into media:group
Branch: 1 branch
BranchTrueFalseTotal
$_->tag eq 'media:group' ? : 0 0 0
4123 ? $_->children : $_}
4124 $item->children) {
4125 0 ▶ next if $elt->tag =~ /^#/; # text
Branch: 1 branch
BranchTrueFalseTotal
if $elt->tag =~ /^#/ 0 0 0
4126 0 ▶ next if App::RSS2Leafnode::XML::Twig::Other::elt_is_empty($elt);
Branch: 1 branch
BranchTrueFalseTotal
if App::RSS2Leafnode::XML::Twig::Other::elt_is_empty($elt) 0 0 0
4127 0 my $path = $elt->path;
4128 0 $path =~ s{^/(rss|channel)/channel}{/channel};
4129 0 $path =~ s{^/(feed|rdf:RDF)}{/channel};
4130 0 $path =~ s{^/channel/entry}{/channel/item};
4131 0 ▶ next if $path =~ m{/xhtml};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[/xhtml] 0 0 0
4132 0 ▶ next if $path =~ m{^/channel/item/(description|content:encoded)/};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[^/channel/item/(description|content:encoded)/] 0 0 0
4133 0 ▶ next if exists $known{$path};
Branch: 1 branch
BranchTrueFalseTotal
if exists $known{$path} 0 0 0
4134 ### unknown path: $path
4135  
4136 0 require Text::Wrap;
4137 0 my $part = do {
4138 0 local $Text::Wrap::columns = $self->{'render_width'} + 1 + 4;
4139 0 local $Text::Wrap::huge = 'overflow'; # don't break long words
4140 0 local $Text::Wrap::unexpand = 0; # no tabs in output
4141 0 $elt->sprint
4142 };
4143 0 $part =~ s/^ //mg; # indentation from element depth
4144 0 $part =~ s/^\n+//; # leading blank lines
4145 0 $xml .= $part;
4146 }
4147 0 ▶ if ($xml eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml eq "") 0 0 0
4148 0 return '';
4149 }
4150 ### $xml
4151  
4152 0 ▶ if ($want_html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_html) { } 0 0 0
4153 0 return "\n<p>\n" . __('Further feed XML:') . "<br>\n"
4154 . "<pre>$Entitize{$xml}</pre>\n</p>\n";
4155 } else {
4156 0 return "\n" . __('Further feed XML:') . "\n" . $xml;
4157 }
4158 }
4159  
4160 2 @known{qw(/channel/item/media:group/media:title
4161 /channel/item/media:group/media:description
4162 /channel/item/media:group/media:credit
4163 /channel/item/media:group/media:player
4164 /channel/item/media:group/media:thumbnail
4165 /channel/item/media:group/media:content
4166 /channel/item/media:group/media:copyright
4167  
4168 --ENHANCE-ME--nothing-for-these-yet
4169 /channel/item/media:group/media:category
4170 /channel/item/media:group/media:rating
4171 )} = (); # hash slice
4172  
4173 0 ▶sub media_group_to_html {
Subroutine media_group_to_html: not called CC=13 SCAR=52.0
Pod undocumented
4174 0 my ($self, $group) = @_;
4175 ### media_group_to_html(): "$group"
4176  
4177 0 my $ret = "<p>\n";
4178 0 my @lines;
4179  
4180 0 foreach my $elt ($group->children('media:title'),
4181 $group->children('media:description')) {
4182 0 push @lines, elt_to_html($elt);
4183 }
4184  
4185 0 foreach my $elt ($group->children('media:credit')) {
4186 0 my $html = elt_to_html($elt);
4187 0 ▶ if (defined (my $role = non_empty($elt->att('role')))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $role = non_empty($elt->att("role")))) 0 0 0
4188 0 $html .= " ($Entitize{$role})";
4189 }
4190 0 push @lines, $html;
4191 }
4192 0 foreach my $elt ($group->children('media:player'),
4193 $group->children('media:thumbnail'),
4194 $group->children('media:content')) {
4195 0 ▶ my $url = $elt->att('url') // next;
Condition0%0/2
$elt->att("url") // (next)
l!l
00
MC/DC0%0/1
$elt->att("url") // (next)
$elt->att("url")
Truth table0%0/2
A
A= $elt->att("url")
Aresult
11
00
4196 0 my $abs_url = App::RSS2Leafnode::XML::Twig::Other::elt_xml_based_uri
4197 ($group, $url);
4198  
4199 0 my $html = "<a href=\"$Entitize{$abs_url}\"";
4200 0 ▶ if (defined (my $type = non_empty($elt->att('type')))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $type = non_empty($elt->att("type")))) 0 0 0
4201 0 $html .= " type=\"$Entitize{$type}\"";
4202 }
4203 0 ▶ if (defined (my $lang = non_empty($elt->att('lang')))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $lang = non_empty($elt->att("lang")))) 0 0 0
4204 0 $html .= " hreflang=\"$Entitize{$lang}\"";
4205 }
4206 0 $html .= ">$Entitize{$url}$url</a>";
4207 {
4208 0 my @paren;
4209 0 ▶ if (defined (my $size = non_empty($elt->att('fileSize')))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $size = non_empty($elt->att("fileSize")))) 0 0 0
4210 0 push @paren, $self->format_size_in_bytes($size);
4211 }
4212 0 ▶ if (defined (my $duration = non_empty($elt->att('duration')))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $duration = non_empty($elt->att("duration")))) 0 0 0
4213 0 ▶ if ($duration !~ /:/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($duration =~ /:/) 0 0 0
4214 0 $duration = __px('s-for-seconds', '{duration}s',
4215 duration => $duration);
4216 }
4217 0 push @paren, $duration;
4218 }
4219 0 ▶ if (@paren) {
Branch: 1 branch
BranchTrueFalseTotal
if (@paren) 0 0 0
4220 0 $html .= $Entitize{' (' . join(', ',@paren). ')'};
4221 }
4222 }
4223 0 $html .= "\n";
4224 0 push @lines, $html;
4225 }
4226  
4227 0 foreach my $elt ($group->children('media:copyright')) {
4228 0 push @lines, "Copyright: ".elt_to_html($elt);
4229 }
4230  
4231 ### total lines: scalar(@lines)
4232 0 return "<p>\n" . join("<br>\n",@lines) . "\n</p>\n";
4233 }
4234  
4235 0 ▶sub elt_to_html {
Subroutine elt_to_html: not called CC=4 SCAR=30.0
Pod undocumented
4236 0 my ($elt) = @_;
4237 0 ▶ defined $elt or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $elt or return 0 0 0
4238
4239 0 my $type = elt_content_type ($elt);
4240 0 ▶ if ($type eq 'xhtml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "xhtml") 0 0 0
4241 0 return elt_xhtml_to_html($elt);
4242 }
4243 0 my $str = elt_subtext($elt);
4244 0 ▶ if ($type eq 'html') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'html') { } 0 0 0
4245 0 return $str;
4246 } else {
4247 0 return $Entitize{$str};
4248 }
4249 }
4250  
4251 # $body construction below
4252 2 @known{qw(/channel/item/description
4253 /channel/item/dc:description
4254 /channel/item/itunes:summary
4255 /channel/item/content:encoded
4256 /channel/item/summary
4257 )} = ();
4258  
4259 # $item is an XML::Twig::Elt
4260 #
4261 0 ▶sub fetch_rss_process_one_item {
Subroutine fetch_rss_process_one_item: not called CC=57 SCAR=80.7
Pod undocumented
4262 0 my ($self, $item) = @_;
4263 0 my $subject = $self->item_to_subject ($item);
4264 0 $self->verbose (1, ' ', __x('item: {subject}', subject => $subject));
4265  
4266 0 my $msgid = $self->item_to_msgid ($item);
4267 0 my $new = 0;
4268  
4269 0 ▶ if (! $self->nntp_message_id_exists ($msgid)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->nntp_message_id_exists($msgid)) 0 0 0
4270 0 my $channel = elt_to_channel($item);
4271 0 my ($from, $sender, @from_links) = $self->item_to_from($item);
4272 0 my @links = ($self->item_to_links ($item),
4273 @from_links);
4274  
4275 # For comments feeds show "Re: Foo" as the subject. Haven't seen a
4276 # comments feed with anything useful in the <title>. Could think about
4277 # including it at the start of the message body if it was any good.
4278 #
4279 #
4280 # http://www.netzpolitik.org/feed/ has <wfw:commentRss> feeds with <title>
4281 # just "Von: Foo" where Foo is the poster's name.
4282 #
4283 # my $dummy = $self->DUMMY_EMAIL_ADDRESS;
4284 # if ($from =~ /(.*) <\Q$dummy\E>$/
4285 # && $subject eq "Von: $1") {
4286 # $subject = $self->{'getting_rss_comments'};
4287 # }
4288 #
4289 0 ▶ if (defined $self->{'getting_rss_comments'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"getting_rss_comments"}) 0 0 0
4290 0 $subject = $self->{'getting_rss_comments'};
4291 }
4292  
4293 0 my $list_post = googlegroups_link_email(@links);
4294 0 ▶ my $precedence = (defined $list_post ? 'list' : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $list_post ? : 0 0 0
4295 0 my $language = $self->item_to_language($item);
4296  
4297 # RSS <rating> PICS-Label
4298 # http://www.w3.org/TR/REC-PICS-labels
4299 # ENHANCE-ME: Maybe transform <itunes:explicit> "yes","no","clean" into
4300 # PICS too maybe, unless it only applies to the enclosure as such. Maybe
4301 # <media:adult> likewise.
4302 0 my $pics_label = collapse_whitespace ($channel->first_child_text('rating'));
4303  
4304 # Crib: an undef value for a header means omit that header, which is good
4305 # for say the merely optional "Content-Language"
4306 #
4307 # there can be multiple "feed" links from Atom ...
4308 # 'X-RSS-Feed-Link:' => $channel->{'link'},
4309 #
4310 my %headers
4311 = ('Path:' => scalar ($self->uri_to_host),
4312 'Newsgroups:' => $self->{'nntp_group'},
4313 From => $from,
4314 Sender => $from,
4315 Subject => $subject,
4316 Keywords => scalar ($self->item_to_keywords($item)),
4317 Date => scalar ($self->item_to_date($item)),
4318 'In-Reply-To:' => scalar ($self->item_to_in_reply_to($item)),
4319 References => $self->{'References:'},
4320 'Message-ID' => $msgid,
4321 'Content-Language:' => $language,
4322 'Importance:' => scalar ($self->item_to_importance($item)),
4323 'Priority:' => scalar ($self->item_to_priority($item)),
4324 'Face:' => scalar ($self->item_to_face($item)),
4325 'List-Post:' => $list_post,
4326 'Precedence:' => $precedence,
4327 'PICS-Label:' => $pics_label,
4328 'X-Copyright:' => scalar ($self->item_to_copyright($item)),
4329 0 'X-RSS-URL:' => scalar ($self->{'uri'}->as_string),
4330 'X-RSS-Feedburner:' => scalar ($self->item_to_feedburner($item)),
4331 'X-RSS-Generator:' => scalar ($self->item_to_generator($item)),
4332 );
4333  
4334 0 my $attach_elt;
4335  
4336 # <media:text> is another possibility, but have seen it from Yahoo as just
4337 # a copy of <description>, with type="html" to make the format clear.
4338 #
4339 # ENHANCE-ME: <itunes:subtitle> might be worthwhile showing at the start
4340 # as well as <itunes:summary>.
4341 #
4342 my $body = (
4343 # <content:encoded> generally bigger or better than
4344 # <description>, so prefer that
4345 $item->first_child('content:encoded')
4346 || $item->first_child('description')
4347 || $item->first_child('dc:description')
4348 || $item->first_child('itunes:summary')
4349 0 ▶ || do {
Condition0%0/15
$item->first_child('content:encoded') || $item->first_child('description') || $item->first_child('dc:description') || $item->first_child('itunes:summary') || do { my $elt = $item->first_child('content'); my $flavour = atom_content_flavour($elt); $flavour eq 'link' ? undef : ($flavour eq 'attach' ? do { $attach_elt = $elt; undef } : $elt) } || $item->first_child('summary')
l!l&&r!l&&!r
000
$item->first_child("content:encoded") or $item->first_child("description") or $item->first_child("dc:description") or $item->first_child("itunes:summary") or do { my $elt = $item->first_child("content"); my $flavour = atom_content_flavour($elt); $flavour eq "link" ? undef : ($flavour eq "attach" ? do { $attach_elt = $elt; undef } : $elt) }
l!l&&r!l&&!r
000
$item->first_child("content:encoded") or $item->first_child("description") or $item->first_child("dc:description") or $item->first_child("itunes:summary")
l!l&&r!l&&!r
000
$item->first_child("content:encoded") or $item->first_child("description") or $item->first_child("dc:description")
l!l&&r!l&&!r
000
$item->first_child("content:encoded") or $item->first_child("description")
l!l&&r!l&&!r
000
MC/DC0%0/6
$item->first_child('content:encoded') || $item->first_child('description') || $item->first_child('dc:description') || $item->first_child('itunes:summary') || do { my $elt = $item->first_child('content'); my $flavour = atom_content_flavour($elt); $flavour eq 'link' ? undef : ($flavour eq 'attach' ? do { $attach_elt = $elt; undef } : $elt) } || $item->first_child('summary')
$item->first_child("content:encoded") $item->first_child("description") $item->first_child("dc:description") $item->first_child("itunes:summary") do { my $elt = $item->first_child("content"); my $flavour = atom_content_flavour($elt); $flavour eq "link" ? undef : ($flavour eq "attach" ? do { $attach_elt = $elt; undef } : $elt) } $item->first_child('summary')
Truth table0%0/7
A or B or C or D or E || F
A= $item->first_child("content:encoded")B= $item->first_child("description")C= $item->first_child("dc:description")D= $item->first_child("itunes:summary")E= do { my $elt = $item->first_child("content"); my $flavour = atom_content_flavour($elt); $flavour eq "link" ? undef : ($flavour eq "attach" ? do { $attach_elt = $elt; undef } : $elt) }F= $item->first_child('summary')
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
4350 # Atom spec is for no more than one <content>.
4351 # Exclude "link", and leave "attach" to code below.
4352 0 my $elt = $item->first_child('content');
4353 0 my $flavour = atom_content_flavour($elt);
4354 ($flavour eq 'link' ? undef
4355 0 ▶ : $flavour eq 'attach' ? do { $attach_elt = $elt; undef }
Branch: 2 branches
BranchTrueFalseTotal
$flavour eq 'link' ? : 0 0 0
$flavour eq 'attach' ? : 0 0 0
4356 : $elt)
4357 }
4358 || $item->first_child('summary')); # Atom
4359  
4360 0 my $body_type = elt_content_type ($body);
4361 0 $self->verbose (3, ' body_type from elt: ', $body_type);
4362 0 my $body_charset = 'utf-8';
4363 0 my $body_base_url = App::RSS2Leafnode::XML::Twig::Other::elt_xml_base ($body);
4364 0 ▶ if (! defined $body_type) { # no $body element at all
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $body_type) { } 0 0 0
elsif ($body_type eq 'xhtml') { } 0 0 0
elsif ($body_type eq 'html') { } 0 0 0
elsif ($body_type eq 'text') { } 0 0 0
elsif ($body_type =~ m[^text/]) { } 0 0 0
4365 0 $body = '';
4366 0 $body_type = 'text/plain';
4367  
4368 } elsif ($body_type eq 'xhtml') { # Atom
4369 0 $body = elt_xhtml_to_html ($body);
4370 0 $body_type = 'html';
4371  
4372 } elsif ($body_type eq 'html') { # RSS or Atom
4373 0 $body = elt_subtext($body);
4374  
4375 } elsif ($body_type eq 'text') { # Atom 'text' to be flowed
4376 # should be text-only, no sub-elements, but extract sub-elements to
4377 # cope with dodgy feeds with improperly escaped html etc
4378 0 $body = $self->text_wrap (elt_subtext ($body));
4379 0 $body_type = 'text/plain';
4380 } elsif ($body_type =~ m{^text/}) { # Atom mime text type
4381 0 $body = elt_subtext ($body);
4382  
4383 } else { # Atom base64 something
4384 0 $body = MIME::Base64::decode ($body->text);
4385 0 $body_charset = undef;
4386 }
4387 0 ▶ $self->verbose (3, " body: $body_type charset=",
Condition0%0/2
$body_charset // "undef"
l!l
00
MC/DC0%0/1
$body_charset // "undef"
$body_charset
Truth table0%0/2
A
A= $body_charset
Aresult
11
00
4388 $body_charset//'undef', "\n",
4389 "$body\n");
4390  
4391 0 ▶ my $body_is_html = ($body_type eq 'html'|| $body_type eq 'text/html');
Condition0%0/3
$body_type eq 'html' || $body_type eq 'text/html'
l!l&&r!l&&!r
000
MC/DC0%0/2
$body_type eq 'html' || $body_type eq 'text/html'
$body_type eq 'html' $body_type eq 'text/html'
Truth table0%0/3
A || B
A= $body_type eq 'html'B= $body_type eq 'text/html'
ABresult
1X1
011
000
4392 0 ▶ my $links_want_html = ($body_is_html && ! $self->{'render'});
Condition0%0/3
$body_is_html && !$self->{'render'}
!ll&&!rl&&r
000
MC/DC0%0/2
$body_is_html && !$self->{'render'}
$body_is_html !$self->{'render'}
Truth table0%0/3
A && not(B)
A= $body_is_htmlB= !$self->{'render'}
ABresult
0X0
100
111
4393 0 ▶ $self->verbose (3, " links_want_html: ",
Branch: 1 branch
BranchTrueFalseTotal
$links_want_html ? : 0 0 0
4394 ($links_want_html ? "yes" : "no"));
4395  
4396 # sort downloadables to the start, then by "priority"
4397 2 ▶ use sort 'stable';
Subroutine BEGIN: called CC=1 SCAR=0.0
4398 0 @links = sort {($b->{'download'}||0) <=> ($a->{'download'}||0)
4399 0 ▶ || ($b->{'priority'}||0) <=> ($a->{'priority'}||0)}
Condition0%0/11
($App::RSS2Leafnode::b->{'download'} || 0) <=> ($App::RSS2Leafnode::a->{'download'} || 0) || ($App::RSS2Leafnode::b->{'priority'} || 0) <=> ($App::RSS2Leafnode::a->{'priority'} || 0)
l!l&&r!l&&!r
000
$App::RSS2Leafnode::b->{'download'} || 0
l!l
00
$App::RSS2Leafnode::a->{'download'} || 0
l!l
00
$App::RSS2Leafnode::b->{'priority'} || 0
l!l
00
$App::RSS2Leafnode::a->{'priority'} || 0
l!l
00
MC/DC0%0/2
($App::RSS2Leafnode::b->{'download'} || 0) <=> ($App::RSS2Leafnode::a->{'download'} || 0) || ($App::RSS2Leafnode::b->{'priority'} || 0) <=> ($App::RSS2Leafnode::a->{'priority'} || 0)
$App::RSS2Leafnode::b->{'download'} $App::RSS2Leafnode::b->{'priority'}
MC/DC0%0/1
$App::RSS2Leafnode::a->{'download'} || 0
$App::RSS2Leafnode::a->{'download'}
MC/DC0%0/1
$App::RSS2Leafnode::a->{'priority'} || 0
$App::RSS2Leafnode::a->{'priority'}
Truth table0%0/3
A || B
A= $App::RSS2Leafnode::b->{'download'}B= $App::RSS2Leafnode::b->{'priority'}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $App::RSS2Leafnode::a->{'download'}
Aresult
11
00
Truth table0%0/2
A
A= $App::RSS2Leafnode::a->{'priority'}
Aresult
11
00
4400 @links;
4401 0 ▶ my $links_str = ($links_want_html
Branch: 1 branch
BranchTrueFalseTotal
$links_want_html ? : 0 0 0
4402 ? links_to_html(@links)
4403 : links_to_text(@links));
4404 0 $links_str .= $self->item_common_alert_protocol($item, $links_want_html);
4405 0 my @parts;
4406  
4407 # <media:group> elements as either a html part or in the text links
4408 {
4409 0 my $content = join ("\n",
4410 0 map {$self->media_group_to_html($_)}
4411 $item->children('media:group'));
4412 0 ▶ if (is_non_empty($content)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty($content)) 0 0 0
4413 0 ($content, my $charset) = html_wrap_fragment ($item, $content);
4414 0 my $content_type = 'text/html';
4415 0 ($content, $content_type, $charset, my $rendered)
4416 = $self->render_maybe ($content, $content_type, $charset,
4417 $body_base_url);
4418 ### media group content: $content
4419 0 ▶ if ($content_type eq 'text/plain') {
Branch: 1 branch
BranchTrueFalseTotal
if ($content_type eq 'text/plain') { } 0 0 0
4420 0 $links_str .= $content;
4421 } else {
4422 0 $content = Encode::encode ($charset, $content);
4423 0 push @parts, $self->mime_build ({}, # headers
4424 Type => $content_type,
4425 Charset => $charset,
4426 Data => $content);
4427 }
4428 }
4429 }
4430  
4431 0 ▶ if (is_non_empty(my $content
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty(my $content = $self->item_unknowns($item, $links_want_html))) 0 0 0
4432 = $self->item_unknowns($item, $links_want_html))) {
4433 0 ▶ my $content_type = ($links_want_html ? 'text/html' : 'text/plain');
Branch: 1 branch
BranchTrueFalseTotal
$links_want_html ? : 0 0 0
4434 0 ▶ if (@parts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts) { } 0 0 0
4435 0 ▶ my $charset = (is_ascii($content) ? 'us-ascii' : 'utf-8');
Branch: 1 branch
BranchTrueFalseTotal
is_ascii($content) ? : 0 0 0
4436 0 $content = Encode::encode ($charset, $content);
4437 0 push @parts, $self->mime_build ({}, # headers
4438 Type => $content_type,
4439 Charset => $charset,
4440 Data => $content);
4441 } else {
4442 0 $links_str .= $content;
4443 }
4444 }
4445  
4446 0 ▶ if ($self->{'rss_get_links'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rss_get_links"}) 0 0 0
4447 0 foreach my $l (@links) {
4448 0 ▶ next if ! $l->{'download'};
Branch: 1 branch
BranchTrueFalseTotal
unless $l->{"download"} 0 0 0
4449 0 my $url = $l->{'uri'};
4450 $self->verbose (1, ' ', __x('link: "{name}" {url}',
4451 0 name => $l->{'name'},
4452 url => $url));
4453 0 require HTTP::Request;
4454 0 my $req = HTTP::Request->new (GET => $url);
4455 0 my $resp = $self->ua->request($req);
4456 0 $resp = $self->aireview_follow ($url, $resp);
4457  
4458 0 ▶ if (! $resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
4459 print __x("rss2leafnode: {url}\n {status}\n",
4460 0 url => $l->{'uri'},
4461 status => $resp->status_line);
4462 my $msg = __x("Cannot download link {url}\n {status}",
4463 0 url => $l->{'uri'},
4464 status => $resp->status_line);
4465 0 ▶ if ($links_want_html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($links_want_html) { } 0 0 0
4466 0 $msg = $Entitize{$msg};
4467 0 $msg =~ s/\n/<br>/;
4468 0 $links_str .= "<p>&nbsp;$msg\n</p>\n";
4469 } else {
4470 0 $links_str .= "\n$msg\n";
4471 }
4472 0 next;
4473 }
4474  
4475 # suspect little value in a description when inlined
4476 # 'Content-Description:' => mimewords_non_ascii($l->{'title'})
4477 # favicon used for Face if nothing in the item
4478 #
4479 0 $self->enforce_html_charset_from_content ($resp);
4480 0 ▶ $headers{'Face:'} ||= $self->http_resp_to_face($resp);
Condition0%0/3
$headers{"Face:"} ||= $self->http_resp_to_face($resp)
l!l&&r!l&&!r
000
MC/DC0%0/2
$headers{"Face:"} ||= $self->http_resp_to_face($resp)
$headers{"Face:"} $self->http_resp_to_face($resp)
Truth table0%0/3
A ||= B
A= $headers{"Face:"}B= $self->http_resp_to_face($resp)
ABresult
1X1
011
000
4481 0 $self->http_resp_extract_main($resp);
4482 0 push @parts, $self->mime_part_from_response($resp);
4483 }
4484 }
4485 0 ▶ if ($links_want_html && $body_type eq 'html') {
Branch: 1 branch
BranchTrueFalseTotal
if ($links_want_html and $body_type eq "html") 0 0 0
Condition0%0/3
$links_want_html and $body_type eq "html"
!ll&&!rl&&r
000
MC/DC0%0/2
$links_want_html and $body_type eq "html"
$links_want_html $body_type eq "html"
Truth table0%0/3
A and B
A= $links_want_htmlB= $body_type eq "html"
ABresult
0X0
100
111
4486 # append to html fragment
4487 0 $body .= $links_str;
4488 0 undef $links_str;
4489 }
4490  
4491 0 ▶ if ($body_type eq 'html') {
Branch: 1 branch
BranchTrueFalseTotal
if ($body_type eq "html") 0 0 0
4492 0 ($body, $body_charset) = html_wrap_fragment ($item, $body, $language);
4493 0 $body_type = 'text/html';
4494 }
4495 0 ▶ if (defined $body_charset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body_charset) 0 0 0
4496 0 $body = Encode::encode ($body_charset, $body);
4497 }
4498  
4499 0 ($body, $body_type, $body_charset)
4500 = $self->render_maybe ($body, $body_type, $body_charset, $body_base_url);
4501  
4502 0 ▶ if ($body_type eq 'text/plain') {
Branch: 1 branch
BranchTrueFalseTotal
if ($body_type eq "text/plain") 0 0 0
4503 # remove trailing whitespace from any text
4504 0 $body =~ s/\s+$//;
4505 0 $body .= "\n";
4506  
4507 0 ▶ if (! $links_want_html) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($links_want_html) 0 0 0
4508 # append to text/plain, either atom type=text or rendered html
4509 0 ▶ unless (is_empty ($links_str)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_empty($links_str)) 0 0 0
4510 0 $links_str = Encode::encode ($body_charset, $links_str);
4511 0 $body .= "\n$links_str\n";
4512 }
4513 0 undef $links_str;
4514 }
4515 }
4516  
4517 0 ▶ unless (is_empty ($links_str)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_empty($links_str)) 0 0 0
4518 0 my $links_type;
4519 my $links_charset;
4520 0 ▶ if ($links_want_html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($links_want_html) { } 0 0 0
4521 0 $links_type = 'text/html';
4522 0 ($links_str, $links_charset) = html_wrap_fragment ($item, $links_str);
4523 } else {
4524 0 $links_type = 'text/plain';
4525 0 ▶ $links_charset = (is_ascii($links_str) ? 'us-ascii' : 'utf-8');
Branch: 1 branch
BranchTrueFalseTotal
is_ascii($links_str) ? : 0 0 0
4526 }
4527 0 $links_str = Encode::encode ($links_charset, $links_str);
4528 0 unshift @parts, $self->mime_build ({},
4529 Type => $links_type,
4530 Encoding => $links_charset,
4531 Data => $links_str);
4532 }
4533  
4534  
4535 0 my $top = $self->mime_build (\%headers,
4536 Top => 1,
4537 Type => $body_type,
4538 Charset => $body_charset,
4539 Data => $body);
4540  
4541 # Atom <content> of a non-text type
4542 0 ▶ if ($attach_elt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attach_elt) 0 0 0
4543 # ENHANCE-ME: this decodes base64 from the xml and then re-encodes for
4544 # the mime, is it possible to pass straight in?
4545 unshift @parts, $self->mime_build
4546 0 ▶ ({ 'Content-Location:' => $self->{'uri'}->as_string },
Condition0%0/3
$attach_elt->att("atom:type") // $attach_elt->att("type")
l!l&&r!l&&!r
000
MC/DC0%0/2
$attach_elt->att("atom:type") // $attach_elt->att("type")
$attach_elt->att("atom:type") $attach_elt->att("type")
Truth table0%0/3
A // B
A= $attach_elt->att("atom:type")B= $attach_elt->att("type")
ABresult
1X1
011
000
4547 Type => scalar ($attach_elt->att('atom:type')
4548 // $attach_elt->att('type')),
4549 Encoding => 'base64',
4550 Data => MIME::Base64::decode($attach_elt->text));
4551 }
4552  
4553 0 $self->verbose (2, 'parts count: ',scalar(@parts));
4554 0 foreach my $part (@parts) {
4555 0 $top->make_multipart;
4556 0 $top->add_part ($part);
4557 }
4558  
4559 0 mime_entity_lines($top);
4560 0 ▶ $self->nntp_post($top) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->nntp_post($top) or return 0 0 0 0
4561 0 $self->verbose (1, ' ', __('posted'));
4562 0 $new++;
4563 }
4564  
4565 # ENHANCE-ME: check the replies count to see if more to fetch
4566 0 ▶ if ($self->{'rss_get_comments'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rss_get_comments"}) 0 0 0
4567 0 my ($comments_rss_url, $comments_count)
4568 = $self->item_to_comments_rss($item);
4569 ### rss_get_comments: $comments_rss_url, $comments_count
4570 0 ▶ if (defined $comments_rss_url) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $comments_rss_url) 0 0 0
4571  
4572 # ENHANCE-ME: There's also a thr:updated in RFC 4685, but haven't seen
4573 # that ever actually used.
4574 0 my $status = $self->status_geturl ($comments_rss_url);
4575 0 ▶ if (defined $status->{'comments_count'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $status->{'comments_count'} and defined $comments_count and $status->{'comments_count'} == $comments_count) { } 0 0 0
Condition0%0/6
defined $status->{"comments_count"} and defined $comments_count and $status->{"comments_count"} == $comments_count
!ll&&!rl&&r
000
defined $status->{"comments_count"} and defined $comments_count
!ll&&!rl&&r
000
MC/DC0%0/3
defined $status->{"comments_count"} and defined $comments_count and $status->{"comments_count"} == $comments_count
defined $status->{"comments_count"} defined $comments_count $status->{"comments_count"} == $comments_count
Truth table0%0/4
A and B and C
A= defined $status->{"comments_count"}B= defined $comments_countC= $status->{"comments_count"} == $comments_count
ABCresult
0XX0
10X0
1100
1111
4576 && defined $comments_count
4577 && $status->{'comments_count'} == $comments_count) {
4578 0 $self->verbose (1, ' ', __x('comments count unchanged: {count}',
4579 count => $comments_count));
4580  
4581 } else {
4582 0 local $self->{'rss_get_links'} = 0;
4583 0 local $self->{'rss_get_comments'} = 0;
4584 0 local $self->{'comments_count'} = $comments_count;
4585 # "Re:" is not translated, variants of that are very annoying
4586 0 local $self->{'getting_rss_comments'} = "Re: $subject";
4587 0 local $self->{'References:'} = $msgid;
4588 0 $new += fetch_rss ($self, $self->{'nntp_group'}, $comments_rss_url);
4589 }
4590 }
4591 }
4592 0 return $new;
4593 }
4594  
4595 0 ▶sub item_to_comments_rss {
Subroutine item_to_comments_rss: not called CC=11 SCAR=48.8
Pod undocumented
4596 0 my ($self, $item) = @_;
4597 0 my ($url, $url_elt);
4598  
4599 # Atom <link rel='replies' type='application/atom+xml'
4600 # href='http:/...' />
4601 0 foreach my $elt ($item->children('link')) {
4602 0 ▶ my $rel = ($elt->att('rel')
Condition0%0/5
($elt->att("rel") // $elt->att("atom:rel")) // (next)
l!l
00
$elt->att("rel") // $elt->att("atom:rel")
l!l&&r!l&&!r
000
MC/DC0%0/2
($elt->att("rel") // $elt->att("atom:rel")) // (next)
$elt->att("rel") $elt->att("atom:rel")
Truth table0%0/3
A // B
A= $elt->att("rel")B= $elt->att("atom:rel")
ABresult
1X1
011
000
4603 // $elt->att('atom:rel')
4604 // next);
4605 0 ▶ $rel eq 'replies' or next;
Branch: 1 branch
BranchTrueFalseTotal
$rel eq "replies" or next 0 0 0
4606 0 ▶ $self->atom_link_is_rss($elt) or next;
Branch: 1 branch
BranchTrueFalseTotal
$self->atom_link_is_rss($elt) or next 0 0 0
4607 0 ▶ my $href = ($elt->att('href')
Condition0%0/3
$elt->att("href") // $elt->att("atom:href")
l!l&&r!l&&!r
000
MC/DC0%0/2
$elt->att("href") // $elt->att("atom:href")
$elt->att("href") $elt->att("atom:href")
Truth table0%0/3
A // B
A= $elt->att("href")B= $elt->att("atom:href")
ABresult
1X1
011
000
4608 // $elt->att('atom:href'));
4609 0 ▶ if (is_non_empty ($href)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty($href)) 0 0 0
4610 0 $url = $href;
4611 0 $elt = $url_elt;
4612 }
4613 }
4614  
4615 # <wfw:commentRss>http://...</wfw:commentRss>
4616 # it appeared in the spec page as wfw:commentRSS, so ignore case
4617 0 ▶ if (! defined $url) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $url) 0 0 0
4618 0 my $u = $item->first_child_trimmed_text (qr/^wfw:commentRss$/i);
4619 0 ▶ if (is_non_empty ($u)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_non_empty($u)) 0 0 0
4620 0 $url = $u;
4621 }
4622 }
4623  
4624 0 ▶ return ($url,
Condition0%0/3
defined $url && $self->item_elt_comments_count($item, $url_elt)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $url && $self->item_elt_comments_count($item, $url_elt)
defined $url $self->item_elt_comments_count($item, $url_elt)
Truth table0%0/3
A && B
A= defined $urlB= $self->item_elt_comments_count($item, $url_elt)
ABresult
0X0
100
111
4625 (defined($url) && $self->item_elt_comments_count($item,$url_elt)));
4626 }
4627  
4628 # <jf:replyCount> is merely informational about how many other <item>s there
4629 # are which are replies, there's no comments link as such for it to refer
4630 # to, it seems
4631 0 ▶sub item_elt_comments_count {
Subroutine item_elt_comments_count: not called CC=8 SCAR=42.8
Pod undocumented
4632 0 my ($self, $item, $elt) = @_;
4633 0 ▶ return (($elt && $elt->att('thr:count'))
Condition0%0/21
((($elt && $elt->att("thr:count") // $elt && $elt->att("count")) // $elt && $elt->att("atom:count")) // non_empty($item->first_child_trimmed_text("thr:total"))) // non_empty($item->first_child_trimmed_text("slash:comments"))
l!l&&r!l&&!r
000
(($elt && $elt->att("thr:count") // $elt && $elt->att("count")) // $elt && $elt->att("atom:count")) // non_empty($item->first_child_trimmed_text("thr:total"))
l!l&&r!l&&!r
000
($elt && $elt->att("thr:count") // $elt && $elt->att("count")) // $elt && $elt->att("atom:count")
l!l&&r!l&&!r
000
$elt && $elt->att("thr:count") // $elt && $elt->att("count")
l!l&&r!l&&!r
000
$elt and $elt->att("thr:count")
!ll&&!rl&&r
000
$elt and $elt->att("count")
!ll&&!rl&&r
000
$elt and $elt->att("atom:count")
!ll&&!rl&&r
000
MC/DC0%0/8
((($elt && $elt->att("thr:count") // $elt && $elt->att("count")) // $elt && $elt->att("atom:count")) // non_empty($item->first_child_trimmed_text("thr:total"))) // non_empty($item->first_child_trimmed_text("slash:comments"))
$elt $elt->att("thr:count") $elt $elt->att("count") $elt $elt->att("atom:count") non_empty($item->first_child_trimmed_text("thr:total")) non_empty($item->first_child_trimmed_text("slash:comments"))
Truth table0%0/31
A and B // C and D // E and F // G // H
A= $eltB= $elt->att("thr:count")C= $eltD= $elt->att("count")E= $eltF= $elt->att("atom:count")G= non_empty($item->first_child_trimmed_text("thr:total"))H= non_empty($item->first_child_trimmed_text("slash:comments"))
ABCDEFGHresult
11XXXXXX1
0X11XXXX1
1011XXXX1
0X0X11XX1
0X1011XX1
100X11XX1
101011XX1
0X0X0X1X1
0X0X101X1
0X100X1X1
0X10101X1
100X0X1X1
100X101X1
10100X1X1
1010101X1
0X0X0X011
0X0X10011
0X100X011
0X1010011
100X0X011
100X10011
10100X011
101010011
0X0X0X000
0X0X10000
0X100X000
0X1010000
100X0X000
100X10000
10100X000
101010000
4634 // ($elt && $elt->att('count'))
4635 // ($elt && $elt->att('atom:count'))
4636 // non_empty ($item->first_child_trimmed_text('thr:total'))
4637 // non_empty ($item->first_child_trimmed_text('slash:comments')));
4638 }
4639 2 @known{qw(/channel/item/jf:replyCount
4640 )} = ();
4641  
4642 # $group is a string, the name of a local newsgroup
4643 # $url is a string, an RSS feed to be read
4644 #
4645 0 ▶sub fetch_rss {
Subroutine fetch_rss: not called CC=14 SCAR=53.5
Pod documented
4646 0 my ($self, $group, $url, %options) = @_;
4647 0 local @{$self}{keys %options} = values %options; # hash slice
4648 0 $self->verbose (2, "fetch_rss: $group $url");
4649  
4650 0 my $group_uri = URI->new($group,'news');
4651 0 local $self->{'nntp_host'} = uri_to_nntp_host ($group_uri);
4652 0 local $self->{'nntp_group'} = $group = $group_uri->group;
4653 0 ▶ $self->nntp_group_check($group) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->nntp_group_check($group) or return 0 0 0 0
4654  
4655 # an in-memory cookie jar, used only per-RSS feed and then discarded,
4656 # which means only kept for fetching for $self->{'rss_get_links'} from a
4657 # feed
4658 0 $self->ua->cookie_jar({});
4659  
4660 0 ▶ if (defined $self->{'getting_rss_comments'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'getting_rss_comments'}) { } 0 0 0
4661 0 $self->verbose (1, ' ', __x('rss comments: {url}', url => $url));
4662 } else {
4663 0 $self->verbose (1, __x('feed: {url}', url => $url));
4664 }
4665 0 require HTTP::Request;
4666 0 my $req = HTTP::Request->new (GET => $url);
4667 0 ▶ $self->status_etagmod_req($req,1) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->status_etagmod_req($req, 1) or return 0 0 0 0
4668  
4669 # $req->uri can be a URI object or a string
4670 0 local $self->{'uri'} = URI->new ($req->uri);
4671  
4672 0 my $resp = $self->ua->request($req);
4673 0 ▶ if ($resp->code == 304) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->code == 304) 0 0 0
4674 0 $self->status_unchanged ($url);
4675 0 return 0;
4676 }
4677 0 ▶ if (! $resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
4678 0 print __x("rss2leafnode: {url}\n {status}\n",
4679 url => $url,
4680 status => $resp->status_line);
4681 0 return 0;
4682 }
4683 0 local $self->{'resp'} = $resp;
4684 0 my $bytes = length($resp->as_string);
4685  
4686 0 $self->verbose (3, "response:", $resp->dump, "\n"); # extra newline
4687 0 ▶ $resp->decode
Branch: 1 branch
BranchTrueFalseTotal
$resp->decode or die "Oops, cannot decode Content-Encoding: ", $self->header("Content-Encoding") 0 0 0
4688 or die "Oops, cannot decode Content-Encoding: ",
4689 $self->header("Content-Encoding");
4690  
4691 0 my $xml = $resp->content; # raw bytes
4692 0 $xml = $self->enforce_rss_charset_override ($xml);
4693  
4694 0 my ($twig, $err) = $self->twig_parse($xml);
4695 0 ▶ if (defined $err) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err) 0 0 0
4696 0 my $message = __x("XML::Twig parse error on\n\n {url}\n\n",
4697 url => $url);
4698 0 ▶ if ($resp->request->uri ne $url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->request->uri ne $url) 0 0 0
4699 0 $message .= __x("which redirected to\n\n {url}\n\n",
4700 url => $resp->request->uri);
4701 }
4702 0 $message .= $err . "\n\n" . __("Raw XML below.\n") . "\n";
4703 0 $self->error_message
4704 (__x("Error parsing {url}", url => $url),
4705 $message, $xml);
4706 # after successful error message to news
4707 0 $self->status_etagmod_resp ($url, $resp);
4708 0 return 0;
4709 }
4710 0 ▶ if ($self->{'verbose'} >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} >= 3) 0 0 0
4711 0 require Data::Dumper;
4712 0 $self->verbose (3,
4713 Data::Dumper->new([$twig->root],['root'])
4714 ->Indent(1)->Sortkeys(1)->Dump);
4715 }
4716  
4717 # "item" for RSS/RDF, "entry" for Atom
4718 0 my @items = $twig->descendants(qr/^(item|entry)$/);
4719  
4720 0 @items = $self->rss_newest_only_items(@items);
4721  
4722 0 my $new = 0;
4723 0 foreach my $item (@items) {
4724 0 $new += $self->fetch_rss_process_one_item ($item);
4725 }
4726  
4727 0 ▶ if ($self->{'verbose'} >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} >= 2) 0 0 0
4728 0 my $jar = $self->ua->cookie_jar;
4729 0 ▶ if ($jar && (my $str = $jar->as_string ne '')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jar and my $str = $jar->as_string ne '') { } 0 0 0
Condition0%0/3
$jar and my $str = $jar->as_string ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$jar and my $str = $jar->as_string ne ""
$jar my $str = $jar->as_string ne ""
Truth table0%0/3
A and B
A= $jarB= my $str = $jar->as_string ne ""
ABresult
0X0
100
111
4730 0 $self->verbose (2, "accumulated cookies from this feed:\n", $str);
4731 } else {
4732 0 $self->verbose (2, 'no cookies from this feed');
4733 }
4734 }
4735 0 $self->ua->cookie_jar (undef);
4736  
4737 0 $self->status_etagmod_resp ($url, $resp, $twig);
4738 0 say __xn('{group}: {count} new article, from {bytes} bytes feed',
4739 '{group}: {count} new articles, from {bytes} bytes feed',
4740 $new,
4741 group => $group,
4742 count => $new,
4743 bytes => $bytes);
4744  
4745 0 return $new;
4746 }
4747  
4748 2 1;
4749 __END__
↑ Summary RSS2Leafnode/XML/Twig/Other.pm »