Branch Coverage

blib/lib/XML/Simple.pm
Criterion Covered Total %
branch 407 454 89.6


line true false branch
96 1 10 if grep /^:strict$/, @_
112 1 270 if (@_ % 2)
121 270 0 unless exists $raw_opt{'strictmode'}
126 1 308 unless exists $known_opt{$lkey}
148 486 271 if $package eq 'XML::Simple'
149 1 270 if $set_mode
165 203 243 if ($_[0] and UNIVERSAL::isa($_[0], 'XML::Simple')) { }
195 1 179 if (not defined $target) { }
2 177 elsif ($target eq '-') { }
2 175 elsif (my $type = ref $target) { }
147 28 elsif ($target =~ /<.*?>/s) { }
206 0 2 if ($type eq 'SCALAR') { }
237 1 26 unless defined $filename
243 17 7 if ($self->{'opt'}{'cache'})
247 8 9 if $opt
253 9 7 if ($self->{'opt'}{'cache'})
272 0 0 defined $fh ? :
0 2 unless ref $fh
294 136 0 ref $string ? :
314 1 0 if ($script_dir)
335 0 154 if $@
339 5 149 $self->{'opt'}{'keeproot'} ? :
368 147 7 unless (defined $preferred_parser)
371 0 154 if ($preferred_parser eq 'XML::Parser')
376 0 154 if ($@)
377 0 0 if ($preferred_parser)
383 0 154 if $preferred_parser
389 16 138 if ($filename) { }
393 2 136 if (ref $string and ref $string ne 'SCALAR') { }
423 0 0 if ($@)
427 0 0 if ($self->{'opt'}{'nsexpand'})
433 0 0 if ($filename) { }
435 0 0 unless open my $xfh, '<', $filename
460 0 5 if ('VMS' eq $^O) { }
484 2 6 unless -r $cachefile
485 3 3 unless (stat $cachefile)[9] > (stat $filename)[9]
489 0 3 if ('VMS' eq $^O) { }
538 1 3 unless $MemShareCache{$filename}
539 1 2 unless $MemShareCache{$filename}[0] > (stat $filename)[9]
572 1 3 unless $MemCopyCache{$filename}
573 1 2 unless $MemCopyCache{$filename}[0] > (stat $filename)[9]
592 2 84 unless @_
600 3 76 if ($self->{'opt'}{'nsexpand'})
609 4 75 if (UNIVERSAL::isa($ref, 'ARRAY'))
616 2 77 if ($self->{'opt'}{'keeproot'}) { }
5 72 elsif ($self->{'opt'}{'rootname'} eq '') { }
618 2 0 if (@keys == 1)
627 3 2 if (UNIVERSAL::isa($ref, 'HASH'))
631 3 4 if (ref $refsave->{$_}) { }
648 2 75 if ($self->{'opt'}{'xmldecl'})
652 2 75 if ($self->{'opt'}{'outputfile'}) { }
2 73 elsif ($self->{'opt'}{'handler'}) { }
653 1 1 if (ref $self->{'opt'}{'outputfile'}) { }
655 0 1 if (UNIVERSAL::isa($fh, 'GLOB') and not UNIVERSAL::can($fh, 'print'))
657 0 0 if $@
662 0 1 unless open my $out, '>', "$self->{'opt'}{'outputfile'}"
664 1 0 if $] >= 5.008
665 0 1 unless print $out $xml
666 0 1 unless close $out
706 187 84 if ($dirn eq 'in') { }
716 2 269 if (@_ % 2)
726 2 267 unless $known_opt{$lkey}
734 4724 267 unless (exists $opt->{$_})
735 314 4410 if (exists $self->{'def_opt'}{$_})
744 20 247 if (exists $opt->{'rootname'}) { }
745 1 19 unless (defined $opt->{'rootname'})
753 1 266 if ($opt->{'xmldecl'} and $opt->{'xmldecl'} eq '1')
757 69 198 if (exists $opt->{'contentkey'}) { }
758 61 8 if ($opt->{'contentkey'} =~ /^-(.*)$/)
767 263 4 unless (exists $opt->{'normalisespace'})
770 262 5 unless defined $opt->{'normalisespace'}
774 3 264 if ($opt->{'searchpath'}) { }
775 2 1 unless (ref $opt->{'searchpath'})
783 18 249 if ($opt->{'cache'} and not ref $opt->{'cache'})
786 19 248 if ($opt->{'cache'})
790 2 17 unless $self->can($method)
795 0 265 if (exists $opt->{'parseropts'}) { }
796 0 0 if (warnings::enabled())
809 36 229 if (exists $opt->{'forcearray'}) { }
810 1 35 if (ref $opt->{'forcearray'} eq 'Regexp')
814 16 20 if (ref $opt->{'forcearray'} eq 'ARRAY') { }
816 14 2 if (@force_list) { }
819 3 18 if (ref $tag eq 'Regexp') { }
832 16 4 $opt->{'forcearray'} ? :
836 3 226 if ($opt->{'strictmode'} and $dirn eq 'in')
846 78 184 if (exists $opt->{'keyattr'}) { }
847 74 4 if (ref $opt->{'keyattr'}) { }
848 58 16 if (ref $opt->{'keyattr'} eq 'HASH') { }
859 64 0 if ($opt->{'keyattr'}{$el} =~ /^(\+|-)?(.*)$/) { }
860 8 56 $1 ? :
861 9 55 if ($opt->{'strictmode'} and $dirn eq 'in')
862 3 6 if $opt->{'forcearray'} == 1
864 2 2 if ref $opt->{'forcearray'} eq 'HASH' and $opt->{'forcearray'}{$el}
874 4 12 if (@{$opt->{'keyattr'};} == 0)
884 4 180 if ($opt->{'strictmode'})
893 5 249 if (exists $opt->{'valueattr'})
894 2 3 if (ref $opt->{'valueattr'} eq 'ARRAY')
902 14 240 if ($opt->{'grouptags'})
904 1 13 unless UNIVERSAL::isa($opt->{'grouptags'}, 'HASH')
907 14 1 if $key ne $val
915 1 251 if ($opt->{'variables'} and not UNIVERSAL::isa($opt->{'variables'}, 'HASH'))
919 4 247 if ($opt->{'variables'}) { }
2 245 elsif ($opt->{'varattr'}) { }
949 23 4 if ($filename ne $file) { }
950 22 1 if -e $file
956 2 3 if -e $fullpath
962 1 2 unless (@search_path)
963 0 1 if -e $file
1005 36 3501 if ($self->{'opt'}{'noattr'}) { }
15 3486 elsif ($self->{'opt'}{'normalisespace'} == 2) { }
1017 37 3500 if (my $var = $self->{'_var_values'})
1027 42 3495 if (not @_ and keys %$attr == 1)
1029 7 1 if ($self->{'opt'}{'valueattrlist'} and $self->{'opt'}{'valueattrlist'}{$k})
1041 0 8308 unless defined $val
1043 3376 4932 if (ref $val) { }
4932 0 elsif ($key eq '0') { }
1045 6 2 if not defined $val and $self->{'opt'}{'suppressempty'}
1048 3664 1268 if $val =~ /^\s*$/s
1051 10 1258 if $self->{'opt'}{'normalisespace'} == 2
1055 26 1242 if (my $var = $self->{'_var_values'})
1062 23 1245 if (my $var = $self->{'opt'}{'varattr'})
1063 10 13 if (exists $attr->{$var})
1071 1141 1 unless (%$attr or @_)
1073 2 1139 $self->{'opt'}{'forcecontent'} ? :
1082 2859 638 if (exists $attr->{$key}) { }
4 634 elsif (defined $val and UNIVERSAL::isa($val, 'ARRAY')) { }
1083 2729 130 if (UNIVERSAL::isa($attr->{$key}, 'ARRAY')) { }
1094 194 440 if ($key ne $self->{'opt'}{'contentkey'} and $self->{'opt'}{'forcearray'} == 1 || ref $self->{'opt'}{'forcearray'} eq 'HASH' && ($self->{'opt'}{'forcearray'}{$key} || grep(($key =~ /$_/), @{$$self{'opt'}{'forcearray'}{'_regex'};}))) { }
1118 2367 22 if ($self->{'opt'}{'keyattr'})
1120 322 4403 if (defined $val and UNIVERSAL::isa($val, 'ARRAY'))
1129 26 2358 if ($self->{'opt'}{'grouptags'})
1131 41 10 unless UNIVERSAL::isa($val, 'HASH') and keys %$val == 1
1132 1 9 unless exists $self->{'opt'}{'grouptags'}{$key}
1136 8 1 if ($self->{'opt'}{'grouptags'}{$key} eq $child_key)
1146 61 145 if ($count == 1 and exists $attr->{'anon'} and UNIVERSAL::isa($attr->{'anon'}, 'ARRAY'))
1156 11 2 if (not %$attr and exists $self->{'opt'}{'suppressempty'})
1157 2 9 if (defined $self->{'opt'}{'suppressempty'} and $self->{'opt'}{'suppressempty'} eq '')
1167 10 2302 if ($self->{'opt'}{'valueattr'})
1169 14 4 unless $self->{'opt'}{'valueattr'}{$key}
1170 0 4 unless UNIVERSAL::isa($val, 'HASH') and keys %$val == 1
1172 0 4 unless $k eq $self->{'opt'}{'valueattr'}{$key}
1207 20 1 if defined $value
1252 189 133 if (ref $self->{'opt'}{'keyattr'} eq 'HASH') { }
1253 68 121 unless exists $self->{'opt'}{'keyattr'}{$name}
1256 1908 4 if (UNIVERSAL::isa($arrayref->[$i], 'HASH') and exists $arrayref->[$i]{$key}) { }
1260 4 1904 if (ref $val)
1265 2 1902 if $self->{'opt'}{'normalisespace'} == 1
1267 3 1901 if exists $hashref->{$val}
1269 4 1899 if $flag eq '-'
1270 1901 2 unless $flag eq '+'
1287 76 129 unless UNIVERSAL::isa($arrayref->[$i], 'HASH')
1290 119 54 if (defined $arrayref->[$i]{$key})
1292 2 117 if (ref $val)
1293 1 1 unless $default_keys
1298 2 115 if $self->{'opt'}{'normalisespace'} == 1
1300 1 116 if exists $hashref->{$val}
1313 36 121 if ($self->{'opt'}{'collapseagain'})
1335 5 8 if $self->{'opt'}{'strictmode'}
1336 5 3 if (warnings::enabled())
1385 22 48 unless ref $val eq 'HASH' and keys %$val == 1 and exists $val->{$contentkey}
1422 81 2105 $indent eq '' ? :
1423 6 2180 if ($self->{'opt'}{'noindent'})
1431 2170 16 if (my $refaddr = &Scalar::Util::refaddr($ref)) { }
1433 1 2169 if $self->{'_ancestors'}{$refaddr}
1437 14 2 if ($named) { }
1440 1 13 $self->{'opt'}{'noescape'} ? :
1452 2003 79 if (UNIVERSAL::isa($ref, 'HASH') and keys %$ref and $self->{'opt'}{'keyattr'} and not $is_root)
1467 1980 189 if (UNIVERSAL::isa($ref, 'HASH')) { }
188 1 elsif (UNIVERSAL::isa($ref, 'ARRAY')) { }
1471 12 1968 if ($self->{'opt'}{'grouptags'})
1474 5 13 if ($self->{'opt'}{'grouptags'}{$key})
1487 5 1975 if ($self->{'nsup'})
1493 2 3 if (exists $ref->{'xmlns'})
1505 8 1 if ($uri)
1506 1 7 if ($uri eq $xmlns_ns)
1518 7 1 if ($uri)
1519 4 3 if ($default_ns_uri and $uri eq $default_ns_uri) { }
1525 1 2 unless ($prefix)
1542 1977 3 if ($named)
1546 1977 3 if (keys %$ref) { }
1550 2 3946 if substr($key, 0, 1) eq '-'
1551 5 3941 unless (defined $value)
1552 1 4 if $self->{'opt'}{'suppressempty'}
1553 2 2 unless (exists $self->{'opt'}{'suppressempty'} and not defined $self->{'opt'}{'suppressempty'})
1556 1 1 if warnings::enabled()
1558 1 3 if ($key eq $self->{'opt'}{'contentkey'}) { }
1562 1 2 exists $self->{'opt'}{'suppressempty'} ? :
1566 2 3 if (not ref $value and $self->{'opt'}{'valueattr'} and $self->{'opt'}{'valueattr'}{$key})
1575 187 3758 if (ref $value or $self->{'opt'}{'noattr'}) { }
1580 19 3739 if ($key eq $self->{'opt'}{'contentkey'}) { }
1581 19 0 unless $self->{'opt'}{'noescape'}
1585 3737 2 unless $self->{'opt'}{'noescape'}
1587 3 3736 if $self->{'opt'}{'attrindent'} and not $first_arg
1598 180 1799 if (@nested or defined $text_content) { }
1599 177 3 if ($named) { }
1601 22 155 if (defined $text_content) { }
1603 0 22 if @nested
1608 155 22 if (@nested)
1620 5 1974 if $self->{'nsup'}
1628 1 1 if not defined $value and $self->{'opt'}{'suppressempty'}
1629 930 1920 if (not ref $value) { }
1877 43 elsif (UNIVERSAL::isa($value, 'HASH')) { }
1632 1 929 $self->{'opt'}{'noescape'} ? :
1652 2167 0 if (my $refaddr = &Scalar::Util::refaddr($ref))
1670 0 1977 if $self->{'opt'}{'nosort'}
1677 1877 100 if (ref $keyattr eq 'HASH') { }
95 5 elsif (ref $keyattr eq 'ARRAY') { }
1678 1847 30 if (exists $keyattr->{$name} and exists $hash{$keyattr->{$name}[0]})
1685 21 216 if (exists $hash{$_})
1706 2 4695 unless defined $data
1713 4691 4 unless my $level = $self->{'opt'}{'numericescape'}
1721 2 2 if ($self->{'opt'}{'numericescape'} eq '2') { }
1763 0 2003 $self->{'opt'}{'nosort'} ? :
1766 1896 1948 unless UNIVERSAL::isa($value, 'HASH')
1768 1931 17 if (ref $self->{'opt'}{'keyattr'} eq 'HASH') { }
1769 2 1929 unless defined $self->{'opt'}{'keyattr'}{$parent}
1806 7 154 unless $self->{'opt'}
1818 11 3520 if ($self->{'opt'}{'nsexpand'})
1820 6 5 if ($element->{'NamespaceURI'})
1825 3531 0 if ($element->{'Attributes'})
1827 6 4138 if ($self->{'opt'}{'nsexpand'}) { }
1829 4 2 if ($attr->{'NamespaceURI'})
1832 0 6 if $name eq $bad_def_ns_jcn
1855 11 4932 if ($pos > 0 and $$clist[$pos - 1] eq '0') { }
1883 154 7 if $self->{'nocollapse'}
1888 1 6 if ($self->{'opt'}{'keeproot'}) { }
1895 2 5 if ($self->{'opt'}{'datahandler'})