| 1 | package IO::Util ; | ||||||||||||||||||||||||||||||||||||
| 2 | 7 | $VERSION = 1.5 ; | |||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use 5.006_001 ; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use strict ; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||
| 6 | # This file uses the "Perlish" coding style | ||||||||||||||||||||||||||||||||||||
| 7 | # please read http://perl.4pro.net/perlish_coding_style.html | ||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | ; use Carp | ||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | ; $Carp::Internal{+__PACKAGE__}++ | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | ; use File::Spec | ||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | ############# slurping files ############# | ||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | ; sub slurp | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | 10 | ▶ | { my %a = map {ref||path => $_} @_ | ||||||||||||||||||||||||||||||||||
|
Subroutine
slurp: called CC=10 SCAR=23.0
Pod
documented
Condition100%2/2
ref $_ || 'path'
MC/DC100%1/1
ref $_ || 'path'
ref $_
Truth table100%2/2
A
A= ref $_
| |||||||||||||||||||||||||||||||||||||
| 17 | ; local $_ = defined $a{path} ? $a{path} | ||||||||||||||||||||||||||||||||||||
| 18 | : defined $a{GLOB} ? $a{GLOB} | ||||||||||||||||||||||||||||||||||||
| 19 | 10 | ▶ | : (defined && length) ? $_ | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
defined $_ and length $_
MC/DC50%1/2
defined $_ and length $_
defined $_
length $_
Truth table66%2/3
A and B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||||
| 20 | : croak 'Wrong file argument, died' | ||||||||||||||||||||||||||||||||||||
| 21 | 9 | ▶ | ; $a{SCALAR} ||= \ my $content | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$a{"SCALAR"} ||= \my $content
MC/DC100%1/1
$a{"SCALAR"} ||= \my $content
$a{"SCALAR"}
Truth table100%2/2
A
A= $a{"SCALAR"}
| |||||||||||||||||||||||||||||||||||||
| 22 | 9 | ▶ | ; if ( ref eq 'GLOB' | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $_ eq "GLOB" or ref \$_ eq "GLOB"
MC/DC100%2/2
ref $_ eq "GLOB" or ref \$_ eq "GLOB"
ref $_ eq "GLOB"
ref \$_ eq "GLOB"
Truth table100%3/3
A or B
A= ref $_ eq "GLOB"B= ref \$_ eq "GLOB"
| |||||||||||||||||||||||||||||||||||||
| 23 | || ref \$_ eq 'GLOB' | ||||||||||||||||||||||||||||||||||||
| 24 | ) | ||||||||||||||||||||||||||||||||||||
| 25 | 3 | { ${$a{SCALAR}} = do { local $/; <$_> } | |||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||
| 27 | else | ||||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | { open _ or croak "$^E, died" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 29 | 5 | ; ${$a{SCALAR}} = do { local $/; <_> } | |||||||||||||||||||||||||||||||||||
| 30 | 5 | ; close _ | |||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||
| 32 | ; $a{SCALAR} | ||||||||||||||||||||||||||||||||||||
| 33 | 8 | } | |||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | ############# unique ids ############# | ||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||
| 38 | 7 | ; my %charset = ( base34 => [ 1..9, 'A'..'N', 'P'..'Z' ] | |||||||||||||||||||||||||||||||||||
| 39 | , base62 => [ 0..9, 'a'..'z', 'A'..'Z' ] | ||||||||||||||||||||||||||||||||||||
| 40 | ) | ||||||||||||||||||||||||||||||||||||
| 41 | 7 | ; my $separator = '_' | |||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||
| 43 | ; sub import | ||||||||||||||||||||||||||||||||||||
| 44 | 6 | ▶ | { return unless @_ | ||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | ; require Exporter | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 46 | 6 | ; our @ISA = 'Exporter' | |||||||||||||||||||||||||||||||||||
| 47 | 6 | ; our @EXPORT_OK = qw| capture | |||||||||||||||||||||||||||||||||||
| 48 | slurp | ||||||||||||||||||||||||||||||||||||
| 49 | Tid Lid Uid | ||||||||||||||||||||||||||||||||||||
| 50 | load_mml | ||||||||||||||||||||||||||||||||||||
| 51 | | | ||||||||||||||||||||||||||||||||||||
| 52 | 6 | ; my ($pkg, @subs) = @_ | |||||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | ; require Time::HiRes if grep /id$/ , @subs | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | ; require Sys::Hostname if grep /^Uid$/, @subs | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 55 | 6 | ; $pkg->export_to_level(1, @_) | |||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | ; sub _convert | ||||||||||||||||||||||||||||||||||||
| 59 | 54 | ▶ | { my ( $num, $args ) = @_ | ||||||||||||||||||||||||||||||||||
|
Subroutine
_convert: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||
| 60 | ; my $chars = defined $$args{chars} | ||||||||||||||||||||||||||||||||||||
| 61 | ? ref($$args{chars}) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||
| 62 | ? $$args{chars} | ||||||||||||||||||||||||||||||||||||
| 63 | : exists $charset{$$args{chars}} | ||||||||||||||||||||||||||||||||||||
| 64 | ? $charset{$$args{chars}} | ||||||||||||||||||||||||||||||||||||
| 65 | : croak 'Invalid chars, died' | ||||||||||||||||||||||||||||||||||||
| 66 | : $charset{base34} | ||||||||||||||||||||||||||||||||||||
| 67 | 54 | ▶ | ; my $result = '' | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 68 | 54 | ; my $dnum = @$chars | |||||||||||||||||||||||||||||||||||
| 69 | 54 | ▶ | ; while ( $num > 0 ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 70 | 271 | { substr($result, 0, 0) = $$chars[ $num % $dnum] | |||||||||||||||||||||||||||||||||||
| 71 | 271 | ; $num = int($num/$dnum) | |||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||
| 73 | 54 | ; $result | |||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||
| 76 | ; sub Tid | ||||||||||||||||||||||||||||||||||||
| 77 | 18 | ▶ | { require Time::HiRes | ||||||||||||||||||||||||||||||||||
|
Subroutine
Tid: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 78 | 18 | ; my %args = @_ | |||||||||||||||||||||||||||||||||||
| 79 | 18 | ▶ | ; my $sep = defined $args{separator} ? $args{separator} : $separator | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 80 | 18 | ; my($sec, $usec) = Time::HiRes::gettimeofday() | |||||||||||||||||||||||||||||||||||
| 81 | 18 | ; my($new_sec, $new_usec) | |||||||||||||||||||||||||||||||||||
| 82 | 18 | ▶ | ; do{ ($new_sec, $new_usec) = Time::HiRes::gettimeofday() } | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$new_usec != $usec or $new_sec != $sec
MC/DC0%0/2
$new_usec != $usec or $new_sec != $sec
$new_usec != $usec
$new_sec != $sec
Truth table33%1/3
A or B
A= $new_usec != $usecB= $new_sec != $sec
| |||||||||||||||||||||||||||||||||||||
| 83 | until ( $new_usec != $usec || $new_sec != $sec ) | ||||||||||||||||||||||||||||||||||||
| 84 | 18 | ; join $sep, map _convert($_, \%args), $sec , $usec | |||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||
| 87 | ; sub Lid | ||||||||||||||||||||||||||||||||||||
| 88 | 12 | ▶ | { my %args = @_ | ||||||||||||||||||||||||||||||||||
|
Subroutine
Lid: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 89 | 12 | ▶ | ; my $sep = defined $args{separator} ? $args{separator} : $separator | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 90 | 12 | ; join $sep, _convert($$, \%args), Tid(@_) | |||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||
| 93 | ; sub Uid | ||||||||||||||||||||||||||||||||||||
| 94 | 6 | ▶ | { require Sys::Hostname | ||||||||||||||||||||||||||||||||||
|
Subroutine
Uid: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 95 | 6 | ; my %args = @_ | |||||||||||||||||||||||||||||||||||
| 96 | 6 | ▶ | ; my $sep = defined $args{separator} ? $args{separator} : $separator | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 97 | ; my $ip = sprintf '1%03d%03d%03d%03d' | ||||||||||||||||||||||||||||||||||||
| 98 | , $args{IP} | ||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | ? @{$args{IP}} | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 100 | : unpack( "C4", (gethostbyname(Sys::Hostname::hostname()))[4] ) | ||||||||||||||||||||||||||||||||||||
| 101 | 6 | ; join $sep, _convert($ip, \%args), Lid(@_) | |||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||
| 104 | ############# parsing cache ############# | ||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||
| 106 | 7 | ; our %PARSING_CACHE | |||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||
| 108 | ; sub _path_mtime | ||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | { my $path = File::Spec->rel2abs($_[0]) | ||||||||||||||||||||||||||||||||||
|
Subroutine
_path_mtime: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | ; my $mtime = ( stat($path) )[9] or croak "$^E, died" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 111 | 0 | ; $path, $mtime | |||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||
| 114 | ; sub _set_parsing_cache | ||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | { my $type = shift | ||||||||||||||||||||||||||||||||||
|
Subroutine
_set_parsing_cache: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 116 | 0 | ; my ($path, $mtime) = &_path_mtime | |||||||||||||||||||||||||||||||||||
| 117 | 0 | ; $PARSING_CACHE{$type}{$path}{mtime} = $mtime | |||||||||||||||||||||||||||||||||||
| 118 | 0 | ; $PARSING_CACHE{$type}{$path}{value} = $_[1] | |||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||
| 121 | ; sub _get_parsing_cache | ||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | { my $type = shift | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_parsing_cache: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||
| 123 | 0 | ; my ($path, $mtime) = &_path_mtime | |||||||||||||||||||||||||||||||||||
| 124 | ; exists $PARSING_CACHE{$type}{$path} # if it is cached | ||||||||||||||||||||||||||||||||||||
| 125 | &&! $mtime > $PARSING_CACHE{$type}{$path}{mtime} # and not old | ||||||||||||||||||||||||||||||||||||
| 126 | ? $PARSING_CACHE{$type}{$path}{value} | ||||||||||||||||||||||||||||||||||||
| 127 | : undef | ||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | } | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $IO::Util::PARSING_CACHE{$type}{$path} and !$mtime > $IO::Util::PARSING_CACHE{$type}{$path}{"mtime"}
MC/DC0%0/2
exists $IO::Util::PARSING_CACHE{$type}{$path} and !$mtime > $IO::Util::PARSING_CACHE{$type}{$path}{"mtime"}
exists $IO::Util::PARSING_CACHE{$type}{$path}
!$mtime > $IO::Util::PARSING_CACHE{$type}{$path}{"mtime"}
Truth table0%0/3
A and not(B)
A= exists $IO::Util::PARSING_CACHE{$type}{$path}B= !$mtime > $IO::Util::PARSING_CACHE{$type}{$path}{"mtime"}
| |||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||
| 130 | ; sub _purge_parsing_cache | ||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | { my $type = shift | ||||||||||||||||||||||||||||||||||
|
Subroutine
_purge_parsing_cache: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | ; @_ || return delete $PARSING_CACHE{$type} | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 133 | 0 | ; map delete $PARSING_CACHE{$type}{$_} | |||||||||||||||||||||||||||||||||||
| 134 | , map File::Spec->rel2abs($_) | ||||||||||||||||||||||||||||||||||||
| 135 | , @_ | ||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||
| 138 | ############# loading MML ############# | ||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||
| 141 | 7 | ; my %parser_re = ( '<>' => | |||||||||||||||||||||||||||||||||||
| 142 | qr/ \G(.*?) # elements and text outside blocks | ||||||||||||||||||||||||||||||||||||
| 143 | (?<!\\)< # not excaped '<' | ||||||||||||||||||||||||||||||||||||
| 144 | (\w+)([^>]*?) # id + attributes | ||||||||||||||||||||||||||||||||||||
| 145 | (?<!\\)> # not escaped '>' | ||||||||||||||||||||||||||||||||||||
| 146 | (.*?) # content | ||||||||||||||||||||||||||||||||||||
| 147 | <\/\2> # end | ||||||||||||||||||||||||||||||||||||
| 148 | /xs | ||||||||||||||||||||||||||||||||||||
| 149 | , '[]' => | ||||||||||||||||||||||||||||||||||||
| 150 | qr/ \G(.*?) # elements and text outside blocks | ||||||||||||||||||||||||||||||||||||
| 151 | (?<!\\)\[ # not excaped '[' | ||||||||||||||||||||||||||||||||||||
| 152 | (\w+)([^\]]*?) # id + attributes | ||||||||||||||||||||||||||||||||||||
| 153 | (?<!\\)\] # not escaped ']' | ||||||||||||||||||||||||||||||||||||
| 154 | (.*?) # content | ||||||||||||||||||||||||||||||||||||
| 155 | \[\/\2\] # end | ||||||||||||||||||||||||||||||||||||
| 156 | /xs | ||||||||||||||||||||||||||||||||||||
| 157 | , '{}' => | ||||||||||||||||||||||||||||||||||||
| 158 | qr/ \G(.*?) # elements and text outside blocks | ||||||||||||||||||||||||||||||||||||
| 159 | (?<!\\)\{ # not excaped '<' | ||||||||||||||||||||||||||||||||||||
| 160 | (\w+)([^\}]*?) # id + attributes | ||||||||||||||||||||||||||||||||||||
| 161 | (?<!\\)\} # not escaped '>' | ||||||||||||||||||||||||||||||||||||
| 162 | (.*?) # content | ||||||||||||||||||||||||||||||||||||
| 163 | \{\/\2\} # end | ||||||||||||||||||||||||||||||||||||
| 164 | /xs | ||||||||||||||||||||||||||||||||||||
| 165 | ) | ||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||
| 167 | 7 | ; my %not_escaped_re = ( '<>' => qr/( (?<!\\) < | (?<!\\) > )/xs | |||||||||||||||||||||||||||||||||||
| 168 | , '[]' => qr/( (?<!\\) \[ | (?<!\\) \] )/xs | ||||||||||||||||||||||||||||||||||||
| 169 | , '{}' => qr/( (?<!\\) \{ | (?<!\\) \} )/xs | ||||||||||||||||||||||||||||||||||||
| 170 | ) | ||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||
| 172 | 7 | ; my %comment_re = ( '<>' => qr/<!--.*?-->/xs | |||||||||||||||||||||||||||||||||||
| 173 | , '[]' => qr/\[!--.*?--\]/xs | ||||||||||||||||||||||||||||||||||||
| 174 | , '{}' => qr/\{!--.*?--\}/xs | ||||||||||||||||||||||||||||||||||||
| 175 | ) | ||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||
| 177 | ; sub load_mml | ||||||||||||||||||||||||||||||||||||
| 178 | 40 | ▶ | { my $mml = shift | ||||||||||||||||||||||||||||||||||
|
Subroutine
load_mml: called CC=16 SCAR=34.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 179 | 40 | ▶ | ; my $opt = ref $_[0] eq 'HASH' ? $_[0] : { @_ } | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 180 | 40 | ▶ | ; if ( $$opt{optional} && not ref $mml ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt->{"optional"} and not ref $mml
MC/DC0%0/2
$opt->{"optional"} and not ref $mml
$opt->{"optional"}
not ref $mml
Truth table33%1/3
A and not(B)
A= $opt->{"optional"}B= not ref $mml
| |||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | { return unless -f $mml | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||
| 183 | 40 | ; my $struct | |||||||||||||||||||||||||||||||||||
| 184 | 40 | ▶ | ; defined $$opt{cache} or $$opt{cache} = 1 | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 185 | 40 | ▶ | ; if ( $$opt{cache} && not ref $mml ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt->{"cache"} and not ref $mml
MC/DC0%0/2
$opt->{"cache"} and not ref $mml
$opt->{"cache"}
not ref $mml
Truth table33%1/3
A and not(B)
A= $opt->{"cache"}B= not ref $mml
| |||||||||||||||||||||||||||||||||||||
| 186 | 0 | { $struct = _get_parsing_cache 'mml_struct', $mml | |||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | ; return $struct if $struct | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||
| 189 | 40 | ▶ | ; defined $$opt{strict} or $$opt{strict} = 1 | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 190 | 40 | ▶ | ; my $content = ref $mml eq 'SCALAR' ? $mml : slurp $mml | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 191 | 40 | ▶ | ; $$opt{markers} ||= '<>' | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt->{"markers"} ||= "<>"
MC/DC100%1/1
$opt->{"markers"} ||= "<>"
$opt->{"markers"}
Truth table100%2/2
A
A= $opt->{"markers"}
| |||||||||||||||||||||||||||||||||||||
| 192 | 40 | ; $$content =~ s/$comment_re{$$opt{markers}}//g | |||||||||||||||||||||||||||||||||||
| 193 | 34 | ; $struct = parse_mml( '', $content, $opt ) | |||||||||||||||||||||||||||||||||||
| 194 | 34 | ▶ | ; unless ( $$opt{keep_root} ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 195 | 32 | ▶ | { ref $struct eq 'HASH' | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 196 | or croak 'Parsed structure is not a HASH reference: ' | ||||||||||||||||||||||||||||||||||||
| 197 | . 'check your MML or set keep_root, died' | ||||||||||||||||||||||||||||||||||||
| 198 | 32 | ; $struct = $$struct{(keys %$struct)[0]} | |||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||
| 200 | 34 | ▶ | ; $$opt{cache} &&! ref($mml) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt->{"cache"} and not ref $mml
MC/DC0%0/2
$opt->{"cache"} and not ref $mml
$opt->{"cache"}
not ref $mml
Truth table33%1/3
A and not(B)
A= $opt->{"cache"}B= not ref $mml
| |||||||||||||||||||||||||||||||||||||
| 201 | && _set_parsing_cache 'mml_struct', $mml, $struct | ||||||||||||||||||||||||||||||||||||
| 202 | 34 | ; $struct | |||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||
| 205 | ; sub parse_mml | ||||||||||||||||||||||||||||||||||||
| 206 | 236 | ▶ | { my ($id, $mml, $opt) = @_ | ||||||||||||||||||||||||||||||||||
|
Subroutine
parse_mml: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 207 | 236 | ; my ($node, $control, $no_data) | |||||||||||||||||||||||||||||||||||
| 208 | 236 | ▶ | ; while ( $$mml =~ /$parser_re{$$opt{markers}}/g ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 209 | 204 | { $no_data = 1 | |||||||||||||||||||||||||||||||||||
| 210 | 204 | ; my ( $garb, $child_id, $attr, $child_mml ) = ($1, $2, $3, $4) | |||||||||||||||||||||||||||||||||||
| 211 | 204 | ▶ | ; if ( $$opt{strict} ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 212 | 168 | ▶ | { $garb =~ /\S/ && croak | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 213 | "Garbage '$garb' found parsing element '$child_id', died" | ||||||||||||||||||||||||||||||||||||
| 214 | 168 | ▶ | ; length $attr && croak | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 215 | "Attributes '$attr' found parsing element '$child_id', died" | ||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||
| 217 | ; my ($k) = grep $child_id =~ /$_/ | ||||||||||||||||||||||||||||||||||||
| 218 | 204 | , keys %{$$opt{handler}} | |||||||||||||||||||||||||||||||||||
| 219 | ; my $parser_sub = defined $k | ||||||||||||||||||||||||||||||||||||
| 220 | 204 | ▶ | ? $$opt{handler}{$k} | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 221 | : \&parse_mml | ||||||||||||||||||||||||||||||||||||
| 222 | 7 | ▶ | ; my $child = do{ no strict 'refs' | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 223 | 7 | ; &$parser_sub($child_id, \$child_mml, $opt) | |||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||
| 225 | 204 | ▶ | ; if ( defined $child ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 226 | 202 | ▶ | { if ( defined $$control{$child_id} ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 227 | 20 | ▶ | { if ( $$control{$child_id} > 1 ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 228 | 8 | { push @{$$node{$child_id}}, $child | |||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||
| 230 | else | ||||||||||||||||||||||||||||||||||||
| 231 | 12 | { $$node{$child_id} = [ $$node{$child_id}, $child ] | |||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||
| 234 | else | ||||||||||||||||||||||||||||||||||||
| 235 | 182 | { $$node{$child_id} = $child | |||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||
| 237 | 202 | ; $$control{$child_id} ++ | |||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||
| 240 | 236 | ▶ | ; return $node if $no_data | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 241 | ; $$opt{strict} && ( $$mml =~ $not_escaped_re{$$opt{markers}} ) | ||||||||||||||||||||||||||||||||||||
| 242 | 142 | ▶ | and croak "Not escaped '$1' found in '$id' data, died" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt->{"strict"} and $$mml =~ /$not_escaped_re{$opt->{"markers"}}/
MC/DC0%0/2
$opt->{"strict"} and $$mml =~ /$not_escaped_re{$opt->{"markers"}}/
$opt->{"strict"}
$$mml =~ /$not_escaped_re{$opt->{"markers"}}/
Truth table66%2/3
A and B
A= $opt->{"strict"}B= $$mml =~ /$not_escaped_re{$opt->{"markers"}}/
| |||||||||||||||||||||||||||||||||||||
| 243 | 142 | ; $$mml =~ s/\\(.)/$1/g # unescape | |||||||||||||||||||||||||||||||||||
| 244 | ; my ($k) = grep $id =~ /$_/ | ||||||||||||||||||||||||||||||||||||
| 245 | 142 | , keys %{$$opt{filter}} | |||||||||||||||||||||||||||||||||||
| 246 | 142 | ▶ | ; my $filter_sub = $$opt{filter}{$k} if defined $k | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 247 | ; $filter_sub | ||||||||||||||||||||||||||||||||||||
| 248 | 142 | ▶ | ? do{ local $_ = $$mml | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 249 | 7 | ▶ | ; no strict 'refs' | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 250 | 7 | ; &{$filter_sub}($id, $mml, $opt) | |||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||
| 252 | : $$mml | ||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||
| 255 | ; sub TRIM_BLANKS # filter | ||||||||||||||||||||||||||||||||||||
| 256 | 32 | ▶ | { s/^\s+//gm | ||||||||||||||||||||||||||||||||||
|
Subroutine
TRIM_BLANKS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 257 | 32 | ; s/\s+$//gm | |||||||||||||||||||||||||||||||||||
| 258 | 32 | ; $_ | |||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||
| 261 | ; sub ONE_LINE # filter | ||||||||||||||||||||||||||||||||||||
| 262 | 30 | ▶ | { s/\n+/ /g | ||||||||||||||||||||||||||||||||||
|
Subroutine
ONE_LINE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 263 | 30 | ; $_ | |||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||
| 266 | ; sub SPLIT_LINES # handler | ||||||||||||||||||||||||||||||||||||
| 267 | 2 | ▶ | { [ split /\n+/, parse_mml @_ ] | ||||||||||||||||||||||||||||||||||
|
Subroutine
SPLIT_LINES: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||
| 270 | ############## capturing output ############# | ||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||
| 272 | ; sub capture (&;@) | ||||||||||||||||||||||||||||||||||||
| 273 | 9 | ▶ | { my %a = map {ref, $_} @_ | ||||||||||||||||||||||||||||||||||
|
Subroutine
capture: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 274 | 9 | ▶ | ; $a{GLOB} ||= select | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$a{"GLOB"} ||= select
MC/DC0%0/2
$a{"GLOB"} ||= select
$a{"GLOB"}
select
Truth table66%2/3
A ||= B
A= $a{"GLOB"}B= select
| |||||||||||||||||||||||||||||||||||||
| 275 | ; local $IO::Util::WriteHandle::out_ref | ||||||||||||||||||||||||||||||||||||
| 276 | 9 | ▶ | = $a{SCALAR} || \ my $scalar | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$a{'SCALAR'} || \my $scalar
MC/DC100%1/1
$a{'SCALAR'} || \my $scalar
$a{'SCALAR'}
Truth table100%2/2
A
A= $a{'SCALAR'}
| |||||||||||||||||||||||||||||||||||||
| 277 | 7 | ▶ | ; no strict 'refs' | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 278 | 7 | ▶ | ; if ( my $tied = tied *{$a{GLOB}} ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 279 | 2 | { my $tied_class = ref $tied | |||||||||||||||||||||||||||||||||||
| 280 | 2 | ; bless $tied, 'IO::Util::WriteHandle' | |||||||||||||||||||||||||||||||||||
| 281 | 2 | ; $a{CODE}->() | |||||||||||||||||||||||||||||||||||
| 282 | 2 | ; bless $tied, $tied_class | |||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||
| 284 | else | ||||||||||||||||||||||||||||||||||||
| 285 | 7 | { tie *{$a{GLOB}}, 'IO::Util::WriteHandle' | |||||||||||||||||||||||||||||||||||
| 286 | 7 | ; $a{CODE}->() | |||||||||||||||||||||||||||||||||||
| 287 | 7 | ; untie *{$a{GLOB}} | |||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||
| 289 | 9 | ; $IO::Util::WriteHandle::out_ref | |||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||
| 293 | ############################### | ||||||||||||||||||||||||||||||||||||
| 294 | ; package IO::Util::WriteHandle | ||||||||||||||||||||||||||||||||||||
| 295 | ; use strict | ||||||||||||||||||||||||||||||||||||
| 296 | 7 | ▶ | ; our $out_ref | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||
| 298 | ; sub TIEHANDLE | ||||||||||||||||||||||||||||||||||||
| 299 | 7 | ▶ | { bless \ my $dummy, $_[0] | ||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHANDLE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||
| 302 | ; sub WRITE | ||||||||||||||||||||||||||||||||||||
| 303 | 2 | ▶ | { shift | ||||||||||||||||||||||||||||||||||
|
Subroutine
WRITE: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||
| 304 | 2 | ; my( $scalar, $len, $offset ) = @_ | |||||||||||||||||||||||||||||||||||
| 305 | 2 | ▶ | ; my $data = substr $scalar | ||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$offset || 0
$len || length $scalar
MC/DC0%0/1
$offset || 0
$offset
MC/DC0%0/2
$len || length $scalar
$len
length $scalar
Truth table50%1/2
A
A= $offset
Truth table33%1/3
A || B
A= $lenB= length $scalar
| |||||||||||||||||||||||||||||||||||||
| 306 | , $offset || 0 | ||||||||||||||||||||||||||||||||||||
| 307 | , $len || length $scalar | ||||||||||||||||||||||||||||||||||||
| 308 | 2 | ; $$out_ref .= $data | |||||||||||||||||||||||||||||||||||
| 309 | 2 | ; length $data | |||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||
| 312 | ; sub PRINT | ||||||||||||||||||||||||||||||||||||
| 313 | 13 | ▶ | { shift | ||||||||||||||||||||||||||||||||||
|
Subroutine
PRINT: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 314 | 13 | ▶ | ; $$out_ref .= join defined $, ? $, : '', @_ | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 315 | 13 | ▶ | ; $$out_ref .= $\ if defined $\ | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 316 | 13 | ; 1 | |||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||
| 319 | ; sub PRINTF | ||||||||||||||||||||||||||||||||||||
| 320 | 1 | ▶ | { shift | ||||||||||||||||||||||||||||||||||
|
Subroutine
PRINTF: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 321 | 1 | ; $$out_ref .= sprintf shift, @_ | |||||||||||||||||||||||||||||||||||
| 322 | 1 | ; 1 | |||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | ; sub OPEN { 1 } | ||||||||||||||||||||||||||||||||||
|
Subroutine
OPEN: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | ; sub CLOSE { 1 } | ||||||||||||||||||||||||||||||||||
|
Subroutine
CLOSE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | ; sub FILENO { 1 } | ||||||||||||||||||||||||||||||||||
|
Subroutine
FILENO: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | ; sub BINMODE { 1 } | ||||||||||||||||||||||||||||||||||
|
Subroutine
BINMODE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 329 | 7 | ▶ | ; sub UNTIE { 1 } | ||||||||||||||||||||||||||||||||||
|
Subroutine
UNTIE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||
| 331 | ###### not supported ####### | ||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | ; sub READ { 0 } | ||||||||||||||||||||||||||||||||||
|
Subroutine
READ: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | ; sub READLINE { undef } | ||||||||||||||||||||||||||||||||||
|
Subroutine
READLINE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | ; sub GETC { undef } | ||||||||||||||||||||||||||||||||||
|
Subroutine
GETC: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | ; sub TELL {-1 } | ||||||||||||||||||||||||||||||||||
|
Subroutine
TELL: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | ; sub SEEK { 0 } | ||||||||||||||||||||||||||||||||||
|
Subroutine
SEEK: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | ; sub EOF { 1 } | ||||||||||||||||||||||||||||||||||
|
Subroutine
EOF: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||
| 340 | 7 | ; 1 | |||||||||||||||||||||||||||||||||||
| 341 | __END__ | ||||||||||||||||||||||||||||||||||||