| 1 | # Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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 | package App::RSS2Leafnode::XML::Twig::Other; | ||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use 5.004; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use vars '$VERSION', '@ISA', '@EXPORT_OK'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 2 | $VERSION = 79; | |||||||||||||||||||||||||||||||||
| 25 | 2 | @ISA = ('Exporter'); | |||||||||||||||||||||||||||||||||
| 26 | 2 | @EXPORT_OK = (qw(elt_is_empty | |||||||||||||||||||||||||||||||||
| 27 | elt_tree_strip_prefix | ||||||||||||||||||||||||||||||||||
| 28 | )); | ||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | # XML::Twig | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub elt_is_empty { | ||||||||||||||||||||||||||||||||
|
Subroutine
elt_is_empty: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 33 | 0 | my ($elt) = @_; | |||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return ($elt->has_no_atts | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$elt->has_no_atts && !$elt->has_child && $elt->text_only =~ /^\s*$/
$elt->has_no_atts and not $elt->has_child
MC/DC0%0/3
$elt->has_no_atts && !$elt->has_child && $elt->text_only =~ /^\s*$/
$elt->has_no_atts
not $elt->has_child
$elt->text_only =~ /^\s*$/
Truth table0%0/4
A and not(B) && C
A= $elt->has_no_attsB= not $elt->has_childC= $elt->text_only =~ /^\s*$/
| |||||||||||||||||||||||||||||||||||
| 35 | && ! $elt->has_child | ||||||||||||||||||||||||||||||||||
| 36 | && $elt->text_only =~ /^\s*$/); | ||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub elt_tree_strip_prefix { | ||||||||||||||||||||||||||||||||
|
Subroutine
elt_tree_strip_prefix: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($elt, $prefix) = @_; | |||||||||||||||||||||||||||||||||
| 41 | 0 | foreach my $child ($elt->descendants_or_self(qr/^\Q$prefix\E:/)) { | |||||||||||||||||||||||||||||||||
| 42 | 0 | $child->set_tag ($child->local_name); | |||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | # Return a URI object for string $url. | ||||||||||||||||||||||||||||||||||
| 47 | # If $url is relative then it's resolved against xml:base, if available, to | ||||||||||||||||||||||||||||||||||
| 48 | # make it absolute. | ||||||||||||||||||||||||||||||||||
| 49 | # If $url is undef then return undef, which is handy if passing a possibly | ||||||||||||||||||||||||||||||||||
| 50 | # attribute like $elt->att('href'). | ||||||||||||||||||||||||||||||||||
| 51 | # The feed toplevel has an xml:base set to the feed location if no other | ||||||||||||||||||||||||||||||||||
| 52 | # value, so elt_xml_based_uri() ends up relative to the feed location if no | ||||||||||||||||||||||||||||||||||
| 53 | # other xml:base. | ||||||||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub elt_xml_based_uri { | ||||||||||||||||||||||||||||||||
|
Subroutine
elt_xml_based_uri: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 56 | 0 | my ($elt, $url_str) = @_; | |||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if (! defined $url_str) { return undef; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 58 | 0 | require URI; | |||||||||||||||||||||||||||||||||
| 59 | 0 | my $uri = URI->new ($url_str); | |||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (my $base = elt_xml_base ($elt)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 61 | 0 | return $uri->abs ($base); | |||||||||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||||||||
| 63 | 0 | return $uri; | |||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | # Return a URI object for the xml:base applying to $elt, or undef. | ||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub elt_xml_base { | ||||||||||||||||||||||||||||||||
|
Subroutine
elt_xml_base: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 69 | 0 | my ($elt) = @_; | |||||||||||||||||||||||||||||||||
| 70 | 0 | my @relative; | |||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | for ( ; $elt; $elt = $elt->parent) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | next if ! defined (my $base = $elt->att('xml:base')); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 73 | 0 | $base = URI->new($base); | |||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if (defined $base->scheme) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | # an absolute URL | ||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | while (@relative) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 77 | 0 | $base = (pop @relative)->abs($base); | |||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||
| 79 | 0 | return $base; | |||||||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||||||||
| 81 | # a relative path | ||||||||||||||||||||||||||||||||||
| 82 | 0 | push @relative, $base; | |||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | # oops, no base, only relative paths | ||||||||||||||||||||||||||||||||||
| 86 | 0 | return undef; | |||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||||||||