| 1 | # Copyrights 2008-2020 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # This code is part of distribution XML-LibXML-Simple. Meta-POD processed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # with OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | package XML::LibXML::Simple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | $VERSION = '1.01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | our @EXPORT = qw(XMLin); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | our @EXPORT_OK = qw(xml_in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use XML::LibXML (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use File::Basename qw/fileparse/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Data::Dumper; #to be removed | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | my %known_opts = map +($_ => 1), | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | qw(keyattr keeproot forcecontent contentkey noattr searchpath | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | forcearray grouptags nsexpand normalisespace normalizespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | valueattr nsstrip parser parseropts hooknodes suppressempty); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | my @default_attributes = qw(name key id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | my $default_content_key = 'content'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | #------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | sub new(@) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 84 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 84 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 84 | my $opts = $self->{opts} = $self->_take_opts(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # parser object cannot be reused | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | !defined $opts->{parser} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 84 | ▶ | or error __x"parser option for XMLin only"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 84 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | #------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | sub XMLin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 84 | ▶ | { my $self = @_ > 1 && blessed $_[0] && $_[0]->isa(__PACKAGE__) ? shift | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
XMLin: called CC=9 SCAR=23.4
Pod
documented
Branch: 1 branch
Condition83%5/6
@_ > 1 and builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
@_ > 1 and builtin::blessed($_[0])
MC/DC0%0/3
@_ > 1 and builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
@_ > 1
builtin::blessed($_[0])
$_[0]->isa(__PACKAGE__)
Truth table75%3/4
A and B and C
A= @_ > 1B= builtin::blessed($_[0])C= $_[0]->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | : __PACKAGE__->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 84 | my $target = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 84 | my $this = $self->_take_opts(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 82 | my $opts = $self->_init($self->{opts}, $this); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 82 | ▶ | my $xml = $self->_get_xml($target, $opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 79 | ▶ | if(my $cb = $opts->{hooknodes}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | { $self->{XCS_hooks} = $cb->($self, $xml); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 79 | my $top = $self->collapse($xml, $opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 79 | ▶ | if($opts->{keeproot}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | { my $subtop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | = $opts->{forcearray_always} && ref $top ne 'ARRAY' ? [$top] : $top; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opts->{"forcearray_always"} and ref $top ne "ARRAY"
MC/DC0%0/2
$opts->{"forcearray_always"} and ref $top ne "ARRAY"
$opts->{"forcearray_always"}
ref $top ne "ARRAY"
Truth table33%1/3
A and B
A= $opts->{"forcearray_always"}B= ref $top ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | $top = +{ $xml->localName => $subtop }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 79 | $top; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | *xml_in = \&XMLin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | sub _get_xml($$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 82 | ▶ | { my ($self, $source, $opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_xml: called CC=11 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 82 | ▶ | $source = $self->default_data_source($opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | unless defined $source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 82 | ▶ | $source = \*STDIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | if $source eq '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | my $parser = $opts->{parser} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 82 | ▶ | || $self->_create_parser($opts->{parseropts}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts->{'parser'} || $self->_create_parser($opts->{'parseropts'})
MC/DC0%0/2
$opts->{'parser'} || $self->_create_parser($opts->{'parseropts'})
$opts->{'parser'}
$self->_create_parser($opts->{'parseropts'})
Truth table33%1/3
A || B
A= $opts->{'parser'}B= $self->_create_parser($opts->{'parseropts'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | my $xml | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | = blessed $source && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ( $source->isa('XML::LibXML::Document') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | || $source->isa('XML::LibXML::Element' )) ? $source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | : ref $source eq 'SCALAR' ? $parser->parse_string($$source) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | : ref $source ? $parser->parse_fh($source) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | : $source =~ m{^\s*\<.*?\>\s*$}s ? $parser->parse_string($source) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | : $parser->parse_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 82 | ▶ | ($self->find_xml_file($source, @{$opts->{searchpath}})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition50%3/6
builtin::blessed($source) and $source->isa("XML::LibXML::Document") || $source->isa("XML::LibXML::Element")
$source->isa("XML::LibXML::Document") or $source->isa("XML::LibXML::Element")
MC/DC0%0/3
builtin::blessed($source) and $source->isa("XML::LibXML::Document") || $source->isa("XML::LibXML::Element")
builtin::blessed($source)
$source->isa("XML::LibXML::Document")
$source->isa("XML::LibXML::Element")
Truth table50%2/4
A and B or C
A= builtin::blessed($source)B= $source->isa("XML::LibXML::Document")C= $source->isa("XML::LibXML::Element")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 79 | ▶ | $xml = $xml->documentElement | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | if $xml->isa('XML::LibXML::Document'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 79 | $xml; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | sub _create_parser(@) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 82 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_parser: called CC=3 SCAR=13.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my @popt = @_ != 1 ? @_ : ref $_[0] eq 'HASH' ? %{$_[0]} : @{$_[0]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | XML::LibXML->new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ( line_numbers => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | , no_network => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | , expand_xinclude => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | , expand_entities => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | , load_ext_dtd => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | , ext_ent_handler => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub { alert __x"parsing external entities disabled"; '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | , @popt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 82 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | sub _take_opts(@) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 168 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_take_opts: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 168 | my %opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 168 | ▶ | @_ % 2==0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | or die "ERROR: odd number of options.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 167 | ▶ | while(@_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 119 | { my ($key, $val) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 119 | my $lkey = lc $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 119 | $lkey =~ s/_//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 119 | ▶ | $known_opts{$lkey} or croak "Unrecognised option: $key"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 118 | $opts{$lkey} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 166 | \%opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # Returns the name of the XML file to parse if no filename or XML string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # was provided explictly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | sub default_data_source($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | { my ($self, $opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_data_source: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | my ($basename, $script_dir, $ext) = fileparse $0, qr[\.[^\.]+]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # Add script directory to searchpath | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | unshift @{$opts->{searchpath}}, $script_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | if $script_dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | "$basename.xml"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | sub _init($$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 82 | ▶ | { my ($self, $global, $this) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=23 SCAR=31.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 82 | my %opt = (%$global, %$this); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 82 | ▶ | if(defined $opt{contentkey}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 48 | { $opt{collapseagain} = $opt{contentkey} =~ s/^\-// } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 34 | else { $opt{contentkey} = $default_content_key } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 82 | ▶ | $opt{normalisespace} ||= $opt{normalizespace} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
$opt{"normalisespace"} ||= $opt{"normalizespace"} || 0
$opt{'normalizespace'} || 0
MC/DC100%2/2
$opt{"normalisespace"} ||= $opt{"normalizespace"} || 0
$opt{"normalisespace"}
$opt{'normalizespace'}
Truth table100%3/3
A ||= B
A= $opt{"normalisespace"}B= $opt{'normalizespace'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 82 | ▶ | $opt{searchpath} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt{"searchpath"} ||= []
MC/DC100%1/1
$opt{"searchpath"} ||= []
$opt{"searchpath"}
Truth table100%2/2
A
A= $opt{"searchpath"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ref $opt{searchpath} eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 82 | ▶ | or $opt{searchpath} = [ $opt{searchpath} ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 82 | ▶ | my $fa = delete $opt{forcearray} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $opt{'forcearray'} || 0
MC/DC100%1/1
delete $opt{'forcearray'} || 0
delete $opt{'forcearray'}
Truth table100%2/2
A
A= delete $opt{'forcearray'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 82 | my (@fa_regex, %fa_elem); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 82 | ▶ | if(ref $fa) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 6 | ▶ | { foreach (ref $fa eq 'ARRAY' ? @$fa : $fa) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 8 | ▶ | { if(ref $_ eq 'Regexp') { push @fa_regex, $_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 5 | else { $fa_elem{$_} = 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 76 | else { $opt{forcearray_always} = $fa } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 82 | $opt{forcearray_regex} = \@fa_regex; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 82 | $opt{forcearray_elem} = \%fa_elem; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # Special cleanup for {keyattr} which could be arrayref or hashref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # which behave differently. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 82 | ▶ | my $ka = $opt{keyattr} || \@default_attributes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt{'keyattr'} || \@default_attributes
MC/DC100%1/1
$opt{'keyattr'} || \@default_attributes
$opt{'keyattr'}
Truth table100%2/2
A
A= $opt{'keyattr'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 82 | ▶ | $ka = [ $ka ] unless ref $ka; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 82 | ▶ | if(ref $ka eq 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 62 | ▶ | { if(@$ka) { $opt{keyattr} = $ka } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | else { delete $opt{keyattr} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | elsif(ref $ka eq 'HASH') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | { # Convert keyattr => { elem => '+attr' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # to keyattr => { elem => [ 'attr', '+' ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 20 | my %at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 20 | ▶ | while(my($k,$v) = each %$ka) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 23 | { $v =~ /^(\+|-)?(.*)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 23 | ▶ | $at{$k} = [ $2, $1 || '' ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$1 || ''
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 20 | $opt{keyattr} = \%at; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Special cleanup for {valueattr} which could be arrayref or hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 82 | ▶ | my $va = delete $opt{valueattr} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $opt{'valueattr'} || {}
MC/DC100%1/1
delete $opt{'valueattr'} || {}
delete $opt{'valueattr'}
Truth table100%2/2
A
A= delete $opt{'valueattr'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 82 | ▶ | $va = +{ map +($_ => 1), @$va } if ref $va eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 82 | $opt{valueattrlist} = $va; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # make sure there's nothing weird in {grouptags} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 82 | ▶ | !$opt{grouptags} || ref $opt{grouptags} eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $opt{"grouptags"} or ref $opt{"grouptags"} eq "HASH"
MC/DC0%0/2
not $opt{"grouptags"} or ref $opt{"grouptags"} eq "HASH"
not $opt{"grouptags"}
ref $opt{"grouptags"} eq "HASH"
Truth table66%2/3
not(A) or B
A= not $opt{"grouptags"}B= ref $opt{"grouptags"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | or croak "Illegal value for 'GroupTags' option -expected a hashref"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 82 | ▶ | $opt{parseropts} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt{"parseropts"} ||= {}
MC/DC0%0/1
$opt{"parseropts"} ||= {}
$opt{"parseropts"}
Truth table50%1/2
A
A= $opt{"parseropts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 82 | \%opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | sub find_xml_file($@) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | ▶ | { my ($self, $file) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_xml_file: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 7 | ▶ | my @search_path = @_ ? @_ : '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 7 | my ($filename, $filedir) = fileparse $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 7 | ▶ | if($filename eq $file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | { foreach my $path (@search_path) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 6 | { my $fullpath = File::Spec->catfile($path, $file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 6 | ▶ | return $fullpath if -e $fullpath; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | elsif(-e $file) # Ignore searchpath if dir component | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | { return $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | local $" = ':'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 3 | die "data source $file not found in @search_path\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | sub _add_kv($$$$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 540 | ▶ | { my ($d, $k, $v, $opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_kv: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 540 | ▶ | if(defined $d->{$k}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | { # Combine duplicate attributes into arrayref if required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 97 | ▶ | if(ref $d->{$k} eq 'ARRAY') { push @{$d->{$k}}, $v } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 51 | else { $d->{$k} = [ $d->{$k}, $v ] } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | elsif(ref $v eq 'ARRAY') { push @{$d->{$k}}, $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | ▶ | elsif(ref $v eq 'HASH' | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
ref $v eq "HASH" and $k ne $opts->{"contentkey"} and $opts->{"forcearray_always"}
ref $v eq "HASH" and $k ne $opts->{"contentkey"}
MC/DC66%2/3
ref $v eq "HASH" and $k ne $opts->{"contentkey"} and $opts->{"forcearray_always"}
ref $v eq "HASH"
$k ne $opts->{"contentkey"}
$opts->{"forcearray_always"}
Truth table75%3/4
A and B and C
A= ref $v eq "HASH"B= $k ne $opts->{"contentkey"}C= $opts->{"forcearray_always"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | && $k ne $opts->{contentkey} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 24 | && $opts->{forcearray_always}) { push @{$d->{$k}}, $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | ▶ | elsif($opts->{forcearray_elem}{$k} | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opts->{"forcearray_elem"}{$k} or grep(($k =~ /$_/), @{$$opts{"forcearray_regex"};})
MC/DC100%2/2
$opts->{"forcearray_elem"}{$k} or grep(($k =~ /$_/), @{$$opts{"forcearray_regex"};})
$opts->{"forcearray_elem"}{$k}
grep(($k =~ /$_/), @{$$opts{"forcearray_regex"};})
Truth table100%3/3
A or B
A= $opts->{"forcearray_elem"}{$k}B= grep(($k =~ /$_/), @{$$opts{"forcearray_regex"};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 412 | || grep $k =~ $_, @{$opts->{forcearray_regex}} | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 12 | ) { push @{$d->{$k}}, $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 405 | else { $d->{$k} = $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 540 | $d->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # Takes the parse tree that XML::LibXML::Parser produced from the supplied | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # XML and recurse through it 'collapsing' unnecessary levels of indirection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # (nested arrays etc) to produce a data structure that is easier to work with. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | sub _expand_name($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | { my $node = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expand_name: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | my $uri = $node->namespaceURI || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$node->namespaceURI || ''
MC/DC0%0/1
$node->namespaceURI || ''
$node->namespaceURI
Truth table0%0/2
A
A= $node->namespaceURI
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | (length $uri ? "{$uri}" : '') . $node->localName; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | sub collapse($$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 383 | ▶ | { my ($self, $xml, $opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collapse: called CC=57 SCAR=48.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 383 | ▶ | $xml->isa('XML::LibXML::Element') or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 383 | my (%data, $text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 383 | my $hooks = $self->{XCS_hooks}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 383 | ▶ | unless($opts->{noattr}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | ATTR: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 366 | foreach my $attr ($xml->attributes) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 236 | my $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 236 | ▶ | if($hooks && (my $hook = $hooks->{$attr->unique_key})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$hooks and my $hook = $$hooks{$attr->unique_key}
MC/DC0%0/2
$hooks and my $hook = $$hooks{$attr->unique_key}
$hooks
my $hook = $$hooks{$attr->unique_key}
Truth table33%1/3
A and B
A= $hooksB= my $hook = $$hooks{$attr->unique_key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | { $value = $hook->($attr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | defined $value or next ATTR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 236 | { $value = $attr->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | $value = $self->normalise_space($value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 236 | ▶ | if !ref $value && $opts->{normalisespace}==2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $value and $opts->{"normalisespace"} == 2
MC/DC50%1/2
not ref $value and $opts->{"normalisespace"} == 2
not ref $value
$opts->{"normalisespace"} == 2
Truth table66%2/3
not(A) and B
A= not ref $valueB= $opts->{"normalisespace"} == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | my $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | = !$attr->isa('XML::LibXML::Attr') ? $attr->nodeName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | : $opts->{nsexpand} ? _expand_name($attr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 236 | ▶ | : $opts->{nsstrip} ? $attr->localName | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | : $attr->nodeName; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 236 | _add_kv \%data, $name => $value, $opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 383 | my $nr_attrs = keys %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 383 | my $nr_elems = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | CHILD: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 383 | foreach my $child ($xml->childNodes) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 841 | ▶ | if($child->isa('XML::LibXML::Text')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 537 | { $text .= $child->data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 537 | next CHILD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 304 | ▶ | $child->isa('XML::LibXML::Element') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | or next CHILD; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 304 | $nr_elems++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 304 | my $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 304 | ▶ | if($hooks && (my $hook = $hooks->{$child->unique_key})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$hooks and my $hook = $$hooks{$child->unique_key}
MC/DC0%0/2
$hooks and my $hook = $$hooks{$child->unique_key}
$hooks
my $hook = $$hooks{$child->unique_key}
Truth table33%1/3
A and B
A= $hooksB= my $hook = $$hooks{$child->unique_key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | { $v = $hook->($child) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 304 | else { $v = $self->collapse($child, $opts) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | next CHILD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 304 | ▶ | if ! defined $v && $opts->{suppressempty}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $v and $opts->{"suppressempty"}
MC/DC0%0/2
not defined $v and $opts->{"suppressempty"}
not defined $v
$opts->{"suppressempty"}
Truth table33%1/3
not(A) and B
A= not defined $vB= $opts->{"suppressempty"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | my $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | = $opts->{nsexpand} ? _expand_name($child) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 304 | ▶ | : $opts->{nsstrip} ? $child->localName | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | : $child->nodeName; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 304 | _add_kv \%data, $name => $v, $opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | $text = $self->normalise_space($text) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 383 | ▶ | if defined $text && $opts->{normalisespace}==2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $text and $opts->{"normalisespace"} == 2
MC/DC100%2/2
defined $text and $opts->{"normalisespace"} == 2
defined $text
$opts->{"normalisespace"} == 2
Truth table100%3/3
A and B
A= defined $textB= $opts->{"normalisespace"} == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 383 | ▶ | return $opts->{forcecontent} ? { $opts->{contentkey} => $text } : $text | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$nr_attrs + $nr_elems == 0 and defined $text
MC/DC100%2/2
$nr_attrs + $nr_elems == 0 and defined $text
$nr_attrs + $nr_elems == 0
defined $text
Truth table100%3/3
A and B
A= $nr_attrs + $nr_elems == 0B= defined $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | if $nr_attrs+$nr_elems==0 && defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 247 | ▶ | $data{$opts->{contentkey}} = $text | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $text and $nr_elems == 0
MC/DC100%2/2
defined $text and $nr_elems == 0
defined $text
$nr_elems == 0
Truth table100%3/3
A and B
A= defined $textB= $nr_elems == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | if defined $text && $nr_elems==0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # Roll up 'value' attributes (but only if no nested elements) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 247 | ▶ | if(keys %data==1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 101 | { my ($k) = keys %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 101 | ▶ | return $data{$k} if $opts->{valueattrlist}{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # Turn arrayrefs into hashrefs if key fields present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 240 | ▶ | if($opts->{keyattr}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 233 | ▶ | { while(my ($key, $val) = each %data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 459 | ▶ | { $data{$key} = $self->array_to_hash($key, $val, $opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | if ref $val eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # disintermediate grouped tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 240 | ▶ | if(my $gr = $opts->{grouptags}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | ELEMENT: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 21 | ▶ | while(my ($key, $val) = each %data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 43 | ▶ | { my $sub = $gr->{$key} or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 8 | ▶ | if(ref $val eq 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | { next ELEMENT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if grep { keys %$_!=1 || !exists $_->{$sub} } @$val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
keys %$_ != 1 || !exists $_->{$sub}
MC/DC0%0/2
keys %$_ != 1 || !exists $_->{$sub}
keys %$_ != 1
!exists $_->{$sub}
Truth table0%0/3
A || not(B)
A= keys %$_ != 1B= !exists $_->{$sub}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $data{$key} = { map { %{$_->{$sub}} } @$val }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 8 | ▶ | { ref $val eq 'HASH' && keys %$val==1 or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $val eq "HASH" and keys %$val == 1
MC/DC0%0/2
ref $val eq "HASH" and keys %$val == 1
ref $val eq "HASH"
keys %$val == 1
Truth table33%1/3
A and B
A= ref $val eq "HASH"B= keys %$val == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 8 | my ($child_key, $child_val) = %$val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | $data{$key} = $child_val | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 8 | ▶ | if $gr->{$key} eq $child_key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # Fold hashes containing a single anonymous array up into just the array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | return $data{anon} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | if keys %data == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | && exists $data{anon} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 240 | ▶ | && ref $data{anon} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
keys %data == 1 and exists $data{"anon"} and ref $data{"anon"} eq "ARRAY"
keys %data == 1 and exists $data{"anon"}
MC/DC66%2/3
keys %data == 1 and exists $data{"anon"} and ref $data{"anon"} eq "ARRAY"
keys %data == 1
exists $data{"anon"}
ref $data{"anon"} eq "ARRAY"
Truth table75%3/4
A and B and C
A= keys %data == 1B= exists $data{"anon"}C= ref $data{"anon"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # Suppress empty elements? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 228 | ▶ | if(! keys %data && exists $opts->{suppressempty}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not keys %data and exists $opts->{"suppressempty"}
MC/DC0%0/2
not keys %data and exists $opts->{"suppressempty"}
not keys %data
exists $opts->{"suppressempty"}
Truth table66%2/3
not(A) and B
A= not keys %dataB= exists $opts->{"suppressempty"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my $sup = $opts->{suppressempty}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | return +(defined $sup && $sup eq '') ? '' : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $sup and $sup eq ""
MC/DC0%0/2
defined $sup and $sup eq ""
defined $sup
$sup eq ""
Truth table0%0/3
A and B
A= defined $supB= $sup eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # Roll up named elements with named nested 'value' attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 228 | ▶ | if(my $va = $opts->{valueattrlist}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 228 | ▶ | { while(my($key, $val) = each %data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 458 | ▶ | { $va->{$key} && ref $val eq 'HASH' && keys %$val==1 or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$va->{$key} and ref $val eq "HASH" and keys %$val == 1
$va->{$key} and ref $val eq "HASH"
MC/DC33%1/3
$va->{$key} and ref $val eq "HASH" and keys %$val == 1
$va->{$key}
ref $val eq "HASH"
keys %$val == 1
Truth table50%2/4
A and B and C
A= $va->{$key}B= ref $val eq "HASH"C= keys %$val == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 4 | $data{$key} = $val->{$va->{$key}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | $nr_elems+$nr_attrs ? \%data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | : !defined $text ? {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 228 | ▶ | : $opts->{forcecontent} ? { $opts->{contentkey} => $text } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | : $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | sub normalise_space($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 20 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalise_space: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 20 | local $_ = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 20 | s/^\s+//s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 20 | s/\s+$//s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 20 | s/\s\s+/ /sg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 20 | $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # Attempts to 'fold' an array of hashes into an hash of hashes. Returns a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # reference to the hash on success or the original array if folding is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # not possible. Behaviour is controlled by 'keyattr' option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | sub array_to_hash($$$$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 84 | ▶ | { my ($self, $name, $in, $opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
array_to_hash: called CC=34 SCAR=35.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 84 | my %out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 84 | ▶ | my $ka = $opts->{keyattr} or return $in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 84 | ▶ | if(ref $ka eq 'HASH') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 28 | ▶ | { my $newkey = $ka->{$name} or return $in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 20 | my ($key, $flag) = @$newkey; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 20 | foreach my $h (@$in) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 44 | ▶ | { unless(ref $h eq 'HASH' && defined $h->{$key}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $h eq "HASH" and defined $h->{$key}
MC/DC50%1/2
ref $h eq "HASH" and defined $h->{$key}
ref $h eq "HASH"
defined $h->{$key}
Truth table66%2/3
A and B
A= ref $h eq "HASH"B= defined $h->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 2 | ▶ | { warn "<$name> element has no '$key' key attribute\n" if $^W; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 2 | return $in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 42 | my $val = $h->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 42 | ▶ | if(ref $val) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 2 | ▶ | { warn "<$name> element has non-scalar '$key' key attribute\n" if $^W; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 2 | return $in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | $val = $self->normalise_space($val) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 40 | ▶ | if $opts->{normalisespace}==1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | warn "<$name> element has non-unique value in '$key' " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 40 | ▶ | . "key attribute: $val\n" if $^W && defined $out{$val}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$^W and defined $out{$val}
MC/DC100%2/2
$^W and defined $out{$val}
$^W
defined $out{$val}
Truth table100%3/3
A and B
A= $^WB= defined $out{$val}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 40 | $out{$val} = { %$h }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 40 | ▶ | $out{$val}{"-$key"} = $out{$val}{$key} if $flag eq '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 40 | ▶ | delete $out{$val}{$key} if $flag ne '+'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | else # Arrayref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 56 | { my $default_keys = "@default_attributes" eq "@$ka"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | ELEMENT: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 56 | foreach my $h (@$in) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 78 | ▶ | { ref $h eq 'HASH' or return $in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 50 | foreach my $key (@$ka) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 81 | { my $val = $h->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 81 | ▶ | defined $val or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 42 | ▶ | if(ref $val) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 2 | ▶ | { warn "<$name> element has non-scalar '$key' key attribute" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$^W and not $default_keys
MC/DC50%1/2
$^W and not $default_keys
$^W
not $default_keys
Truth table66%2/3
A and not(B)
A= $^WB= not $default_keys
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | if $^W && ! $default_keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 2 | return $in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | $val = $self->normalise_space($val) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 40 | ▶ | if $opts->{normalisespace} == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | warn "<$name> element has non-unique value in '$key' " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 40 | ▶ | . "key attribute: $val" if $^W && $out{$val}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$^W and $out{$val}
MC/DC100%2/2
$^W and $out{$val}
$^W
$out{$val}
Truth table100%3/3
A and B
A= $^WB= $out{$val}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 40 | $out{$val} = { %$h }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 40 | delete $out{$val}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 40 | next ELEMENT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 8 | return $in; # No keyfield matched | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | $opts->{collapseagain} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 34 | ▶ | or return \%out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # avoid over-complicated structures like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | # dir => { libexecdir => { content => '$exec_prefix/libexec' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # localstatedir => { content => '$prefix' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # into | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # dir => { libexecdir => '$exec_prefix/libexec', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # localstatedir => '$prefix', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 27 | my $contentkey = $opts->{contentkey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | # first go through the values, checking that they are fit to collapse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 27 | foreach my $v (values %out) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 35 | ▶ | { next if !defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 35 | ▶ | next if ref $v eq 'HASH' && keys %$v == 1 && exists $v->{$contentkey}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $v eq "HASH" and keys %$v == 1 and exists $v->{$contentkey}
ref $v eq "HASH" and keys %$v == 1
MC/DC66%2/3
ref $v eq "HASH" and keys %$v == 1 and exists $v->{$contentkey}
ref $v eq "HASH"
keys %$v == 1
exists $v->{$contentkey}
Truth table75%3/4
A and B and C
A= ref $v eq "HASH"B= keys %$v == 1C= exists $v->{$contentkey}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 21 | ▶ | next if ref $v eq 'HASH' && !keys %$v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $v eq "HASH" and not keys %$v
MC/DC0%0/2
ref $v eq "HASH" and not keys %$v
ref $v eq "HASH"
not keys %$v
Truth table33%1/3
A and not(B)
A= ref $v eq "HASH"B= not keys %$v
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 21 | return \%out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 6 | $out{$_} = $out{$_}{$contentkey} for keys %out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 6 | \%out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||