| 1 | #!/usr/bin/perl -w | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package XML::Bare; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use vars qw( @ISA @EXPORT @EXPORT_OK $VERSION ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | require DynaLoader; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | @ISA = qw(Exporter DynaLoader); | |||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | $VERSION = "0.53"; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use vars qw($VERSION *AUTOLOAD); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | *AUTOLOAD = \&XML::Bare::AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | bootstrap XML::Bare $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | @EXPORT = qw( ); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | @EXPORT_OK = qw( xget merge clean add_node del_node find_node del_node forcearray del_by_perl xmlin xval ); | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | XML::Bare - Minimal XML parser implemented via a C state engine | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0.53 | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 43 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 43 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 43 | my $self = { @_ }; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 43 | $self->{'i'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 43 | ▶ | if( $self->{ 'text' } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 41 | ▶ | if( $self->{'unsafe'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $self->{'parser'} = XML::Bare::c_parse_unsafely( $self->{'text'} ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 41 | $self->{'parser'} = XML::Bare::c_parse( $self->{'text'} ); | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | my $res = open( my $XML, $self->{ 'file' } ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | if( !$res ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $self->{ 'xml' } = 0; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | $self->{'text'} = <$XML>; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | close( $XML ); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | $self->{'parser'} = XML::Bare::c_parse( $self->{'text'} ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 43 | bless $self, "XML::Bare::Object"; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 43 | ▶ | return $self if( !wantarray ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 33 | ▶ | return ( $self, ( $self->{'simple'} ? $self->simple() : $self->parse() ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | sub simple { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simple: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | return new( @_, simple => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | package XML::Bare::Object; | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # Stubs ( to allow these functions to be used via an object as well, not just via import or namespace ) | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | sub find_by_perl { shift; return XML::Bare::find_by_perl( @_ ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_by_perl: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | sub find_node { shift; return XML::Bare::find_node( @_ ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_node: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 42 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 9 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | #print Dumper( $self ); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 42 | undef $self->{'text'}; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 42 | undef $self->{'i'}; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 42 | $self->free_tree(); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 42 | undef $self->{'parser'}; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub read_more { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_more: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my %p = ( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $i = $self->{'i'}++; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if( $p{'text'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $self->{"text$i"} = $p{'text'}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | XML::Bare::c_parse_more( $self->{"text$i"}, $self->{'parser'} ); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 33 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=7 SCAR=28.1
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 33 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 33 | my $res = XML::Bare::xml2obj( $self->{'parser'} ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 33 | ▶ | if( defined( $self->{'scheme'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $self->{'xbs'} = new XML::Bare( %{ $self->{'scheme'} } ); | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 33 | ▶ | if( defined( $self->{'xbs'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $xbs = $self->{'xbs'}; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $ob = $xbs->parse(); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $self->{'xbso'} = $ob; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | readxbs( $ob ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if( !ref( $res ) && $res < 0 ) { croak "Error at ".$self->lineinfo( -$res ); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $res and $res < 0
MC/DC0%0/2
not ref $res and $res < 0
not ref $res
$res < 0
Truth table33%1/3
not(A) and B
A= not ref $resB= $res < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 33 | $self->{ 'xml' } = $res; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 33 | ▶ | if( defined( $self->{'xbso'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $ob = $self->{'xbso'}; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $cres = $self->check( $res, $ob ); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | croak( $cres ) if( $cres ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 33 | return $self->{ 'xml' }; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # xml bare schema | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my ( $self, $node, $scheme, $parent ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $fail = ''; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if( ref( $scheme ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | for my $one ( @$scheme ) { | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $res = $self->checkone( $node, $one, $parent ); | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return 0 if( !$res ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $fail .= "$res\n"; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | else { return $self->checkone( $node, $scheme, $parent ); } | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | return $fail; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub checkone { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkone: not called CC=25 SCAR=64.8
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my ( $self, $node, $scheme, $parent ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | for my $key ( keys %$node ) { | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | next if( substr( $key, 0, 1 ) eq '_' || $key eq '_att' || $key eq 'comment' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
substr($key, 0, 1) eq "_" or $key eq "_att" or $key eq "comment"
substr($key, 0, 1) eq "_" or $key eq "_att"
MC/DC0%0/3
substr($key, 0, 1) eq "_" or $key eq "_att" or $key eq "comment"
substr($key, 0, 1) eq "_"
$key eq "_att"
$key eq "comment"
Truth table0%0/4
A or B or C
A= substr($key, 0, 1) eq "_"B= $key eq "_att"C= $key eq "comment"
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if( $key eq 'value' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $val = $node->{ 'value' }; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $regexp = $scheme->{'value'}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if( $regexp ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if( $val !~ m/^($regexp)$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $linfo = $self->lineinfo( $node->{'_i'} ); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return "Value of '$parent' node ($val) does not match /$regexp/ [$linfo]"; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $sub = $node->{ $key }; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $ssub = $scheme->{ $key }; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if( !$ssub ) { #&& ref( $schemesub ) ne 'HASH' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $linfo = $self->lineinfo( $sub->{'_i'} ); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | return "Invalid node '$key' in xml [$linfo]"; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if( ref( $sub ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $res = $self->check( $sub, $ssub, $key ); | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return $res if( $res ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if( ref( $sub ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $asub = $ssub; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if( ref( $asub ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $asub = $asub->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if( $asub->{'_t'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my $max = $asub->{'_max'} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$asub->{'_max'} || 0
MC/DC0%0/1
$asub->{'_max'} || 0
$asub->{'_max'}
Truth table0%0/2
A
A= $asub->{'_max'}
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if( $#$sub >= $max ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my $linfo = $self->lineinfo( $sub->[0]->{'_i'} ); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | return "Too many nodes of type '$key'; max $max; [$linfo]" | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | my $min = $asub->{'_min'} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$asub->{'_min'} || 0
MC/DC0%0/1
$asub->{'_min'} || 0
$asub->{'_min'}
Truth table0%0/2
A
A= $asub->{'_min'}
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if( ($#$sub+1)<$min ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $linfo = $self->lineinfo( $sub->[0]->{'_i'} ); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return "Not enough nodes of type '$key'; min $min [$linfo]" | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | for( @$sub ) { | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $res = $self->check( $_, $ssub, $key ); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | return $res if( $res ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if( my $dem = $scheme->{'_demand'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | for my $req ( @{$scheme->{'_demand'}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $ck = $node->{ $req }; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if( !$ck ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $linfo = $self->lineinfo( $node->{'_i'} ); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return "Required node '$req' does not exist [$linfo]" | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if( ref( $ck ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my $linfo = $self->lineinfo( $node->{'_i'} ); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | return "Required node '$req' is empty array [$linfo]" if( $#$ck == -1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 10 | ▶ | sub simple { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simple: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 10 | my $res = XML::Bare::xml2obj_simple( $self->{'parser'} );#$self->xml2obj(); | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if( !ref( $res ) && $res < 0 ) { croak "Error at ".$self->lineinfo( -$res ); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $res and $res < 0
MC/DC0%0/2
not ref $res and $res < 0
not ref $res
$res < 0
Truth table33%1/3
not(A) and B
A= not ref $resB= $res < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 10 | $self->{ 'xml' } = $res; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 10 | return $res; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | ▶ | sub add_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_node: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | my ( $self, $node, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | my @newar; | |||||||||||||||||||||||||||||||||||||||||
| 216 | my %blank; | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | $node->{ 'multi_'.$name } = \%blank if( ! $node->{ 'multi_'.$name } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | $node->{ $name } = \@newar if( ! $node->{ $name } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | my $newnode = new_node( 0, splice( @_, 3 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | push( @{ $node->{ $name } }, $newnode ); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | return $newnode; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub add_node_after { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_node_after: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my ( $self, $node, $prev, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my @newar; | |||||||||||||||||||||||||||||||||||||||||
| 227 | my %blank; | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | $node->{ 'multi_'.$name } = \%blank if( ! $node->{ 'multi_'.$name } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | $node->{ $name } = \@newar if( ! $node->{ $name } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $newnode = $self->new_node( splice( @_, 4 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $cur = 0; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | for my $anode ( @{ $node->{ $name } } ) { | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | $anode->{'_pos'} = $cur if( !$anode->{'_pos'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $cur++; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $opos = $prev->{'_pos'}; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | for my $anode ( @{ $node->{ $name } } ) { | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | $anode->{'_pos'}++ if( $anode->{'_pos'} > $opos ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $newnode->{'_pos'} = $opos + 1; | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | push( @{ $node->{ $name } }, $newnode ); | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | return $newnode; | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | sub del_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
del_node: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my %match = @_; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | $node = $node->{ $name }; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | return if( !$node ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | for( my $i = 0; $i <= $#$node; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $one = $node->[ $i ]; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | foreach my $key ( keys %match ) { | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $val = $match{ $key }; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if( $one->{ $key }->{'value'} eq $val ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | delete $node->[ $i ]; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | # Created a node of XML hash with the passed in variables already set | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | ▶ | sub new_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_node: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | my %parts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | my %newnode; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | foreach( keys %parts ) { | |||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | my $val = $parts{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | if( m/^_/ || ref( $val ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
/^_/ or ref $val eq "HASH"
MC/DC0%0/2
/^_/ or ref $val eq "HASH"
/^_/
ref $val eq "HASH"
Truth table33%1/3
A or B
A= /^_/B= ref $val eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $newnode{ $_ } = $val; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | $newnode{ $_ } = { value => $val }; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | return \%newnode; | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub simplify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simplify: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $node = CORE::shift; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my $ref = ref( $node ); | |||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my @ret; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | for my $sub ( @$node ) { | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | CORE::push( @ret, simplify( $sub ) ); | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | return \@ret; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if( $ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my %ret; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my $cnt = 0; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | for my $key ( keys %$node ) { | |||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | next if( $key eq 'comment' || $key eq 'value' || $key =~ m/^_/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$key eq "comment" or $key eq "value" or $key =~ /^_/
$key eq "comment" or $key eq "value"
MC/DC0%0/3
$key eq "comment" or $key eq "value" or $key =~ /^_/
$key eq "comment"
$key eq "value"
$key =~ /^_/
Truth table0%0/4
A or B or C
A= $key eq "comment"B= $key eq "value"C= $key =~ /^_/
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $cnt++; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $ret{ $key } = simplify( $node->{ $key } ); | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if( $cnt == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | return $node->{'value'}; | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | return \%ret; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | return $node; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | sub hash2xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash2xml: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my ( $node, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $ref = ref( $node ); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | return '' if( $name && $name =~ m/^\_/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name and $name =~ /^\_/
MC/DC0%0/2
$name and $name =~ /^\_/
$name
$name =~ /^\_/
Truth table0%0/3
A and B
A= $nameB= $name =~ /^\_/
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | my $txt = $name ? "<$name>" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $txt = ''; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | for my $sub ( @$node ) { | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $txt .= hash2xml( $sub, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | return $txt; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | elsif( $ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | for my $key ( keys %$node ) { | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $txt .= hash2xml( $node->{ $key }, $key ); | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | $node ||= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$node ||= ""
MC/DC0%0/1
$node ||= ""
$node
Truth table0%0/2
A
A= $node
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if( $node =~ /[<]/ ) { $txt .= '<![CDATA[' . $node . ']]>'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | else { $txt .= $node; } | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | if( $name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | $txt .= "</$name>"; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | return $txt; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | # Save an XML hash tree into a file | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=6 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 2 | ▶ | return if( ! $self->{ 'xml' } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | my $xml = $self->xml( $self->{'xml'} ); | |||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | my $len; | |||||||||||||||||||||||||||||||||||||||||
| 348 | { | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 9 | ▶ | use bytes; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 2 | $len = length( $xml ); | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | ▶ | return if( !$len ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | # This is intentionally just :utf8 and not :encoding(UTF-8) | ||||||||||||||||||||||||||||||||||||||||||
| 355 | # :encoding(UTF-8) checks the data for actually being valid UTF-8, and doing so would slow down the file write | ||||||||||||||||||||||||||||||||||||||||||
| 356 | # See http://perldoc.perl.org/functions/binmode.html | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 2 | my $os = $^O; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | my $F; | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | # Note on the following conditional OS check... WTF? This is total bullshit. | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 2 | ▶ | if( $os eq 'MSWin32' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | open( $F, '>:utf8', $self->{ 'file' } ); | |||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | binmode $F; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | open( $F, '>', $self->{ 'file' } ); | |||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | binmode $F, ':utf8'; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 2 | print $F $xml; | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 2 | seek( $F, 0, 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 373 | 2 | my $cursize = tell( $F ); | |||||||||||||||||||||||||||||||||||||||||
| 374 | 2 | ▶ | if( $cursize != $len ) { # concurrency; we are writing a smaller file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | warn "Truncating File $self->{'file'}"; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | `cp $self->{'file'} $self->{'file'}.bad`; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | truncate( F, $len ); | |||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 2 | seek( $F, 0, 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | $cursize = tell( $F ); | |||||||||||||||||||||||||||||||||||||||||
| 381 | 2 | ▶ | if( $cursize != $len ) { # still not the right size even after truncate?? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | die "Write problem; $cursize != $len"; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 2 | close $F; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 18 | ▶ | sub xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xml: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 18 | my ( $self, $obj, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 18 | ▶ | if( !$name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 18 | my %hash; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 18 | $hash{0} = $obj; | |||||||||||||||||||||||||||||||||||||||||
| 392 | 18 | return XML::Bare::obj2xml( \%hash, '', 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my %hash; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $hash{$name} = $obj; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | return XML::Bare::obj2xml( \%hash, '', 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | sub html { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
html: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my ( $self, $obj, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my $pre = ''; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | if( $self->{'style'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $pre = "<style type='text/css'>\@import '$self->{'style'}';</style>"; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | if( !$name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my %hash; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $hash{0} = $obj; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | return $pre.obj2html( \%hash, '', 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my %hash; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $hash{$name} = $obj; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | return $pre.obj2html( \%hash, '', 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub lineinfo { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lineinfo: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my $res = shift; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $line = 1; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $j = 0; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | for( my $i=0;$i<$res;$i++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my $let = substr( $self->{'text'}, $i, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | if( ord($let) == 10 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $line++; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $j = $i; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $part = substr( $self->{'text'}, $res, 10 ); | |||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $part =~ s/\n//g; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $res -= $j; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if( $self->{'offset'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my $off = $self->{'offset'}; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $line += $off; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | return "$off line $line char $res \"$part\""; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | return "line $line char $res \"$part\""; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 42 | ▶ | sub free_tree { my $self = shift; XML::Bare::free_tree_c( $self->{'parser'} ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
free_tree: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | package XML::Bare; | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | 1 | ▶ | sub find_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_node: called CC=9 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 1 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 1 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | my %match = @_; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | ▶ | return 0 if( ! defined $node ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 1 | ▶ | $node = $node->{ $name } or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | ▶ | $node = [ $node ] if( ref( $node ) eq 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 1 | ▶ | if( ref( $node ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | ▶ | for( my $i = 0; $i <= $#$node; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 1 | my $one = $node->[ $i ]; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | for my $key ( keys %match ) { | |||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | my $val = $match{ $key }; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | ▶ | croak('undefined value in find') unless defined $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 1 | ▶ | if( $one->{ $key }{'value'} eq $val ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 1 | return $node->[ $i ]; | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | sub xget { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xget: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $hash = shift; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | return map $_->{'value'}, @{$hash}{@_}; | |||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | sub forcearray { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
forcearray: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | return [] if( !$ref ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | return $ref if( ref( $ref ) eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | return [ $ref ]; | |||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | sub merge { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | # shift in the two array references as well as the field to merge on | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | my ( $a, $b, $id ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | my %hash = map { $_->{ $id } ? ( $_->{ $id }->{ 'value' } => $_ ) : ( 0 => 0 ) } @$a; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | for my $one ( @$b ) { | |||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | next if( !$one->{ $id } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | my $short = $hash{ $one->{ $id }->{ 'value' } }; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | next if( !$short ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | foreach my $key ( keys %$one ) { | |||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | next if( $key eq '_pos' || $key eq 'id' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq "_pos" or $key eq "id"
MC/DC0%0/2
$key eq "_pos" or $key eq "id"
$key eq "_pos"
$key eq "id"
Truth table0%0/3
A or B
A= $key eq "_pos"B= $key eq "id"
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | my $cur = $short->{ $key }; | |||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my $add = $one->{ $key }; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if( !$cur ) { $short->{ $key } = $add; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | my $type = ref( $cur ); | |||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | if( $type eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my @arr; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | $short->{ $key } = \@arr; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | push( @arr, $cur ); | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | if( ref( $add ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | push( @{$short->{ $key }}, $add ); | |||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | else { # we are merging an array | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | push( @{$short->{ $key }}, @$add ); | |||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | # we need to deal with the case where this node | ||||||||||||||||||||||||||||||||||||||||||
| 504 | # is already there, either alone or as an array | ||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | return $a; | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | sub clean { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | my $ob = new XML::Bare( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my $root = $ob->parse(); | |||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | if( $ob->{'save'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | $ob->{'file'} = $ob->{'save'} if( "$ob->{'save'}" ne "1" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $ob->save(); | |||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | return $ob->xml( $root ); | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 8 | ▶ | sub xmlin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xmlin: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | 8 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 523 | 8 | my %ops = ( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 524 | 8 | my $ob = new XML::Bare( text => $text ); | |||||||||||||||||||||||||||||||||||||||||
| 525 | 8 | my $simple = $ob->simple(); | |||||||||||||||||||||||||||||||||||||||||
| 526 | 8 | ▶ | if( !$ops{'keeproot'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | 8 | my @keys = keys %$simple; | |||||||||||||||||||||||||||||||||||||||||
| 528 | 8 | my $first = $keys[0]; | |||||||||||||||||||||||||||||||||||||||||
| 529 | 8 | ▶ | $simple = $simple->{ $first } if( $first ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 8 | return $simple; | |||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | sub tohtml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tohtml: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my %ops = ( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | my $ob = new XML::Bare( %ops ); | |||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | return $ob->html( $ob->parse(), $ops{'root'} || 'xml' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ops{'root'} || 'xml'
MC/DC0%0/1
$ops{'root'} || 'xml'
$ops{'root'}
Truth table0%0/2
A
A= $ops{'root'}
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | sub readxbs { # xbs = xml bare schema | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readxbs: not called CC=21 SCAR=61.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my @demand; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | for my $key ( keys %$node ) { | |||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | next if( substr( $key, 0, 1 ) eq '_' || $key eq '_att' || $key eq 'comment' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
substr($key, 0, 1) eq "_" or $key eq "_att" or $key eq "comment"
substr($key, 0, 1) eq "_" or $key eq "_att"
MC/DC0%0/3
substr($key, 0, 1) eq "_" or $key eq "_att" or $key eq "comment"
substr($key, 0, 1) eq "_"
$key eq "_att"
$key eq "comment"
Truth table0%0/4
A or B or C
A= substr($key, 0, 1) eq "_"B= $key eq "_att"C= $key eq "comment"
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | if( $key eq 'value' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | my $val = $node->{'value'}; | |||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | delete $node->{'value'} if( $val =~ m/^\W*$/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | my $sub = $node->{ $key }; | |||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | if( $key =~ m/([a-z_]+)([^a-z_]+)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $name = $1; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | my $t = $2; | |||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $min; | |||||||||||||||||||||||||||||||||||||||||
| 556 | my $max; | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | if( $t eq '+' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $min = 1; | |||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | $max = 1000; | |||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||
| 561 | elsif( $t eq '*' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | $min = 0; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | $max = 1000; | |||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | elsif( $t eq '?' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $min = 0; | |||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | $max = 1; | |||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | elsif( $t eq '@' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $name = 'multi_'.$name; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | $min = 1; | |||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | $max = 1; | |||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 574 | elsif( $t =~ m/\{([0-9]+),([0-9]+)\}/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | $min = $1; | |||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | $max = $2; | |||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | $t = 'r'; # range | |||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | if( ref( $sub ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | my $res = readxbs( $sub ); | |||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | $sub->{'_t'} = $t; | |||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | $sub->{'_min'} = $min; | |||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | $sub->{'_max'} = $max; | |||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | if( ref( $sub ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | for my $item ( @$sub ) { | |||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my $res = readxbs( $item ); | |||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | $item->{'_t'} = $t; | |||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | $item->{'_min'} = $min; | |||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $item->{'_max'} = $max; | |||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | ▶ | push( @demand, $name ) if( $min ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | $node->{$name} = $node->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | delete $node->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||
| 599 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | if( ref( $sub ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | readxbs( $sub ); | |||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | $sub->{'_t'} = 'r'; | |||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | $sub->{'_min'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | $sub->{'_max'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | if( ref( $sub ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | for my $item ( @$sub ) { | |||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | readxbs( $item ); | |||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | $item->{'_t'} = 'r'; | |||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | $item->{'_min'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | $item->{'_max'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | push( @demand, $key ); | |||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | if( @demand ) { $node->{'_demand'} = \@demand; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | 1 | ▶ | sub find_by_perl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_by_perl: called CC=5 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | 1 | my $arr = shift; | |||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | my $cond = shift; | |||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 626 | 1 | ▶ | if( ref( $arr ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | $cond =~ s/-([a-z_]+)/\$ob->\{'$1'\}->\{'value'\}/gi; | |||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | foreach my $ob ( @$arr ) { push( @res, $ob ) if( eval( $cond ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 631 | 1 | $cond =~ s/-([a-z_]+)/\$arr->\{'$1'\}->\{'value'\}/gi; | |||||||||||||||||||||||||||||||||||||||||
| 632 | 1 | ▶ | push( @res, $arr ) if( eval( $cond ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 1 | return \@res; | |||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | sub del_by_perl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
del_by_perl: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | my $arr = shift; | |||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | my $cond = shift; | |||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | $cond =~ s/-value/\$ob->\{'value'\}/g; | |||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | $cond =~ s/-([a-z]+)/\$ob->\{'$1'\}->\{'value'\}/g; | |||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | for( my $i = 0; $i <= $#$arr; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | my $ob = $arr->[ $i ]; | |||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | ▶ | delete $arr->[ $i ] if( eval( $cond ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | return \@res; | |||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | sub newhash { shift; return { value => shift }; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newhash: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | ▶ | sub xval { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xval: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | return $_[0] ? $_[0]->{'value'} : ( $_[1] || '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$_[1] or ""
MC/DC0%0/1
$_[1] or ""
$_[1]
Truth table0%0/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | 96 | ▶ | sub obj2xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
obj2xml: called CC=37 SCAR=37.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | 96 | my ( $objs, $name, $pad, $level, $pdex ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 658 | 96 | ▶ | $level = 0 if( !$level ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 96 | ▶ | $pad = '' if( $level <= 2 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 660 | 96 | my $xml = ''; | |||||||||||||||||||||||||||||||||||||||||
| 661 | 96 | my $att = ''; | |||||||||||||||||||||||||||||||||||||||||
| 662 | 96 | my $imm = 1; | |||||||||||||||||||||||||||||||||||||||||
| 663 | 96 | ▶ | return '' if( !$objs ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | #return $objs->{'_raw'} if( $objs->{'_raw'} ); | ||||||||||||||||||||||||||||||||||||||||||
| 665 | my @dex = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 666 | 96 | my $oba = $objs->{ $a }; | |||||||||||||||||||||||||||||||||||||||||
| 667 | 450 | my $obb = $objs->{ $b }; | |||||||||||||||||||||||||||||||||||||||||
| 668 | 450 | my $posa = 0; | |||||||||||||||||||||||||||||||||||||||||
| 669 | 450 | my $posb = 0; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 450 | ▶ | $oba = $oba->[0] if( ref( $oba ) eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 671 | 450 | ▶ | $obb = $obb->[0] if( ref( $obb ) eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 672 | 450 | ▶ | if( ref( $oba ) eq 'HASH' ) { $posa = $oba->{'_pos'} || 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$oba->{'_pos'} || 0
MC/DC100%1/1
$oba->{'_pos'} || 0
$oba->{'_pos'}
Truth table100%2/2
A
A= $oba->{'_pos'}
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | 450 | ▶ | if( ref( $obb ) eq 'HASH' ) { $posb = $obb->{'_pos'} || 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$obb->{'_pos'} || 0
MC/DC100%1/1
$obb->{'_pos'} || 0
$obb->{'_pos'}
Truth table100%2/2
A
A= $obb->{'_pos'}
| |||||||||||||||||||||||||||||||||||||||||||
| 674 | 450 | return $posa <=> $posb; | |||||||||||||||||||||||||||||||||||||||||
| 675 | } keys %$objs; | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 96 | for my $i ( @dex ) { | |||||||||||||||||||||||||||||||||||||||||
| 677 | 365 | ▶ | my $obj = $objs->{ $i } || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$objs->{$i} || ''
MC/DC100%1/1
$objs->{$i} || ''
$objs->{$i}
Truth table100%2/2
A
A= $objs->{$i}
| |||||||||||||||||||||||||||||||||||||||||||
| 678 | 365 | my $type = ref( $obj ); | |||||||||||||||||||||||||||||||||||||||||
| 679 | 365 | ▶ | if( $type eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | 4 | $imm = 0; | |||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | my @dex2 = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | if( !$a ) { return 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | if( !$b ) { return 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 3 | ▶ | if( ref( $a ) eq 'HASH' && ref( $b ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $a eq "HASH" and ref $b eq "HASH"
MC/DC0%0/2
ref $a eq "HASH" and ref $b eq "HASH"
ref $a eq "HASH"
ref $b eq "HASH"
Truth table33%1/3
A and B
A= ref $a eq "HASH"B= ref $b eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 3 | my $posa = $a->{'_pos'}; | |||||||||||||||||||||||||||||||||||||||||
| 687 | 3 | my $posb = $b->{'_pos'}; | |||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | if( !$posa ) { $posa = 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | if( !$posb ) { $posb = 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | 3 | return $posa <=> $posb; | |||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 693 | } @$obj; | ||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | 4 | for my $j ( @dex2 ) { | |||||||||||||||||||||||||||||||||||||||||
| 696 | 7 | $xml .= obj2xml( $j, $i, $pad.' ', $level+1, $#dex ); | |||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||
| 699 | ▶ | elsif( $type eq 'HASH' && $i !~ /^_/ ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$type eq "HASH" and not $i =~ /^_/
MC/DC50%1/2
$type eq "HASH" and not $i =~ /^_/
$type eq "HASH"
not $i =~ /^_/
Truth table66%2/3
A and not(B)
A= $type eq "HASH"B= not $i =~ /^_/
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | 80 | ▶ | if( $obj->{ '_att' } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 701 | 9 | ▶ | $att .= ' ' . $i . '="' . $obj->{ 'value' } . '"' if( $i !~ /^_/ );; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||
| 703 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 704 | 71 | $imm = 0; | |||||||||||||||||||||||||||||||||||||||||
| 705 | 71 | $xml .= obj2xml( $obj , $i, $pad.' ', $level+1, $#dex ); | |||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||
| 708 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 709 | 281 | ▶ | if( $i eq 'comment' ) { $xml .= '<!--' . $obj . '-->' . "\n"; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | elsif( $i eq 'value' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 42 | ▶ | if( $level > 1 ) { # $#dex < 4 && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 712 | 35 | ▶ | if( $obj && $obj =~ /[<>&;]/ ) { $xml .= '<![CDATA[' . $obj . ']]>'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$obj and $obj =~ /[<>&;]/
MC/DC50%1/2
$obj and $obj =~ /[<>&;]/
$obj
$obj =~ /[<>&;]/
Truth table66%2/3
A and B
A= $objB= $obj =~ /[<>&;]/
| |||||||||||||||||||||||||||||||||||||||||||
| 713 | 34 | ▶ | else { $xml .= $obj if( $obj =~ /\S/ ); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||
| 716 | elsif( $i =~ /^_/ ) {} | ||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | else { $xml .= '<' . $i . '>' . $obj . '</' . $i . '>'; } | |||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 96 | ▶ | my $pad2 = $imm ? '' : $pad; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 721 | 96 | ▶ | my $cr = $imm ? '' : "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | 96 | ▶ | if( substr( $name, 0, 1 ) ne '_' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 96 | ▶ | if( $name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 724 | 60 | ▶ | if( $xml ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 47 | $xml = $pad . '<' . $name . $att . '>' . $cr . $xml . $pad2 . '</' . $name . '>'; | |||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||
| 727 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 728 | 13 | $xml = $pad . '<' . $name . $att . ' />'; | |||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 96 | ▶ | return $xml."\n" if( $level > 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 732 | 36 | return $xml; | |||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | ▶ | sub obj2html { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
obj2html: not called CC=45 SCAR=76.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | my ( $objs, $name, $pad, $level, $pdex ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | my $less = "<span class='ang'><</span>"; | |||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | my $more = "<span class='ang'>></span>"; | |||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | my $tn0 = "<span class='tname'>"; | |||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | my $tn1 = "</span>"; | |||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | my $eq0 = "<span class='eq'>"; | |||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | my $eq1 = "</span>"; | |||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | my $qo0 = "<span class='qo'>"; | |||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | my $qo1 = "</span>"; | |||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | my $sp0 = "<span class='sp'>"; | |||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | my $sp1 = "</span>"; | |||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | my $cd0 = ""; | |||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | my $cd1 = ""; | |||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | $level = 0 if( !$level ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | ▶ | $pad = '' if( $level == 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | my $xml = ''; | |||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | my $att = ''; | |||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | my $imm = 1; | |||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | return '' if( !$objs ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 759 | my @dex = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | my $oba = $objs->{ $a }; | |||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | my $obb = $objs->{ $b }; | |||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | my $posa = 0; | |||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | my $posb = 0; | |||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | ▶ | $oba = $oba->[0] if( ref( $oba ) eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | ▶ | $obb = $obb->[0] if( ref( $obb ) eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | ▶ | if( ref( $oba ) eq 'HASH' ) { $posa = $oba->{'_pos'} || 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$oba->{'_pos'} || 0
MC/DC0%0/1
$oba->{'_pos'} || 0
$oba->{'_pos'}
Truth table0%0/2
A
A= $oba->{'_pos'}
| |||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | ▶ | if( ref( $obb ) eq 'HASH' ) { $posb = $obb->{'_pos'} || 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$obb->{'_pos'} || 0
MC/DC0%0/1
$obb->{'_pos'} || 0
$obb->{'_pos'}
Truth table0%0/2
A
A= $obb->{'_pos'}
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | return $posa <=> $posb; | |||||||||||||||||||||||||||||||||||||||||
| 769 | } keys %$objs; | ||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | if( $objs->{'_cdata'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | my $val = $objs->{'value'}; | |||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | $val =~ s/^(\s*\n)+//; | |||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | $val =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | $val =~ s/&/&/g; | |||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | $val =~ s/</</g; | |||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | $objs->{'value'} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 778 | #$xml = "$less![CDATA[<div class='node'><div class='cdata'>$val</div></div>]]$more"; | ||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | $cd0 = "$less![CDATA[<div class='node'><div class='cdata'>"; | |||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | $cd1 = "</div></div>]]$more"; | |||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | for my $i ( @dex ) { | |||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | ▶ | my $obj = $objs->{ $i } || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$objs->{$i} || ''
MC/DC0%0/1
$objs->{$i} || ''
$objs->{$i}
Truth table0%0/2
A
A= $objs->{$i}
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | my $type = ref( $obj ); | |||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | ▶ | if( $type eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | $imm = 0; | |||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | my @dex2 = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | ▶ | if( !$a ) { return 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | if( !$b ) { return 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | ▶ | if( ref( $a ) eq 'HASH' && ref( $b ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $a eq "HASH" and ref $b eq "HASH"
MC/DC0%0/2
ref $a eq "HASH" and ref $b eq "HASH"
ref $a eq "HASH"
ref $b eq "HASH"
Truth table0%0/3
A and B
A= ref $a eq "HASH"B= ref $b eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | my $posa = $a->{'_pos'}; | |||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | my $posb = $b->{'_pos'}; | |||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | ▶ | if( !$posa ) { $posa = 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | if( !$posb ) { $posb = 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | return $posa <=> $posb; | |||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 799 | } @$obj; | ||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | for my $j ( @dex2 ) { $xml .= obj2html( $j, $i, $pad.' ', $level+1, $#dex ); } | |||||||||||||||||||||||||||||||||||||||||
| 802 | } | ||||||||||||||||||||||||||||||||||||||||||
| 803 | ▶ | elsif( $type eq 'HASH' && $i !~ /^_/ ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$type eq "HASH" and not $i =~ /^_/
MC/DC0%0/2
$type eq "HASH" and not $i =~ /^_/
$type eq "HASH"
not $i =~ /^_/
Truth table0%0/3
A and not(B)
A= $type eq "HASH"B= not $i =~ /^_/
| |||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | if( $obj->{ '_att' } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | my $val = $obj->{ 'value' }; | |||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | $val =~ s/</</g; | |||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | ▶ | if( $val eq '' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | ▶ | $att .= " <span class='aname'>$i</span>" if( $i !~ /^_/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||
| 810 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | ▶ | $att .= " <span class='aname'>$i</span>$eq0=$eq1$qo0\"$qo1$val$qo0\"$qo1" if( $i !~ /^_/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 812 | } | ||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||
| 814 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | $imm = 0; | |||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | $xml .= obj2html( $obj , $i, $pad.' ', $level+1, $#dex ); | |||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||
| 819 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | ▶ | if( $i eq 'comment' ) { $xml .= "$less!--" . $obj . "--$more" . "<br>\n"; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 821 | elsif( $i eq 'value' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | ▶ | if( $level > 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | ▶ | if( $obj && $obj =~ /[<>&;]/ && ! $objs->{'_cdata'} ) { $xml .= "$less![CDATA[$obj]]$more"; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$obj and $obj =~ /[<>&;]/ and not $objs->{"_cdata"}
$obj and $obj =~ /[<>&;]/
MC/DC0%0/3
$obj and $obj =~ /[<>&;]/ and not $objs->{"_cdata"}
$obj
$obj =~ /[<>&;]/
not $objs->{"_cdata"}
Truth table0%0/4
A and B and not(C)
A= $objB= $obj =~ /[<>&;]/C= not $objs->{"_cdata"}
| |||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | ▶ | else { $xml .= $obj if( $obj =~ /\S/ ); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||
| 827 | elsif( $i =~ /^_/ ) {} | ||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | else { $xml .= "$less$tn0$i$tn1$more$obj$less/$tn0$i$tn1$more"; } | |||||||||||||||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | ▶ | my $pad2 = $imm ? '' : $pad; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | ▶ | if( substr( $name, 0, 1 ) ne '_' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 833 | 0 | ▶ | if( $name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | ▶ | if( $imm ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | ▶ | if( $xml =~ /\S/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | $xml = "$sp0$pad$sp1$less$tn0$name$tn1$att$more$cd0$xml$cd1$less/$tn0$name$tn1$more"; | |||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||
| 838 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | $xml = "$sp0$pad$sp1$less$tn0$name$tn1$att/$more"; | |||||||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||
| 842 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | ▶ | if( $xml =~ /\S/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | $xml = "$sp0$pad$sp1$less$tn0$name$tn1$att$more<div class='node'>$xml</div>$sp0$pad$sp1$less/$tn0$name$tn1$more"; | |||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||
| 846 | 0 | else { $xml = "$sp0$pad$sp1$less$tn0$name$tn1$att/$more"; } | |||||||||||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | ▶ | $xml .= "<br>" if( $objs->{'_br'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | ▶ | if( $objs->{'_note'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | $xml .= "<br>"; | |||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | my $note = $objs->{'_note'}{'value'}; | |||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | my @notes = split( /\|/, $note ); | |||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | for( @notes ) { | |||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | $xml .= "<div class='note'>$sp0$pad$sp1<span class='com'><!--</span> $_ <span class='com'>--></span></div>"; | |||||||||||||||||||||||||||||||||||||||||
| 856 | } | ||||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | ▶ | return $xml."<br>\n" if( $level ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 859 | 0 | return $xml; | |||||||||||||||||||||||||||||||||||||||||
| 860 | } | ||||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||
| 864 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||
| 866 | __END__ | ||||||||||||||||||||||||||||||||||||||||||