Branch Coverage

blib/lib/XML/Simple.pm
Criterion Covered Total %
branch 406 452 89.8


line true false branch
95 1 10 if grep /^:strict$/, @_
111 1 270 if (@_ % 2)
120 270 0 unless exists $raw_opt{'strictmode'}
125 1 307 unless exists $known_opt{$lkey}
147 486 271 if $package eq 'XML::Simple'
148 1 270 if $set_mode
164 203 243 if ($_[0] and UNIVERSAL::isa($_[0], 'XML::Simple')) { }
194 1 179 if (not defined $target) { }
2 177 elsif ($target eq '-') { }
2 175 elsif (my $type = ref $target) { }
147 28 elsif ($target =~ /<.*?>/s) { }
205 0 2 if ($type eq 'SCALAR') { }
236 1 26 unless defined $filename
242 17 7 if ($self->{'opt'}{'cache'})
246 8 9 if $opt
252 9 7 if ($self->{'opt'}{'cache'})
271 0 0 defined $fh ? :
0 2 unless ref $fh
293 136 0 ref $string ? :
313 1 0 if ($script_dir)
334 0 154 if $@
338 5 149 $self->{'opt'}{'keeproot'} ? :
367 147 7 unless (defined $preferred_parser)
370 0 154 if ($preferred_parser eq 'XML::Parser')
375 0 154 if ($@)
376 0 0 if ($preferred_parser)
382 0 154 if $preferred_parser
388 16 138 if ($filename) { }
392 2 136 if (ref $string and ref $string ne 'SCALAR') { }
422 0 0 if ($@)
426 0 0 if ($self->{'opt'}{'nsexpand'})
432 0 0 if ($filename) { }
434 0 0 unless open my $xfh, '<', $filename
459 0 5 if ('VMS' eq $^O) { }
483 2 6 unless -r $cachefile
484 3 3 unless (stat $cachefile)[9] > (stat $filename)[9]
488 0 3 if ('VMS' eq $^O) { }
537 1 3 unless $MemShareCache{$filename}
538 1 2 unless $MemShareCache{$filename}[0] > (stat $filename)[9]
571 1 3 unless $MemCopyCache{$filename}
572 1 2 unless $MemCopyCache{$filename}[0] > (stat $filename)[9]
591 2 84 unless @_
599 3 76 if ($self->{'opt'}{'nsexpand'})
608 4 75 if (UNIVERSAL::isa($ref, 'ARRAY'))
615 2 77 if ($self->{'opt'}{'keeproot'}) { }
5 72 elsif ($self->{'opt'}{'rootname'} eq '') { }
617 2 0 if (@keys == 1)
626 3 2 if (UNIVERSAL::isa($ref, 'HASH'))
630 3 4 if (ref $refsave->{$_}) { }
647 2 75 if ($self->{'opt'}{'xmldecl'})
651 2 75 if ($self->{'opt'}{'outputfile'}) { }
2 73 elsif ($self->{'opt'}{'handler'}) { }
652 1 1 if (ref $self->{'opt'}{'outputfile'}) { }
654 0 1 if (UNIVERSAL::isa($fh, 'GLOB') and not UNIVERSAL::can($fh, 'print'))
656 0 0 if $@
661 0 1 unless open my $out, '>', "$self->{'opt'}{'outputfile'}"
663 1 0 if $] >= 5.008
664 0 1 unless print $out $xml
665 0 1 unless close $out
705 187 84 if ($dirn eq 'in') { }
715 2 269 if (@_ % 2)
725 2 267 unless $known_opt{$lkey}
733 4724 267 unless (exists $opt->{$_})
734 314 4410 if (exists $self->{'def_opt'}{$_})
743 20 247 if (exists $opt->{'rootname'}) { }
744 1 19 unless (defined $opt->{'rootname'})
752 1 266 if ($opt->{'xmldecl'} and $opt->{'xmldecl'} eq '1')
756 69 198 if (exists $opt->{'contentkey'}) { }
757 61 8 if ($opt->{'contentkey'} =~ /^-(.*)$/)
766 263 4 unless (exists $opt->{'normalisespace'})
769 262 5 unless defined $opt->{'normalisespace'}
773 3 264 if ($opt->{'searchpath'}) { }
774 2 1 unless (ref $opt->{'searchpath'})
782 18 249 if ($opt->{'cache'} and not ref $opt->{'cache'})
785 19 248 if ($opt->{'cache'})
789 2 17 unless $self->can($method)
794 0 265 if (exists $opt->{'parseropts'}) { }
795 0 0 if (warnings::enabled())
808 36 229 if (exists $opt->{'forcearray'}) { }
809 1 35 if (ref $opt->{'forcearray'} eq 'Regexp')
813 16 20 if (ref $opt->{'forcearray'} eq 'ARRAY') { }
815 14 2 if (@force_list) { }
818 3 18 if (ref $tag eq 'Regexp') { }
831 16 4 $opt->{'forcearray'} ? :
835 3 226 if ($opt->{'strictmode'} and $dirn eq 'in')
845 78 184 if (exists $opt->{'keyattr'}) { }
846 74 4 if (ref $opt->{'keyattr'}) { }
847 58 16 if (ref $opt->{'keyattr'} eq 'HASH') { }
858 64 0 if ($opt->{'keyattr'}{$el} =~ /^(\+|-)?(.*)$/) { }
859 8 56 $1 ? :
860 9 55 if ($opt->{'strictmode'} and $dirn eq 'in')
861 3 6 if $opt->{'forcearray'} == 1
863 2 2 if ref $opt->{'forcearray'} eq 'HASH' and $opt->{'forcearray'}{$el}
873 4 12 if (@{$opt->{'keyattr'};} == 0)
883 4 180 if ($opt->{'strictmode'})
892 5 249 if (exists $opt->{'valueattr'})
893 2 3 if (ref $opt->{'valueattr'} eq 'ARRAY')
901 14 240 if ($opt->{'grouptags'})
903 1 13 unless UNIVERSAL::isa($opt->{'grouptags'}, 'HASH')
906 14 1 if $key ne $val
914 1 251 if ($opt->{'variables'} and not UNIVERSAL::isa($opt->{'variables'}, 'HASH'))
918 4 247 if ($opt->{'variables'}) { }
2 245 elsif ($opt->{'varattr'}) { }
948 23 4 if ($filename ne $file) { }
949 22 1 if -e $file
955 2 3 if -e $fullpath
961 1 2 unless (@search_path)
962 0 1 if -e $file
1004 36 3501 if ($self->{'opt'}{'noattr'}) { }
15 3486 elsif ($self->{'opt'}{'normalisespace'} == 2) { }
1016 37 3500 if (my $var = $self->{'_var_values'})
1026 42 3495 if (not @_ and keys %$attr == 1)
1028 7 1 if ($self->{'opt'}{'valueattrlist'} and $self->{'opt'}{'valueattrlist'}{$k})
1040 0 8308 unless defined $val
1042 3376 4932 if (ref $val) { }
4932 0 elsif ($key eq '0') { }
1044 6 2 if not defined $val and $self->{'opt'}{'suppressempty'}
1047 3664 1268 if $val =~ /^\s*$/s
1050 10 1258 if $self->{'opt'}{'normalisespace'} == 2
1054 26 1242 if (my $var = $self->{'_var_values'})
1061 23 1245 if (my $var = $self->{'opt'}{'varattr'})
1062 10 13 if (exists $attr->{$var})
1070 1141 1 unless (%$attr or @_)
1072 2 1139 $self->{'opt'}{'forcecontent'} ? :
1081 2859 638 if (exists $attr->{$key}) { }
4 634 elsif (defined $val and UNIVERSAL::isa($val, 'ARRAY')) { }
1082 2729 130 if (UNIVERSAL::isa($attr->{$key}, 'ARRAY')) { }
1093 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'};}))) { }
1117 2367 22 if ($self->{'opt'}{'keyattr'})
1119 322 4403 if (defined $val and UNIVERSAL::isa($val, 'ARRAY'))
1128 26 2358 if ($self->{'opt'}{'grouptags'})
1130 41 10 unless UNIVERSAL::isa($val, 'HASH') and keys %$val == 1
1131 1 9 unless exists $self->{'opt'}{'grouptags'}{$key}
1135 8 1 if ($self->{'opt'}{'grouptags'}{$key} eq $child_key)
1145 61 145 if ($count == 1 and exists $attr->{'anon'} and UNIVERSAL::isa($attr->{'anon'}, 'ARRAY'))
1155 11 2 if (not %$attr and exists $self->{'opt'}{'suppressempty'})
1156 2 9 if (defined $self->{'opt'}{'suppressempty'} and $self->{'opt'}{'suppressempty'} eq '')
1166 10 2302 if ($self->{'opt'}{'valueattr'})
1168 14 4 unless $self->{'opt'}{'valueattr'}{$key}
1169 0 4 unless UNIVERSAL::isa($val, 'HASH') and keys %$val == 1
1171 0 4 unless $k eq $self->{'opt'}{'valueattr'}{$key}
1206 20 1 if defined $value
1251 189 133 if (ref $self->{'opt'}{'keyattr'} eq 'HASH') { }
1252 68 121 unless exists $self->{'opt'}{'keyattr'}{$name}
1255 1908 4 if (UNIVERSAL::isa($arrayref->[$i], 'HASH') and exists $arrayref->[$i]{$key}) { }
1259 4 1904 if (ref $val)
1264 2 1902 if $self->{'opt'}{'normalisespace'} == 1
1266 3 1901 if exists $hashref->{$val}
1268 4 1899 if $flag eq '-'
1269 1901 2 unless $flag eq '+'
1286 76 129 unless UNIVERSAL::isa($arrayref->[$i], 'HASH')
1289 119 54 if (defined $arrayref->[$i]{$key})
1291 2 117 if (ref $val)
1292 1 1 unless $default_keys
1297 2 115 if $self->{'opt'}{'normalisespace'} == 1
1299 1 116 if exists $hashref->{$val}
1312 36 121 if ($self->{'opt'}{'collapseagain'})
1334 5 8 if $self->{'opt'}{'strictmode'}
1335 5 3 if (warnings::enabled())
1384 22 48 unless ref $val eq 'HASH' and keys %$val == 1 and exists $val->{$contentkey}
1421 81 2105 $indent eq '' ? :
1422 6 2180 if ($self->{'opt'}{'noindent'})
1431 2170 16 if ($refaddr) { }
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'} ? :
1668 0 1977 if $self->{'opt'}{'nosort'}
1675 1877 100 if (ref $keyattr eq 'HASH') { }
95 5 elsif (ref $keyattr eq 'ARRAY') { }
1676 1847 30 if (exists $keyattr->{$name} and exists $hash{$keyattr->{$name}[0]})
1683 21 216 if (exists $hash{$_})
1704 2 4695 unless defined $data
1711 4691 4 unless my $level = $self->{'opt'}{'numericescape'}
1719 2 2 if ($self->{'opt'}{'numericescape'} eq '2') { }
1761 0 2003 $self->{'opt'}{'nosort'} ? :
1764 1896 1948 unless UNIVERSAL::isa($value, 'HASH')
1766 1931 17 if (ref $self->{'opt'}{'keyattr'} eq 'HASH') { }
1767 2 1929 unless defined $self->{'opt'}{'keyattr'}{$parent}
1804 7 154 unless $self->{'opt'}
1816 11 3520 if ($self->{'opt'}{'nsexpand'})
1818 6 5 if ($element->{'NamespaceURI'})
1823 3531 0 if ($element->{'Attributes'})
1825 6 4138 if ($self->{'opt'}{'nsexpand'}) { }
1827 4 2 if ($attr->{'NamespaceURI'})
1830 0 6 if $name eq $bad_def_ns_jcn
1853 11 4932 if ($pos > 0 and $$clist[$pos - 1] eq '0') { }
1881 154 7 if $self->{'nocollapse'}
1886 1 6 if ($self->{'opt'}{'keeproot'}) { }
1893 2 5 if ($self->{'opt'}{'datahandler'})