Ex/Conf.pm

filter: Statementstmt 30.4% 104 / 342 Branchbran 14.1% 28 / 198 Conditioncond 20.9% 26 / 124 MC/DCmcdc 1.4% 1 / 71 Subroutinesub 38.7% 12 / 31 Podpod 26.9% 7 / 26 totaltotal 22.4% 178 / 792 CC 153 SCAR 55.5
CC
153
Cov
24%
write
650.0
read
495.9
html_parse_yaml_load
342.0
CRAP 257.7
« Ex/Dump.pm ↑ Summary Ex/Fill.pm »
1 package CGI::Ex::Conf;
2  
3 =head1 NAME
4  
5 CGI::Ex::Conf - Conf Reader/Writer for many different data format types
6  
7 =head1 VERSION
8  
9 version 2.54
10  
11 =cut
12  
13 ###----------------------------------------------------------------###
14 # Copyright - Paul Seamons #
15 # Distributed under the Perl Artistic License without warranty #
16 ###----------------------------------------------------------------###
17  
18 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 our @EXPORT_OK = qw(conf_read conf_write in_cache);
24  
25 3 our $VERSION = '2.54'; # VERSION
26  
27 3 our $DEFAULT_EXT = 'conf';
28 3 our @DEFAULT_PATHS;
29  
30 3 our %EXT_READERS = (
31 '' => \&read_handler_yaml,
32 'conf' => \&read_handler_yaml,
33 'json' => \&read_handler_json,
34 'val_json' => \&read_handler_json,
35 'ini' => \&read_handler_ini,
36 'pl' => \&read_handler_pl,
37 'sto' => \&read_handler_storable,
38 'storable' => \&read_handler_storable,
39 'val' => \&read_handler_yaml,
40 'xml' => \&read_handler_xml,
41 'yaml' => \&read_handler_yaml,
42 'yml' => \&read_handler_yaml,
43 'html' => \&read_handler_html,
44 'htm' => \&read_handler_html,
45 );
46  
47 3 our %EXT_WRITERS = (
48 '' => \&write_handler_yaml,
49 'conf' => \&write_handler_yaml,
50 'ini' => \&write_handler_ini,
51 'json' => \&write_handler_json,
52 'val_json' => \&write_handler_json,
53 'pl' => \&write_handler_pl,
54 'sto' => \&write_handler_storable,
55 'storable' => \&write_handler_storable,
56 'val' => \&write_handler_yaml,
57 'xml' => \&write_handler_xml,
58 'yaml' => \&write_handler_yaml,
59 'yml' => \&write_handler_yaml,
60 'html' => \&write_handler_html,
61 'htm' => \&write_handler_html,
62 );
63  
64 ### $DIRECTIVE controls how files are looked for when namespaces are not absolute.
65 ### If directories 1, 2 and 3 are passed and each has a config file
66 ### LAST would return 3, FIRST would return 1, and MERGE will
67 ### try to put them all together. Merge behavior of hashes
68 ### is determined by $IMMUTABLE_\w+ variables.
69 3 our $DIRECTIVE = 'LAST'; # LAST, MERGE, FIRST
70  
71 3 our $IMMUTABLE_QR = qr/_immu(?:table)?$/i;
72  
73 3 our $IMMUTABLE_KEY = 'immutable';
74  
75 3 our $NO_WARN_ON_FAIL;
76  
77 3 our $HTML_KEY;
78  
79 3 our %CACHE;
80  
81 ###----------------------------------------------------------------###
82  
83 sub new {
84 4 ▶ my $class = shift || __PACKAGE__;
Subroutine new: called CC=3 SCAR=11.1
Pod undocumented
Condition50%1/2
shift() || __PACKAGE__
l!l
40
MC/DC0%0/1
shift() || __PACKAGE__
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
85 4 ▶ my $args = shift || {};
Condition100%2/2
shift() || {}
l!l
31
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
86  
87 4 return bless {%$args}, $class;
88 }
89  
90 sub paths {
91 1 ▶ my $self = shift;
Subroutine paths: called CC=2 SCAR=7.2
Pod undocumented
92 1 ▶ return $self->{paths} ||= \@DEFAULT_PATHS;
Condition50%1/2
$self->{"paths"} ||= \@CGI::Ex::Conf::DEFAULT_PATHS
l!l
10
MC/DC0%0/1
$self->{"paths"} ||= \@CGI::Ex::Conf::DEFAULT_PATHS
$self->{"paths"}
Truth table50%1/2
A
A= $self->{"paths"}
Aresult
11
00
93 }
94  
95 ###----------------------------------------------------------------###
96  
97 sub conf_read {
98 3 ▶ my $file = shift;
Subroutine conf_read: called CC=18 SCAR=39.3
Pod documented
99 3 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
30
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
100 3 my $ext;
101  
102 ### they passed the right stuff already
103 3 ▶ if (ref $file) {
Branch: 5 branches
BranchTrueFalseTotal
if (ref $file) { } 1 2 3
elsif (exists $CGI::Ex::Conf::CACHE{$file} and not $args->{'no_cache'}) { } 0 2 2
elsif (index($file, "\n") != -1) { } 0 2 2
elsif ($args->{'file_type'}) { } 1 1 2
elsif ($file =~ /\.(\w+)$/) { } 1 0 1
104 1 ▶ if (UNIVERSAL::isa($file, 'SCALAR')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($file, 'SCALAR')) { } 0 1 1
105 0 ▶ if ($$file =~ /^\s*</) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$file =~ /^\s*</) { } 0 0 0
106 0 return html_parse_yaml_load($$file, $args); # allow for ref to a YAML string
107 } else {
108 0 return yaml_load($$file); # allow for ref to a YAML string
109 }
110 } else {
111 1 return $file;
112 }
113  
114 ### allow for a pre-cached reference
115 ▶ } elsif (exists $CACHE{$file} && ! $args->{no_cache}) {
Condition33%1/3
exists $CGI::Ex::Conf::CACHE{$file} and not $args->{"no_cache"}
!ll&&!rl&&r
200
MC/DC0%0/2
exists $CGI::Ex::Conf::CACHE{$file} and not $args->{"no_cache"}
exists $CGI::Ex::Conf::CACHE{$file} not $args->{"no_cache"}
Truth table33%1/3
A and not(B)
A= exists $CGI::Ex::Conf::CACHE{$file}B= not $args->{"no_cache"}
ABresult
0X0
100
111
116 0 return $CACHE{$file};
117  
118 ### if contains a newline - treat it as a YAML string
119 } elsif (index($file,"\n") != -1) {
120 0 return yaml_load($file);
121  
122 ### otherwise base it off of the file extension
123 } elsif ($args->{file_type}) {
124 1 $ext = $args->{file_type};
125 } elsif ($file =~ /\.(\w+)$/) {
126 1 $ext = $1;
127 } else {
128 $ext = defined($args->{default_ext}) ? $args->{default_ext}
129 0 ▶ : defined($DEFAULT_EXT) ? $DEFAULT_EXT
Branch: 2 branches
BranchTrueFalseTotal
defined $args->{'default_ext'} ? : 0 0 0
defined $CGI::Ex::Conf::DEFAULT_EXT ? : 0 0 0
130 : '';
131 0 ▶ $file = length($ext) ? "$file.$ext" : $file;
Branch: 1 branch
BranchTrueFalseTotal
length $ext ? : 0 0 0
132 }
133  
134 ### determine the handler
135 2 ▶ my $handler = $EXT_READERS{$ext} || croak "Unknown file extension: $ext";
Condition33%1/3
$CGI::Ex::Conf::EXT_READERS{$ext} || croak("Unknown file extension: $ext")
l!l&&r!l&&!r
200
MC/DC0%0/2
$CGI::Ex::Conf::EXT_READERS{$ext} || croak("Unknown file extension: $ext")
$CGI::Ex::Conf::EXT_READERS{$ext} croak("Unknown file extension: $ext")
Truth table33%1/3
A || B
A= $CGI::Ex::Conf::EXT_READERS{$ext}B= croak("Unknown file extension: $ext")
ABresult
1X1
011
000
136  
137 ### don't die if the file is not found - do die otherwise
138 2 ▶ if (! -e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 1 1 2
139 1 eval { die "Conf file $file not found\n" };
140 1 ▶ warn "Conf file $file not found" if ! $args->{'no_warn_on_fail'} && ! $NO_WARN_ON_FAIL;
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"no_warn_on_fail"} or $CGI::Ex::Conf::NO_WARN_ON_FAIL 0 1 1
Condition33%1/3
$args->{"no_warn_on_fail"} or $CGI::Ex::Conf::NO_WARN_ON_FAIL
l!l&&r!l&&!r
100
MC/DC0%0/2
$args->{"no_warn_on_fail"} or $CGI::Ex::Conf::NO_WARN_ON_FAIL
$args->{"no_warn_on_fail"} $CGI::Ex::Conf::NO_WARN_ON_FAIL
Truth table33%1/3
A or B
A= $args->{"no_warn_on_fail"}B= $CGI::Ex::Conf::NO_WARN_ON_FAIL
ABresult
1X1
011
000
141 1 return;
142 }
143  
144 1 ▶ return eval { scalar $handler->($file, $args) } || die "Error while reading conf file $file\n$@";
Condition50%1/2
eval { do { scalar &$handler($file, $args) } } || die("Error while reading conf file $file\n$@")
l!l
10
MC/DC0%0/1
eval { do { scalar &$handler($file, $args) } } || die("Error while reading conf file $file\n$@")
eval { do { scalar &$handler($file, $args) } }
Truth table50%1/2
A
A= eval { do { scalar &$handler($file, $args) } }
Aresult
11
00
145 }
146  
147 sub read_ref {
148 1 ▶ my $self = shift;
Subroutine read_ref: called CC=2 SCAR=7.0
Pod documented
149 1 my $file = shift;
150 1 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
10
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
151 1 return conf_read($file, {%$self, %$args});
152 }
153  
154 ### allow for different kinds of merging of arguments
155 ### allow for key fallback on hashes
156 ### allow for immutable values on hashes
157 sub read {
158 1 ▶ my $self = shift;
Subroutine read: called CC=37 SCAR=62.1
Pod documented
159 1 my $namespace = shift;
160 1 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
10
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
161 1 ▶ my $REF = $args->{ref} || undef; # can pass in existing set of options
Condition50%1/2
$args->{'ref'} || undef
l!l
01
MC/DC0%0/1
$args->{'ref'} || undef
$args->{'ref'}
Truth table50%1/2
A
A= $args->{'ref'}
Aresult
11
00
162 1 ▶ my $IMMUTABLE = $args->{immutable} || {}; # can pass existing immutable types
Condition50%1/2
$args->{'immutable'} || {}
l!l
01
MC/DC0%0/1
$args->{'immutable'} || {}
$args->{'immutable'}
Truth table50%1/2
A
A= $args->{'immutable'}
Aresult
11
00
163  
164 1 ▶ $self = $self->new() if ! ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1 1
165  
166 ### allow for fast short ciruit on path lookup for several cases
167 1 my $directive;
168 1 my @paths = ();
169 1 ▶ if (ref($namespace) # already a ref
Branch: 1 branch
BranchTrueFalseTotal
if (ref $namespace or index($namespace, "\n") != -1 or $namespace =~ m[^\.{0,2}/.+$]) { } 0 1 1
Condition33%2/6
ref $namespace or index($namespace, "\n") != -1 or $namespace =~ m[^\.{0,2}/.+$]
l!l&&r!l&&!r
001
ref $namespace or index($namespace, "\n") != -1
l!l&&r!l&&!r
001
MC/DC0%0/3
ref $namespace or index($namespace, "\n") != -1 or $namespace =~ m[^\.{0,2}/.+$]
ref $namespace index($namespace, "\n") != -1 $namespace =~ m[^\.{0,2}/.+$]
Truth table25%1/4
A or B or C
A= ref $namespaceB= index($namespace, "\n") != -1C= $namespace =~ m[^\.{0,2}/.+$]
ABCresult
1XX1
01X1
0011
0000
170 || index($namespace,"\n") != -1 # yaml string to read in
171 || $namespace =~ m|^\.{0,2}/.+$| # absolute or relative file
172 ) {
173 0 push @paths, $namespace;
174 0 $directive = 'FIRST';
175  
176 ### use the default directories
177 } else {
178 1 ▶ $directive = uc($args->{directive} || $self->{directive} || $DIRECTIVE);
Condition33%2/6
$args->{'directive'} || $self->{'directive'} || $DIRECTIVE
l!l&&r!l&&!r
100
$args->{"directive"} or $self->{"directive"}
l!l&&r!l&&!r
010
MC/DC0%0/3
$args->{'directive'} || $self->{'directive'} || $DIRECTIVE
$args->{"directive"} $self->{"directive"} $DIRECTIVE
Truth table25%1/4
A or B || C
A= $args->{"directive"}B= $self->{"directive"}C= $DIRECTIVE
ABCresult
1XX1
01X1
0011
0000
179 1 $namespace =~ s|::|/|g; # allow perlish style namespace
180 1 ▶ my $paths = $args->{paths} || $self->paths
Condition33%2/6
$args->{'paths'} || $self->paths || croak("No paths found during read on $namespace")
l!l&&r!l&&!r
100
$args->{"paths"} or $self->paths
l!l&&r!l&&!r
010
MC/DC0%0/3
$args->{'paths'} || $self->paths || croak("No paths found during read on $namespace")
$args->{"paths"} $self->paths croak("No paths found during read on $namespace")
Truth table25%1/4
A or B || C
A= $args->{"paths"}B= $self->pathsC= croak("No paths found during read on $namespace")
ABCresult
1XX1
01X1
0011
0000
181 || croak "No paths found during read on $namespace";
182 1 ▶ $paths = [$paths] if ! ref $paths;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $paths 0 1 1
183 1 ▶ if ($directive eq 'LAST') { # LAST shall be FIRST
Branch: 1 branch
BranchTrueFalseTotal
if ($directive eq "LAST") 0 1 1
184 0 $directive = 'FIRST';
185 0 ▶ $paths = [reverse @$paths] if $#$paths != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $paths->$#* != 0 0 0 0
186 }
187 1 foreach my $path (@$paths) {
188 1 ▶ next if exists $CACHE{$path} && ! $CACHE{$path};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CACHE{$path} and not $CACHE{$path} 0 1 1
Condition33%1/3
exists $CACHE{$path} and not $CACHE{$path}
!ll&&!rl&&r
100
MC/DC0%0/2
exists $CACHE{$path} and not $CACHE{$path}
exists $CACHE{$path} not $CACHE{$path}
Truth table33%1/3
A and not(B)
A= exists $CACHE{$path}B= not $CACHE{$path}
ABresult
0X0
100
111
189 1 push @paths, "$path/$namespace";
190 }
191 }
192  
193 ### make sure we have at least one path
194 1 ▶ if ($#paths == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#paths == -1) 0 1 1
195 0 croak "Couldn't find a path for namespace $namespace. Perhaps you need to pass paths => \@paths";
196 }
197  
198 ### now loop looking for a ref
199 1 foreach my $path (@paths) {
200 1 ▶ my $ref = $self->read_ref($path, $args) || next;
Condition50%1/2
$self->read_ref($path, $args) || (next)
l!l
01
MC/DC0%0/1
$self->read_ref($path, $args) || (next)
$self->read_ref($path, $args)
Truth table50%1/2
A
A= $self->read_ref($path, $args)
Aresult
11
00
201 0 ▶ if (! $REF) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $REF) { } 0 0 0
elsif (not UNIVERSAL::isa($ref, ref $REF)) { } 0 0 0
202 0 ▶ if (UNIVERSAL::isa($ref, 'ARRAY')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($ref, 'ARRAY')) { } 0 0 0
elsif (UNIVERSAL::isa($ref, 'HASH')) { } 0 0 0
203 0 $REF = [];
204 } elsif (UNIVERSAL::isa($ref, 'HASH')) {
205 0 $REF = {};
206 } else {
207 0 croak "Unknown config type of \"".ref($ref)."\" for namespace $namespace";
208 }
209 } elsif (! UNIVERSAL::isa($ref, ref($REF))) {
210 0 croak "Found different reference types for namespace $namespace"
211 . " - wanted a type ".ref($REF);
212 }
213 0 ▶ if (ref($REF) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $REF eq 'ARRAY') { } 0 0 0
214 0 ▶ if ($directive eq 'MERGE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($directive eq "MERGE") 0 0 0
215 0 push @$REF, @$ref;
216 0 next;
217 }
218 0 splice @$REF, 0, $#$REF + 1, @$ref;
219 0 last;
220 } else {
221 0 my $immutable = delete $ref->{$IMMUTABLE_KEY};
222 0 my ($key,$val);
223 0 ▶ if ($directive eq 'MERGE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($directive eq "MERGE") 0 0 0
224 0 ▶ while (($key,$val) = each %$ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$ref) 0 0 0
225 0 ▶ next if $IMMUTABLE->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $IMMUTABLE->{$key} 0 0 0
226 0 my $immute = $key =~ s/$IMMUTABLE_QR//o;
227 0 ▶ $IMMUTABLE->{$key} = 1 if $immute || $immutable;
Branch: 1 branch
BranchTrueFalseTotal
if $immute or $immutable 0 0 0
Condition0%0/3
$immute or $immutable
l!l&&r!l&&!r
000
MC/DC0%0/2
$immute or $immutable
$immute $immutable
Truth table0%0/3
A or B
A= $immuteB= $immutable
ABresult
1X1
011
000
228 0 $REF->{$key} = $val;
229 }
230 0 next;
231 }
232 0 ▶ delete $REF->{$key} while $key = each %$REF;
Branch: 1 branch
BranchTrueFalseTotal
defined($key = each %$REF) and do { delete $REF->{$key} } 0 0 0
233 0 ▶ while (($key,$val) = each %$ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$ref) 0 0 0
234 0 my $immute = $key =~ s/$IMMUTABLE_QR//o;
235 0 ▶ $IMMUTABLE->{$key} = 1 if $immute || $immutable;
Branch: 1 branch
BranchTrueFalseTotal
if $immute or $immutable 0 0 0
Condition0%0/3
$immute or $immutable
l!l&&r!l&&!r
000
MC/DC0%0/2
$immute or $immutable
$immute $immutable
Truth table0%0/3
A or B
A= $immuteB= $immutable
ABresult
1X1
011
000
236 0 $REF->{$key} = $val;
237 }
238 0 last;
239 }
240 }
241 1 ▶ $REF->{"Immutable Keys"} = $IMMUTABLE if scalar keys %$IMMUTABLE;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %$IMMUTABLE 0 1 1
242 1 return $REF;
243 }
244  
245 ###----------------------------------------------------------------###
246  
247 sub read_handler_ini {
248 0 ▶ my $file = shift;
Subroutine read_handler_ini: not called CC=1 SCAR=6.9
Pod undocumented
249 0 require Config::IniHash;
250 0 return Config::IniHash::ReadINI($file);
251 }
252  
253 sub read_handler_pl {
254 1 ▶ my $file = shift;
Subroutine read_handler_pl: called CC=2 SCAR=7.1
Pod undocumented
255 ### do has odd behavior in that it turns a simple hashref
256 ### into hash - help it out a little bit
257 1 my @ref = do $file;
258 1 ▶ return ($#ref != 0) ? {@ref} : $ref[0];
Branch: 1 branch
BranchTrueFalseTotal
$#ref != 0 ? : 0 1 1
259 }
260  
261 sub read_handler_json {
262 0 ▶ my $file = shift;
Subroutine read_handler_json: not called CC=3 SCAR=24.8
Pod undocumented
263 0 local *IN;
264 0 ▶ open (IN, $file) || die "Couldn't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open IN, $file or die "Couldn't open ${file}: $!" 0 0 0
265 0 CORE::read(IN, my $text, -s $file);
266 0 close IN;
267 0 require JSON;
268 0 ▶ my $decode = JSON->can('decode') ? 'decode' : 'jsonToObj';
Branch: 1 branch
BranchTrueFalseTotal
'JSON'->can('decode') ? : 0 0 0
269 0 return scalar JSON->new->$decode($text);
270 }
271  
272 sub read_handler_storable {
273 0 ▶ my $file = shift;
Subroutine read_handler_storable: not called CC=1 SCAR=6.9
Pod undocumented
274 0 require Storable;
275 0 return Storable::retrieve($file);
276 }
277  
278 sub read_handler_yaml {
279 0 ▶ my $file = shift;
Subroutine read_handler_yaml: not called CC=2 SCAR=17.9
Pod undocumented
280 0 local *IN;
281 0 ▶ open (IN, $file) || die "Couldn't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open IN, $file or die "Couldn't open ${file}: $!" 0 0 0
282 0 CORE::read(IN, my $text, -s $file);
283 0 close IN;
284 0 return yaml_load($text);
285 }
286  
287 sub yaml_load {
288 0 ▶ my $text = shift;
Subroutine yaml_load: not called CC=3 SCAR=24.8
Pod undocumented
289 0 require YAML;
290 0 my @ret = eval { YAML::Load($text) };
291 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
292 0 die "$@";
293 }
294 0 ▶ return ($#ret == 0) ? $ret[0] : \@ret;
Branch: 1 branch
BranchTrueFalseTotal
$#ret == 0 ? : 0 0 0
295 }
296  
297 sub read_handler_xml {
298 0 ▶ my $file = shift;
Subroutine read_handler_xml: not called CC=1 SCAR=6.9
Pod undocumented
299 0 require XML::Simple;
300 0 return XML::Simple::XMLin($file);
301 }
302  
303 ### this handler will only function if a html_key (such as validation)
304 ### is specified - actually this somewhat specific to validation - but
305 ### I left it as a general use for other types
306  
307 ### is specified
308 sub read_handler_html {
309 0 ▶ my $file = shift;
Subroutine read_handler_html: not called CC=5 SCAR=34.0
Pod undocumented
310 0 my $args = shift;
311 0 ▶ if (! eval { require YAML }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require YAML } }) 0 0 0
312 0 my $err = $@;
313 0 my $found = 0;
314 0 my $i = 0;
315 0 ▶ while (my($pkg, $file, $line, $sub) = caller($i++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = caller $i++) 0 0 0
316 0 ▶ return undef if $sub =~ /\bpreload_files$/;
Branch: 1 branch
BranchTrueFalseTotal
if $sub =~ /\bpreload_files$/ 0 0 0
317 }
318 0 die $err;
319 }
320  
321 ### get the html
322 0 local *IN;
323 0 ▶ open (IN, $file) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
open IN, $file or return undef 0 0 0
324 0 CORE::read(IN, my $html, -s $file);
325 0 close IN;
326  
327 0 return html_parse_yaml_load($html, $args);
328 }
329  
330 sub html_parse_yaml_load {
331 0 ▶ my $html = shift;
Subroutine html_parse_yaml_load: not called CC=18 SCAR=58.3
Pod undocumented
332 0 ▶ my $args = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
333 0 ▶ my $key = $args->{html_key} || $HTML_KEY;
Condition0%0/3
$args->{'html_key'} || $HTML_KEY
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'html_key'} || $HTML_KEY
$args->{'html_key'} $HTML_KEY
Truth table0%0/3
A || B
A= $args->{'html_key'}B= $HTML_KEY
ABresult
1X1
011
000
334 0 ▶ return undef if ! $key || $key !~ /^\w+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key and $key =~ /^\w+$/ 0 0 0
Condition0%0/3
$key and $key =~ /^\w+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$key and $key =~ /^\w+$/
$key $key =~ /^\w+$/
Truth table0%0/3
A and B
A= $keyB= $key =~ /^\w+$/
ABresult
0X0
100
111
335  
336 0 my $str = '';
337 0 my @order = ();
338 0 ▶ while ($html =~ m{
Branch: 1 branch
BranchTrueFalseTotal
if ($html =~ / (document\. # global javascript | var\s+ # local javascript | <\w+\s+[^>]*?) # input, form, select, textarea tag \Q$key\E # the key \s*=\s* # an equals sign ([\"\']) # open quote (.+?[^\\]) # something in between \2 # close quote /gsx) 0 0 0
339 (document\. # global javascript
340 | var\s+ # local javascript
341 | <\w+\s+[^>]*?) # input, form, select, textarea tag
342 \Q$key\E # the key
343 \s*=\s* # an equals sign
344 ([\"\']) # open quote
345 (.+?[^\\]) # something in between
346 \2 # close quote
347 }xsg) {
348 0 my ($line, $quot, $yaml) = ($1, $2, $3);
349 0 ▶ if ($line =~ /^(document\.|var\s)/) { # js variable
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(document\.|var\s)/) { } 0 0 0
350 0 $yaml =~ s/\\$quot/$quot/g;
351 0 $yaml =~ s/\\n\\\n?/\n/g;
352 0 $yaml =~ s/\\\\/\\/g;
353 0 $yaml =~ s/\s*$/\n/s; # fix trailing newline
354 0 $str = $yaml; # use last one found
355 } else { # inline attributes
356 0 $yaml =~ s/\s*$/\n/s; # fix trailing newline
357 0 ▶ if ($line =~ m/<form/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /<form/i) { } 0 0 0
elsif ($line =~ /\bname\s*=\s*('[^\']*'|"[^\"]*"|\S+)/) { } 0 0 0
358 0 ▶ $yaml =~ s/^\Q$1\E//m if $yaml =~ m/^( +)/s;
Branch: 1 branch
BranchTrueFalseTotal
if $yaml =~ /^( +)/s 0 0 0
359 0 $str .= $yaml;
360  
361 } elsif ($line =~ m/\bname\s*=\s*('[^\']*'|"[^\"]*"|\S+)/) {
362 0 my $key = $1;
363 0 push @order, $key;
364 0 $yaml =~ s/^/ /mg; # indent entire thing
365 0 $yaml =~ s/^(\ *[^\s&*\{\[])/\n$1/; # add first newline
366 0 $str .= "$key:$yaml";
367 }
368 }
369 }
370 0 ▶ $str .= "group order: [".join(", ",@order)."]\n"
Branch: 1 branch
BranchTrueFalseTotal
if $str and $#order != -1 and $key eq "validation" 0 0 0
Condition0%0/6
$str and $#order != -1 and $key eq "validation"
!ll&&!rl&&r
000
$str and $#order != -1
!ll&&!rl&&r
000
MC/DC0%0/3
$str and $#order != -1 and $key eq "validation"
$str $#order != -1 $key eq "validation"
Truth table0%0/4
A and B and C
A= $strB= $#order != -1C= $key eq "validation"
ABCresult
0XX0
10X0
1100
1111
371 if $str && $#order != -1 && $key eq 'validation';
372  
373 0 ▶ return undef if ! $str;
Branch: 1 branch
BranchTrueFalseTotal
unless $str 0 0 0
374 0 my $ref = eval { yaml_load($str) };
375 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
376 0 my $err = "$@";
377 0 ▶ if ($err =~ /line:\s+(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err =~ /line:\s+(\d+)/) 0 0 0
378 0 my $line = $1;
379 0 ▶ while ($str =~ m/(.+)/gm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /(.+)/gm) 0 0 0
380 0 ▶ next if -- $line;
Branch: 1 branch
BranchTrueFalseTotal
if --$line 0 0 0
381 0 $err .= "LINE = \"$1\"\n";
382 0 last;
383 }
384 }
385 0 die $err;
386 }
387 0 return $ref;
388 }
389  
390 ###----------------------------------------------------------------###
391  
392 sub conf_write {
393 1 ▶ my $file = shift;
Subroutine conf_write: called CC=17 SCAR=43.0
Pod undocumented
394 1 ▶ my $conf = shift || croak "Missing conf";
Condition33%1/3
shift() || croak('Missing conf')
l!l&&r!l&&!r
100
MC/DC0%0/2
shift() || croak('Missing conf')
shift() croak('Missing conf')
Truth table33%1/3
A || B
A= shift()B= croak('Missing conf')
ABresult
1X1
011
000
395 1 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
10
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
396 1 my $ext;
397  
398 1 ▶ if (ref $file) {
Branch: 5 branches
BranchTrueFalseTotal
if (ref $file) { } 0 1 1
elsif (index($file, "\n") != -1) { } 0 1 1
elsif (exists $CACHE{$file} and not $args->{'no_cache'}) { } 0 1 1
elsif ($args->{'file_type'}) { } 1 0 1
elsif ($file =~ /\.(\w+)$/) { } 0 0 0
399 0 croak "Invalid filename for write: $file";
400  
401 } elsif (index($file,"\n") != -1) {
402 0 croak "Cannot use a yaml string as a filename during write";
403  
404 ### allow for a pre-cached reference
405 ▶ } elsif (exists $CACHE{$file} && ! $args->{no_cache}) {
Condition33%1/3
exists $CACHE{$file} and not $args->{"no_cache"}
!ll&&!rl&&r
100
MC/DC0%0/2
exists $CACHE{$file} and not $args->{"no_cache"}
exists $CACHE{$file} not $args->{"no_cache"}
Truth table33%1/3
A and not(B)
A= exists $CACHE{$file}B= not $args->{"no_cache"}
ABresult
0X0
100
111
406 0 warn "Cannot write back to a file that is in the cache";
407 0 return 0;
408  
409 ### otherwise base it off of the file extension
410 } elsif ($args->{file_type}) {
411 1 $ext = $args->{file_type};
412 } elsif ($file =~ /\.(\w+)$/) {
413 0 $ext = $1;
414 } else {
415 $ext = defined($args->{default_ext}) ? $args->{default_ext}
416 0 ▶ : defined($DEFAULT_EXT) ? $DEFAULT_EXT
Branch: 2 branches
BranchTrueFalseTotal
defined $args->{'default_ext'} ? : 0 0 0
defined $DEFAULT_EXT ? : 0 0 0
417 : '';
418 0 ▶ $file = length($ext) ? "$file.$ext" : $file;
Branch: 1 branch
BranchTrueFalseTotal
length $ext ? : 0 0 0
419 }
420  
421 ### determine the handler
422 1 my $handler;
423 1 ▶ if ($args->{handler}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"handler"}) 0 1 1
424 $handler = (UNIVERSAL::isa($args->{handler},'CODE'))
425 0 ▶ ? $args->{handler} : $args->{handler}->{$ext};
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($args->{'handler'}, 'CODE') ? : 0 0 0
426 }
427 1 ▶ if (! $handler) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handler) 1 0 1
428 1 ▶ $handler = $EXT_WRITERS{$ext} || croak "Unknown file extension: $ext";
Condition33%1/3
$EXT_WRITERS{$ext} || croak("Unknown file extension: $ext")
l!l&&r!l&&!r
100
MC/DC0%0/2
$EXT_WRITERS{$ext} || croak("Unknown file extension: $ext")
$EXT_WRITERS{$ext} croak("Unknown file extension: $ext")
Truth table33%1/3
A || B
A= $EXT_WRITERS{$ext}B= croak("Unknown file extension: $ext")
ABresult
1X1
011
000
429 }
430  
431 1 ▶ return eval { scalar $handler->($file, $conf, $args) } || die "Error while writing conf file $file\n$@";
Condition50%1/2
eval { do { scalar &$handler($file, $conf, $args) } } || die("Error while writing conf file $file\n$@")
l!l
10
MC/DC0%0/1
eval { do { scalar &$handler($file, $conf, $args) } } || die("Error while writing conf file $file\n$@")
eval { do { scalar &$handler($file, $conf, $args) } }
Truth table50%1/2
A
A= eval { do { scalar &$handler($file, $conf, $args) } }
Aresult
11
00
432 }
433  
434 sub write_ref {
435 0 ▶ my $self = shift;
Subroutine write_ref: not called CC=2 SCAR=17.9
Pod documented
436 0 my $file = shift;
437 0 my $conf = shift;
438 0 ▶ my $args = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
439 0 conf_write($file, $conf, {%$self, %$args});
440 }
441  
442 ### Allow for writing out conf values
443 ### Allow for writing out the correct filename (if there is a path array)
444 ### Allow for not writing out immutable values on hashes
445 sub write {
446 0 ▶ my $self = shift;
Subroutine write: not called CC=25 SCAR=64.8
Pod documented
447 0 my $namespace = shift;
448 0 ▶ my $conf = shift || croak "Must pass hashref to write out"; # the info to write
Condition0%0/3
shift() || croak('Must pass hashref to write out')
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || croak('Must pass hashref to write out')
shift() croak('Must pass hashref to write out')
Truth table0%0/3
A || B
A= shift()B= croak('Must pass hashref to write out')
ABresult
1X1
011
000
449 0 ▶ my $args = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
450 0 ▶ my $IMMUTABLE = $args->{immutable} || {}; # can pass existing immutable types
Condition0%0/2
$args->{'immutable'} || {}
l!l
00
MC/DC0%0/1
$args->{'immutable'} || {}
$args->{'immutable'}
Truth table0%0/2
A
A= $args->{'immutable'}
Aresult
11
00
451  
452 0 ▶ $self = $self->new() if ! ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
453  
454 ### allow for fast short ciruit on path lookup for several cases
455 0 my $directive;
456 0 my @paths = ();
457 0 ▶ if (ref($namespace) # already a ref
Branch: 2 branches
BranchTrueFalseTotal
if (ref $namespace or $namespace =~ m[^\.{0,2}/.+$]) { } 0 0 0
elsif (index($namespace, "\n") != -1) { } 0 0 0
Condition0%0/3
ref $namespace or $namespace =~ m[^\.{0,2}/.+$]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $namespace or $namespace =~ m[^\.{0,2}/.+$]
ref $namespace $namespace =~ m[^\.{0,2}/.+$]
Truth table0%0/3
A or B
A= ref $namespaceB= $namespace =~ m[^\.{0,2}/.+$]
ABresult
1X1
011
000
458 || $namespace =~ m|^\.{0,2}/.+$| # absolute or relative file
459 ) {
460 0 push @paths, $namespace;
461 0 $directive = 'FIRST';
462  
463 } elsif (index($namespace,"\n") != -1) { # yaml string - can't write that
464 0 croak "Cannot use a yaml string as a namespace for write";
465  
466 ### use the default directories
467 } else {
468 0 ▶ $directive = uc($args->{directive} || $self->{directive} || $DIRECTIVE);
Condition0%0/6
$args->{'directive'} || $self->{'directive'} || $DIRECTIVE
l!l&&r!l&&!r
000
$args->{"directive"} or $self->{"directive"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args->{'directive'} || $self->{'directive'} || $DIRECTIVE
$args->{"directive"} $self->{"directive"} $DIRECTIVE
Truth table0%0/4
A or B || C
A= $args->{"directive"}B= $self->{"directive"}C= $DIRECTIVE
ABCresult
1XX1
01X1
0011
0000
469 0 $namespace =~ s|::|/|g; # allow perlish style namespace
470 0 ▶ my $paths = $args->{paths} || $self->paths
Condition0%0/6
$args->{'paths'} || $self->paths || croak("No paths found during write on $namespace")
l!l&&r!l&&!r
000
$args->{"paths"} or $self->paths
l!l&&r!l&&!r
000
MC/DC0%0/3
$args->{'paths'} || $self->paths || croak("No paths found during write on $namespace")
$args->{"paths"} $self->paths croak("No paths found during write on $namespace")
Truth table0%0/4
A or B || C
A= $args->{"paths"}B= $self->pathsC= croak("No paths found during write on $namespace")
ABCresult
1XX1
01X1
0011
0000
471 || croak "No paths found during write on $namespace";
472 0 ▶ $paths = [$paths] if ! ref $paths;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $paths 0 0 0
473 0 ▶ if ($directive eq 'LAST') { # LAST shall be FIRST
Branch: 1 branch
BranchTrueFalseTotal
if ($directive eq "LAST") 0 0 0
474 0 $directive = 'FIRST';
475 0 ▶ $paths = [reverse @$paths] if $#$paths != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $paths->$#* != 0 0 0 0
476 }
477 0 foreach my $path (@$paths) {
478 0 ▶ next if exists $CACHE{$path} && ! $CACHE{$path};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CACHE{$path} and not $CACHE{$path} 0 0 0
Condition0%0/3
exists $CACHE{$path} and not $CACHE{$path}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $CACHE{$path} and not $CACHE{$path}
exists $CACHE{$path} not $CACHE{$path}
Truth table0%0/3
A and not(B)
A= exists $CACHE{$path}B= not $CACHE{$path}
ABresult
0X0
100
111
479 0 push @paths, "$path/$namespace";
480 }
481 }
482  
483 ### make sure we have at least one path
484 0 ▶ if ($#paths == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#paths == -1) 0 0 0
485 0 croak "Couldn't find a path for namespace $namespace. Perhaps you need to pass paths => \@paths";
486 }
487  
488 0 my $path;
489 0 ▶ if ($directive eq 'FIRST') {
Branch: 2 branches
BranchTrueFalseTotal
if ($directive eq 'FIRST') { } 0 0 0
elsif ($directive eq 'LAST' or $directive eq 'MERGE') { } 0 0 0
490 0 $path = $paths[0];
491 ▶ } elsif ($directive eq 'LAST' || $directive eq 'MERGE') {
Condition0%0/3
$directive eq "LAST" or $directive eq "MERGE"
l!l&&r!l&&!r
000
MC/DC0%0/2
$directive eq "LAST" or $directive eq "MERGE"
$directive eq "LAST" $directive eq "MERGE"
Truth table0%0/3
A or B
A= $directive eq "LAST"B= $directive eq "MERGE"
ABresult
1X1
011
000
492 0 $path = $paths[-1];
493 } else {
494 0 croak "Unknown directive ($directive) during write of $namespace";
495 }
496  
497 ### remove immutable items (if any)
498 0 ▶ if (UNIVERSAL::isa($conf, 'HASH') && $conf->{"Immutable Keys"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($conf, "HASH") and $conf->{"Immutable Keys"}) 0 0 0
Condition0%0/3
UNIVERSAL::isa($conf, "HASH") and $conf->{"Immutable Keys"}
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($conf, "HASH") and $conf->{"Immutable Keys"}
UNIVERSAL::isa($conf, "HASH") $conf->{"Immutable Keys"}
Truth table0%0/3
A and B
A= UNIVERSAL::isa($conf, "HASH")B= $conf->{"Immutable Keys"}
ABresult
0X0
100
111
499 0 $conf = {%$conf}; # copy the values - only for immutable
500 0 my $IMMUTABLE = delete $conf->{"Immutable Keys"};
501 0 foreach my $key (keys %$IMMUTABLE) {
502 0 delete $conf->{$key};
503 }
504 }
505  
506 ### finally write it out
507 0 $self->write_ref($path, $conf);
508  
509 0 return 1;
510 }
511  
512 ###----------------------------------------------------------------###
513  
514 sub write_handler_ini {
515 0 ▶ my $file = shift;
Subroutine write_handler_ini: not called CC=1 SCAR=6.9
Pod undocumented
516 0 my $ref = shift;
517 0 require Config::IniHash;
518 0 return Config::IniHash::WriteINI($file, $ref);
519 }
520  
521 sub write_handler_pl {
522 1 ▶ my $file = shift;
Subroutine write_handler_pl: called CC=4 SCAR=14.0
Pod undocumented
523 1 my $ref = shift;
524 ### do has odd behavior in that it turns a simple hashref
525 ### into hash - help it out a little bit
526 1 require Data::Dumper;
527 1 local $Data::Dump::Purity = 1;
528 1 local $Data::Dumper::Sortkeys = 1;
529 1 local $Data::Dumper::Quotekeys = 0;
530 1 local $Data::Dumper::Pad = ' ';
531 1 local $Data::Dumper::Varname = 'VunderVar';
532 1 my $str = Data::Dumper->Dumpperl([$ref]);
533 1 ▶ if ($str =~ s/^(.+?=\s*)//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/^(.+?=\s*)//s) 1 0 1
534 1 my $l = length($1);
535 1 $str =~ s/^\s{1,$l}//mg;
536 }
537 1 ▶ if ($str =~ /\$VunderVar/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\$VunderVar/) 0 1 1
538 0 die "Ref to be written contained circular references - can't write";
539 }
540  
541 1 local *OUT;
542 1 ▶ open (OUT, ">$file") || die $!;
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">$file" or die $! 0 1 1
543 1 print OUT $str;
544 1 close OUT;
545 }
546  
547 sub write_handler_json {
548 0 ▶ my $file = shift;
Subroutine write_handler_json: not called CC=3 SCAR=24.8
Pod undocumented
549 0 my $ref = shift;
550 0 require JSON;
551 0 my $str;
552 0 ▶ if (JSON->can('encode')) {
Branch: 1 branch
BranchTrueFalseTotal
if ('JSON'->can('encode')) { } 0 0 0
553 0 my $j = JSON->new;
554 0 $j->canonical(1);
555 0 $j->pretty;
556 0 $str = $j->encode($ref);
557 } else {
558 0 $str = JSON->new->objToJson($ref, {pretty => 1, indent => 2});
559 }
560 0 local *OUT;
561 0 ▶ open (OUT, ">$file") || die $!;
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">$file" or die $! 0 0 0
562 0 print OUT $str;
563 0 close(OUT);
564 }
565  
566 sub write_handler_storable {
567 0 ▶ my $file = shift;
Subroutine write_handler_storable: not called CC=1 SCAR=6.9
Pod undocumented
568 0 my $ref = shift;
569 0 require Storable;
570 0 return Storable::store($ref, $file);
571 }
572  
573 sub write_handler_yaml {
574 0 ▶ my $file = shift;
Subroutine write_handler_yaml: not called CC=1 SCAR=6.9
Pod undocumented
575 0 my $ref = shift;
576 0 require YAML;
577 0 return YAML::DumpFile($file, $ref);
578 }
579  
580 sub write_handler_xml {
581 0 ▶ my $file = shift;
Subroutine write_handler_xml: not called CC=2 SCAR=17.9
Pod undocumented
582 0 my $ref = shift;
583 0 require XML::Simple;
584 0 local *OUT;
585 0 ▶ open (OUT, ">$file") || die $!;
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">$file" or die $! 0 0 0
586 0 print OUT scalar(XML::Simple->new->XMLout($ref, noattr => 1));
587 0 close(OUT);
588 }
589  
590 sub write_handler_html {
591 0 ▶ my $file = shift;
Subroutine write_handler_html: not called CC=1 SCAR=6.9
Pod undocumented
592 0 my $ref = shift;
593 0 die "Write of conf information to html is not supported";
594 }
595  
596 ###----------------------------------------------------------------###
597  
598 sub preload_files {
599 0 ▶ my $self = shift;
Subroutine preload_files: not called CC=15 SCAR=54.8
Pod documented
600 0 ▶ my $paths = shift || $self->paths;
Condition0%0/3
shift() || $self->paths
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->paths
shift() $self->paths
Truth table0%0/3
A || B
A= shift()B= $self->paths
ABresult
1X1
011
000
601  
602 ### what extensions do we look for
603 0 my %EXT;
604 0 ▶ if ($self->{'handler'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'handler'}) { } 0 0 0
605 0 ▶ if (UNIVERSAL::isa($self->{'handler'},'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($self->{"handler"}, "HASH")) 0 0 0
606 0 %EXT = %{ $self->{'handler'} };
607 }
608 } else {
609 0 %EXT = %EXT_READERS;
610 0 ▶ if (! $self->{'html_key'} && ! $HTML_KEY) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"html_key"} or $HTML_KEY) 0 0 0
Condition0%0/3
$self->{"html_key"} or $HTML_KEY
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"html_key"} or $HTML_KEY
$self->{"html_key"} $HTML_KEY
Truth table0%0/3
A or B
A= $self->{"html_key"}B= $HTML_KEY
ABresult
1X1
011
000
611 0 delete $EXT{$_} foreach qw(html htm);
612 }
613 }
614 0 ▶ return if ! keys %EXT;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %EXT 0 0 0
615  
616 ### look in the paths for the files
617 0 ▶ foreach my $path (ref($paths) ? @$paths : $paths) {
Branch: 1 branch
BranchTrueFalseTotal
ref $paths ? : 0 0 0
618 0 $path =~ s|//+|/|g;
619 0 $path =~ s|/$||;
620 0 ▶ next if exists $CACHE{$path};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CACHE{$path} 0 0 0
621 0 ▶ if (-f $path) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $path) { } 0 0 0
elsif (-d _) { } 0 0 0
622 0 ▶ my $ext = ($path =~ /\.(\w+)$/) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$path =~ /\.(\w+)$/ ? : 0 0 0
623 0 ▶ next if ! $EXT{$ext};
Branch: 1 branch
BranchTrueFalseTotal
unless $EXT{$ext} 0 0 0
624 0 $CACHE{$path} = $self->read($path);
625 } elsif (-d _) {
626 0 $CACHE{$path} = 1;
627 0 require File::Find;
628 File::Find::find(sub {
629 0 ▶ return if exists $CACHE{$File::Find::name};
Subroutine __ANON__: not called CC=6 SCAR=37.4
Branch: 1 branch
BranchTrueFalseTotal
if exists $CACHE{$File::Find::name} 0 0 0
630 0 ▶ return if $File::Find::name =~ m|/CVS/|;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::name =~ m[/CVS/] 0 0 0
631 0 ▶ return if ! -f;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_ 0 0 0
632 0 ▶ my $ext = (/\.(\w+)$/) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
/\.(\w+)$/ ? : 0 0 0
633 0 ▶ return if ! $EXT{$ext};
Branch: 1 branch
BranchTrueFalseTotal
unless $EXT{$ext} 0 0 0
634 0 $CACHE{$File::Find::name} = $self->read($File::Find::name);
635 0 }, "$path/");
636 } else {
637 0 $CACHE{$path} = 0;
638 }
639 }
640 }
641  
642 sub in_cache {
643 0 ▶ my ($self, $file) = (@_ == 2) ? @_ : (undef, shift());
Subroutine in_cache: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
644 0 ▶ return exists($CACHE{$file}) || 0;
Condition0%0/2
exists $CACHE{$file} || 0
l!l
00
MC/DC0%0/1
exists $CACHE{$file} || 0
exists $CACHE{$file}
Truth table0%0/2
A
A= exists $CACHE{$file}
Aresult
11
00
645 }
646  
647 ###----------------------------------------------------------------###
648  
649 3 1;
650  
651 __END__
« Ex/Dump.pm ↑ Summary Ex/Fill.pm »