blib/lib/HTML/Template/Pro.pm

filter: Statementstmt 73.7% 163 / 221 Branchbran 59.0% 65 / 110 Conditioncond 40.0% 12 / 30 MC/DCmcdc 10.0% 2 / 20 Subroutinesub 72.7% 24 / 33 Podpod 0.0% 0 / 9 totaltotal 62.8% 266 / 423 SCAR 55.1
CC
69
Cov
66%
_find_file
182.0
_get_filepath
20.0
new
18.9
CRAP 248.3
↑ Summary blib/lib/HTML/Template/Pro/WrapAssociate.pm »
1 package HTML::Template::Pro;
2  
3 14 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use integer; # no floating point math so far!
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use HTML::Template::Pro::WrapAssociate;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use File::Spec; # generate paths that work on all platforms
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Scalar::Util qw(tainted);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 require DynaLoader;
11 14 require Exporter;
12 14 ▶use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 @ISA = qw(DynaLoader Exporter);
14  
15 14 $VERSION = '0.9523';
16  
17 14 @EXPORT_OK = qw/ASK_NAME_DEFAULT ASK_NAME_AS_IS ASK_NAME_LOWERCASE ASK_NAME_UPPERCASE ASK_NAME_MASK/;
18 14 %EXPORT_TAGS = (const => [qw/ASK_NAME_DEFAULT ASK_NAME_AS_IS ASK_NAME_LOWERCASE ASK_NAME_UPPERCASE ASK_NAME_MASK/]);
19  
20 # constants for tmpl_var_case
21 use constant {
22 14 ASK_NAME_DEFAULT => 0,
23 ASK_NAME_AS_IS => 1,
24 ASK_NAME_LOWERCASE => 2,
25 ASK_NAME_UPPERCASE => 4,
26 14 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
27 14 ▶use constant ASK_NAME_MASK => ASK_NAME_AS_IS | ASK_NAME_LOWERCASE | ASK_NAME_UPPERCASE;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29  
30 14 bootstrap HTML::Template::Pro $VERSION;
31  
32 ## when HTML::Template is not loaded,
33 ## all calls to HTML::Template will be sent to HTML::Template::Pro,
34 ## otherwise native HTML::Template will be used
35 14 push @HTML::Template::ISA, qw/HTML::Template::Pro/;
36 14 push @HTML::Template::Expr::ISA, qw/HTML::Template::Pro/;
37  
38 # Preloaded methods go here.
39  
40 # internal C library init -- required
41 14 _init();
42 # internal C library unload -- it is better to comment it:
43 # when process terminates, memory is freed anyway
44 # but END {} can be called between calls (as SpeedyCGI does)
45 # END {_done()}
46  
47 # initialize preset function table
48 14 ▶use vars qw(%FUNC);
Subroutine BEGIN: called CC=1 SCAR=0.0
49 %FUNC =
50 (
51 # note that length,defined,sin,cos,log,tan,... are built-in
52 5 ▶ 'sprintf' => sub { sprintf(shift, @_); },
Subroutine __ANON__: called CC=1 SCAR=0.0
53 'substr' => sub {
54 5 ▶ return substr($_[0], $_[1]) if @_ == 2;
Subroutine __ANON__: called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 5 0 5
55 0 return substr($_[0], $_[1], $_[2]);
56 },
57 4 ▶ 'lc' => sub { lc($_[0]); },
Subroutine __ANON__: called CC=1 SCAR=0.0
58 0 ▶ 'lcfirst' => sub { lcfirst($_[0]); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 1 ▶ 'uc' => sub { uc($_[0]); },
Subroutine __ANON__: called CC=1 SCAR=0.0
60 11 ▶ 'ucfirst' => sub { ucfirst($_[0]); },
Subroutine __ANON__: called CC=1 SCAR=0.0
61 # 'length' => sub { length($_[0]); },
62 # 'defined' => sub { defined($_[0]); },
63 # 'abs' => sub { abs($_[0]); },
64 # 'hex' => sub { hex($_[0]); },
65 # 'oct' => sub { oct($_[0]); },
66 0 ▶ 'rand' => sub { rand($_[0]); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 ▶ 'srand' => sub { srand($_[0]); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 14 );
69  
70 sub new {
71 147 ▶ my $class=shift;
Subroutine new: called CC=16 SCAR=29.4
Pod undocumented
72 147 my %param;
73 147 my $options={param_map=>\%param,
74 functions => {},
75 filter => [],
76 # ---- supported -------
77 debug => 0,
78 max_includes => 10,
79 global_vars => 0,
80 no_includes => 0,
81 search_path_on_include => 0,
82 loop_context_vars => 0,
83 path => [],
84 associate => [],
85 case_sensitive => 0,
86 __strict_compatibility => 1,
87 force_untaint => 0,
88 # ---- unsupported distinct -------
89 die_on_bad_params => 0,
90 strict => 0,
91 # ---- unsupported -------
92 # vanguard_compatibility_mode => 0,
93 #=============================================
94 # The following options are harmless caching-specific.
95 # They are ignored silently because there is nothing to cache.
96 #=============================================
97 # stack_debug => 0,
98 # timing => 0,
99 # cache => 0,
100 # blind_cache => 0,
101 # file_cache => 0,
102 # file_cache_dir => '',
103 # file_cache_dir_mode => 0700,
104 # cache_debug => 0,
105 # shared_cache_debug => 0,
106 # memory_debug => 0,
107 # shared_cache => 0,
108 # double_cache => 0,
109 # double_file_cache => 0,
110 # ipc_key => 'TMPL',
111 # ipc_mode => 0666,
112 # ipc_segment_size => 65536,
113 # ipc_max_size => 0,
114 #============================================
115 @_};
116  
117 # make sure taint mode is on if force_untaint flag is set
118 147 ▶ if ($options->{force_untaint} && ! ${^TAINT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"force_untaint"} and not ${^TAINT}) 0 147 147
Condition33%1/3
$options->{"force_untaint"} and not ${^TAINT}
!ll&&!rl&&r
14700
MC/DC0%0/2
$options->{"force_untaint"} and not ${^TAINT}
$options->{"force_untaint"} not ${^TAINT}
Truth table33%1/3
A and not(B)
A= $options->{"force_untaint"}B= not ${^TAINT}
ABresult
0X0
100
111
119 0 croak("HTML::Template->new() : 'force_untaint' option set but perl does not run in taint mode!");
120 }
121  
122 # associate should be an array if it's not already
123 147 ▶ if (ref($options->{associate}) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $options->{"associate"} ne "ARRAY") 1 146 147
124 1 $options->{associate} = [ $options->{associate} ];
125 }
126 # path should be an array if it's not already
127 147 ▶ if (ref($options->{path}) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $options->{"path"} ne "ARRAY") 28 119 147
128 28 $options->{path} = [ $options->{path} ];
129 }
130 # filter should be an array if it's not already
131 147 ▶ if (ref($options->{filter}) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $options->{"filter"} ne "ARRAY") 4 143 147
132 4 $options->{filter} = [ $options->{filter} ];
133 }
134  
135 147 my $case_sensitive = $options->{case_sensitive};
136 147 my $__strict_compatibility = $options->{__strict_compatibility};
137 # wrap associated objects into tied hash and
138 # make sure objects in associate are support param()
139 $options->{associate} = [
140 1 map {HTML::Template::Pro::WrapAssociate->_wrap($_, $case_sensitive, $__strict_compatibility)}
141 147 @{$options->{associate}}
142 ];
143  
144 # check for syntax errors:
145 147 my $source_count = 0;
146 147 ▶ exists($options->{filename}) and $source_count++;
Branch: 1 branch
BranchTrueFalseTotal
exists $options->{"filename"} and ++$source_count 135 12 147
147 147 ▶ exists($options->{filehandle}) and $source_count++;
Branch: 1 branch
BranchTrueFalseTotal
exists $options->{"filehandle"} and ++$source_count 2 145 147
148 147 ▶ exists($options->{arrayref}) and $source_count++;
Branch: 1 branch
BranchTrueFalseTotal
exists $options->{"arrayref"} and ++$source_count 0 147 147
149 147 ▶ exists($options->{scalarref}) and $source_count++;
Branch: 1 branch
BranchTrueFalseTotal
exists $options->{"scalarref"} and ++$source_count 10 137 147
150 147 ▶ if ($source_count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source_count != 1) 0 147 147
151 0 croak("HTML::Template->new called with multiple (or no) template sources specified! A valid call to new() has exactly one filename => 'file' OR exactly one scalarref => \\\$scalar OR exactly one arrayref => \\\@array OR exactly one filehandle => \*FH");
152 }
153 147 ▶ if ($options->{arrayref}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"arrayref"}) 0 147 147
154 0 ▶ die "bad value of arrayref" unless UNIVERSAL::isa($_[0], 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($_[0], "ARRAY") 0 0 0
155 0 my $template=join('',@{$options->{arrayref}});
156 0 $options->{scalarref}=\$template;
157 }
158 147 ▶ if ($options->{filehandle}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"filehandle"}) 2 145 147
159 2 local $/; # enable "slurp" mode
160 2 local *FH=$options->{filehandle};
161 2 my $template=<FH>;
162 2 $options->{scalarref}=\$template;
163 }
164  
165 # merging built_in funcs with user-defined funcs
166 147 $options->{expr_func}={%FUNC, %{$options->{functions}}};
167  
168 # hack to be fully compatible with HTML::Template;
169 # caused serious memory leak. it should be done on XS level, if needed.
170 # &safe_circular_reference($options,'options') ???
171 #$options->{options}=$options;
172 147 bless $options,$class;
173 147 ▶ $options->_call_filters($options->{scalarref}) if $options->{scalarref} and @{$options->{filter}};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"scalarref"} and @{$options->{"filter"};} 0 147 147
Condition66%2/3
$options->{"scalarref"} and @{$options->{"filter"};}
!ll&&!rl&&r
135120
MC/DC0%0/2
$options->{"scalarref"} and @{$options->{"filter"};}
$options->{"scalarref"} @{$options->{"filter"};}
Truth table66%2/3
A and B
A= $options->{"scalarref"}B= @{$options->{"filter"};}
ABresult
0X0
100
111
174  
175 147 return $options; # == $self
176 }
177  
178 # a few shortcuts to new(), of possible use...
179 sub new_file {
180 0 ▶ my $pkg = shift; return $pkg->new('filename', @_);
Subroutine new_file: not called CC=1 SCAR=6.9
Pod undocumented
181 }
182 sub new_filehandle {
183 1 ▶ my $pkg = shift; return $pkg->new('filehandle', @_);
Subroutine new_filehandle: called CC=1 SCAR=0.0
Pod undocumented
184 }
185 sub new_array_ref {
186 0 ▶ my $pkg = shift; return $pkg->new('arrayref', @_);
Subroutine new_array_ref: not called CC=1 SCAR=6.9
Pod undocumented
187 }
188 sub new_scalar_ref {
189 0 ▶ my $pkg = shift; return $pkg->new('scalarref', @_);
Subroutine new_scalar_ref: not called CC=1 SCAR=6.9
Pod undocumented
190 }
191  
192 sub output {
193 448 ▶ my $self=shift;
Subroutine output: called CC=3 SCAR=11.0
Pod undocumented
194 448 my %oparam=(@_);
195 448 my $print_to = $oparam{print_to};
196  
197 448 ▶ if (defined wantarray && ! $print_to) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray and not $print_to) { } 377 71 448
Condition66%2/3
defined wantarray and not $print_to
!ll&&!rl&&r
710377
MC/DC50%1/2
defined wantarray and not $print_to
defined wantarray not $print_to
Truth table66%2/3
A and not(B)
A= defined wantarrayB= not $print_to
ABresult
0X0
100
111
198 377 return exec_tmpl_string($self);
199 } else {
200 71 exec_tmpl($self,$print_to);
201 }
202 }
203  
204 sub clear_params {
205 0 ▶ my $self = shift;
Subroutine clear_params: not called CC=1 SCAR=6.9
Pod undocumented
206 0 %{$self->{param_map}}=();
207 }
208  
209 sub param {
210 199 ▶ my $self = shift;
Subroutine param: called CC=12 SCAR=24.9
Pod undocumented
211 #my $options = $self->{options};
212 199 my $param_map = $self->{param_map};
213 # compatibility with HTML::Template
214 # the one-parameter case - could be a parameter value request or a
215 # hash-ref.
216 199 ▶ if (scalar @_==0) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 0) { } 3 196 199
elsif (scalar @_ == 1) { } 9 187 196
217 3 return keys (%$param_map);
218 } elsif (scalar @_==1) {
219 9 ▶ if (ref($_[0]) and UNIVERSAL::isa($_[0], 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] and UNIVERSAL::isa($_[0], 'HASH')) { } 1 8 9
Condition66%2/3
ref $_[0] and UNIVERSAL::isa($_[0], "HASH")
!ll&&!rl&&r
801
MC/DC50%1/2
ref $_[0] and UNIVERSAL::isa($_[0], "HASH")
ref $_[0] UNIVERSAL::isa($_[0], "HASH")
Truth table66%2/3
A and B
A= ref $_[0]B= UNIVERSAL::isa($_[0], "HASH")
ABresult
0X0
100
111
220 # ref to hash of params --- simply dereference it
221 1 return $self->param(%{$_[0]});
222 } else {
223 8 ▶ my $key=$self->{case_sensitive} ? $_[0] : lc($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'case_sensitive'} ? : 2 6 8
224 8 ▶ return $param_map->{$key} || $param_map->{$_[0]};
Condition33%1/3
$param_map->{$key} || $$param_map{$_[0]}
l!l&&r!l&&!r
800
MC/DC0%0/2
$param_map->{$key} || $$param_map{$_[0]}
$param_map->{$key} $$param_map{$_[0]}
Truth table33%1/3
A || B
A= $param_map->{$key}B= $$param_map{$_[0]}
ABresult
1X1
011
000
225 }
226 }
227 # loop below is obvious but wrong for perl
228 # while (@_) {$param_map->{shift(@_)}=shift(@_);}
229 187 ▶ if ($self->{case_sensitive}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'case_sensitive'}) { } 40 147 187
230 40 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 222 40 262
231 222 my $key=shift;
232 222 my $val=shift;
233 222 $param_map->{$key}=$val;
234 }
235 } else {
236 147 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 298 147 445
237 298 my $key=shift;
238 298 my $val=shift;
239 298 ▶ if (ref($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) { } 54 244 298
240 54 ▶ if (UNIVERSAL::isa($val, 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($val, 'ARRAY')) { } 48 6 54
241 48 $param_map->{lc($key)}=[map {_lowercase_keys($_)} @$val];
242 } else {
243 6 $param_map->{lc($key)}=$val;
244 }
245 } else {
246 244 $param_map->{lc($key)}=$val;
247 }
248 }
249 }
250 }
251  
252 sub register_function {
253 21 ▶ my($self, $name, $sub) = @_;
Subroutine register_function: called CC=6 SCAR=23.0
Pod undocumented
254 21 ▶ if ( ref($sub) eq 'CODE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $sub eq 'CODE') { } 20 1 21
elsif (defined $sub) { } 1 0 1
255 20 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 12 8 20
256 # per object call
257 12 $self->{expr_func}->{$name} = $sub;
258 12 $self->{expr_func_user_list}->{$name} = 1;
259 } else {
260 # per class call
261 8 $FUNC{$name} = $sub;
262 }
263 } elsif ( defined $sub ) {
264 1 croak("HTML::Template::Pro : last arg of register_function must be subroutine reference\n")
265 } else {
266 0 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
267 0 ▶ if ( defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 0 0 0
268 0 return $self->{expr_func}->{$name};
269 } else {
270 0 return keys %{ $self->{expr_func_user_list} };
271 }
272 } else {
273 0 return keys %FUNC;
274 }
275 }
276 }
277  
278 sub _lowercase_keys {
279 121 ▶ my $orighash=shift;
Subroutine _lowercase_keys: called CC=5 SCAR=16.7
280 121 my $newhash={};
281 121 my ($key,$val);
282 121 ▶ unless (UNIVERSAL::isa($orighash, 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($orighash, "HASH")) 0 121 121
283 0 Carp::carp "HTML::Template::Pro:_lowercase_keys:in param_tree: found strange parameter $orighash while hash was expected";
284 0 return;
285 }
286 121 ▶ while (($key,$val)=each %$orighash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$orighash) 209 121 330
287 209 ▶ if (ref($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) { } 8 201 209
288 8 ▶ if (UNIVERSAL::isa($val, 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($val, 'ARRAY')) { } 8 0 8
289 8 $newhash->{lc($key)}=[map {_lowercase_keys($_)} @$val];
290 } else {
291 0 $newhash->{lc($key)}=$val;
292 }
293 } else {
294 201 $newhash->{lc($key)}=$val;
295 }
296 }
297 121 return $newhash;
298 }
299  
300 # sub _load_file {
301 # my $filepath=shift;
302 # open my $fh, $filepath or die $!;
303 # local $/; # enable localized slurp mode
304 # my $content = <$fh>;
305 # close $fh;
306 # return $content;
307 # }
308  
309 ## HTML::Template based
310  
311 #### callback function called from C library ##############
312 # Note that this _get_filepath perl code is deprecated; ##
313 # by default built-in find_file implementation is used. ##
314 # use magic option __use_perl_find_file => 1 to re-enable it.
315 ###########################################################
316 sub _get_filepath {
317 0 ▶ my ($self, $filename, $last_visited_file) = @_;
Subroutine _get_filepath: not called CC=4 SCAR=30.0
318 # look for the included file...
319 0 my $filepath;
320 0 ▶ if ((not defined $last_visited_file) or $self->{search_path_on_include}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $last_visited_file or $self->{'search_path_on_include'}) { } 0 0 0
Condition0%0/3
not defined $last_visited_file or $self->{"search_path_on_include"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $last_visited_file or $self->{"search_path_on_include"}
not defined $last_visited_file $self->{"search_path_on_include"}
Truth table0%0/3
not(A) or B
A= not defined $last_visited_fileB= $self->{"search_path_on_include"}
ABresult
1X1
011
000
321 0 $filepath = $self->_find_file($filename);
322 } else {
323 0 $filepath = $self->_find_file($filename,
324 [File::Spec->splitdir($last_visited_file)]
325 );
326 }
327 0 ▶ carp "HTML::Template::Pro (using callback): template $filename not found!" unless $filepath;
Branch: 1 branch
BranchTrueFalseTotal
unless $filepath 0 0 0
328 0 return $filepath;
329 }
330  
331 sub _find_file {
332 0 ▶ my ($options, $filename, $extra_path) = @_;
Subroutine _find_file: not called CC=13 SCAR=52.0
333 0 my $filepath;
334  
335 # first check for a full path
336 0 ▶ return File::Spec->canonpath($filename)
Branch: 1 branch
BranchTrueFalseTotal
if "File::Spec"->file_name_is_absolute($filename) and -e $filename 0 0 0
Condition0%0/3
"File::Spec"->file_name_is_absolute($filename) and -e $filename
!ll&&!rl&&r
000
MC/DC0%0/2
"File::Spec"->file_name_is_absolute($filename) and -e $filename
"File::Spec"->file_name_is_absolute($filename) -e $filename
Truth table0%0/3
A and B
A= "File::Spec"->file_name_is_absolute($filename)B= -e $filename
ABresult
0X0
100
111
337 if (File::Spec->file_name_is_absolute($filename) and (-e $filename));
338  
339 # try the extra_path if one was specified
340 0 ▶ if (defined($extra_path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extra_path) 0 0 0
341 0 $extra_path->[$#{$extra_path}] = $filename;
342 0 $filepath = File::Spec->canonpath(File::Spec->catfile(@$extra_path));
343 0 ▶ return File::Spec->canonpath($filepath) if -e $filepath;
Branch: 1 branch
BranchTrueFalseTotal
if -e $filepath 0 0 0
344 }
345  
346 # try pre-prending HTML_Template_Root
347 0 ▶ if (defined($ENV{HTML_TEMPLATE_ROOT})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"HTML_TEMPLATE_ROOT"}) 0 0 0
348 0 $filepath = File::Spec->catfile($ENV{HTML_TEMPLATE_ROOT}, $filename);
349 0 ▶ return File::Spec->canonpath($filepath) if -e $filepath;
Branch: 1 branch
BranchTrueFalseTotal
if -e $filepath 0 0 0
350 }
351  
352 # try "path" option list..
353 0 foreach my $path (@{$options->{path}}) {
354 0 $filepath = File::Spec->catfile($path, $filename);
355 0 ▶ return File::Spec->canonpath($filepath) if -e $filepath;
Branch: 1 branch
BranchTrueFalseTotal
if -e $filepath 0 0 0
356 }
357  
358 # try even a relative path from the current directory...
359 0 ▶ return File::Spec->canonpath($filename) if -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
if -e $filename 0 0 0
360  
361 # try "path" option list with HTML_TEMPLATE_ROOT prepended...
362 0 ▶ if (defined($ENV{HTML_TEMPLATE_ROOT})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"HTML_TEMPLATE_ROOT"}) 0 0 0
363 0 foreach my $path (@{$options->{path}}) {
364 0 $filepath = File::Spec->catfile($ENV{HTML_TEMPLATE_ROOT}, $path, $filename);
365 0 ▶ return File::Spec->canonpath($filepath) if -e $filepath;
Branch: 1 branch
BranchTrueFalseTotal
if -e $filepath 0 0 0
366 }
367 }
368
369 0 return undef;
370 }
371  
372 sub _load_template {
373 9 ▶ my $self = shift;
Subroutine _load_template: called CC=4 SCAR=14.0
374 9 my $filepath=shift;
375 9 my $template = "";
376 9 ▶ confess("HTML::Template->new() : Cannot open file $filepath : $!")
Branch: 1 branch
BranchTrueFalseTotal
unless defined open(TEMPLATE, $filepath) 0 9 9
377 unless defined(open(TEMPLATE, $filepath));
378 # read into scalar
379 9 ▶ while (read(TEMPLATE, $template, 10240, length($template))) {}
Branch: 1 branch
BranchTrueFalseTotal
if (read TEMPLATE, $template, 10240, length $template) 9 9 18
380 9 close(TEMPLATE);
381 9 ▶ $self->_call_filters(\$template) if @{$self->{filter}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"filter"};} 9 0 9
382 9 return \$template;
383 }
384  
385 # handle calling user defined filters
386 sub _call_filters {
387 9 ▶ my $self = shift;
Subroutine _call_filters: called CC=13 SCAR=27.4
388 9 my $template_ref = shift;
389 9 my $options = $self;#->{options};
390  
391 9 my ($format, $sub);
392 9 foreach my $filter (@{$options->{filter}}) {
393 11 ▶ croak("HTML::Template->new() : bad value set for filter parameter - must be a code ref or a hash ref.")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $filter 0 11 11
394 unless ref $filter;
395  
396 # translate into CODE->HASH
397 11 ▶ $filter = { 'format' => 'scalar', 'sub' => $filter }
Branch: 1 branch
BranchTrueFalseTotal
if ref $filter eq "CODE" 2 9 11
398 if (ref $filter eq 'CODE');
399  
400 11 ▶ if (ref $filter eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $filter eq 'HASH') { } 11 0 11
401 11 $format = $filter->{'format'};
402 11 $sub = $filter->{'sub'};
403  
404 # check types and values
405 11 ▶ croak("HTML::Template->new() : bad value set for filter parameter - hash must contain \"format\" key and \"sub\" key.")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $format and defined $sub 0 11 11
Condition33%1/3
defined $format and defined $sub
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $format and defined $sub
defined $format defined $sub
Truth table33%1/3
A and B
A= defined $formatB= defined $sub
ABresult
0X0
100
111
406 unless defined $format and defined $sub;
407 11 ▶ croak("HTML::Template->new() : bad value set for filter parameter - \"format\" must be either 'array' or 'scalar'")
Branch: 1 branch
BranchTrueFalseTotal
unless $format eq "array" or $format eq "scalar" 0 11 11
Condition66%2/3
$format eq "array" or $format eq "scalar"
l!l&&r!l&&!r
380
MC/DC0%0/2
$format eq "array" or $format eq "scalar"
$format eq "array" $format eq "scalar"
Truth table66%2/3
A or B
A= $format eq "array"B= $format eq "scalar"
ABresult
1X1
011
000
408 unless $format eq 'array' or $format eq 'scalar';
409 11 ▶ croak("HTML::Template->new() : bad value set for filter parameter - \"sub\" must be a code ref")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sub and ref $sub eq "CODE" 0 11 11
Condition33%1/3
ref $sub and ref $sub eq "CODE"
!ll&&!rl&&r
0011
MC/DC0%0/2
ref $sub and ref $sub eq "CODE"
ref $sub ref $sub eq "CODE"
Truth table33%1/3
A and B
A= ref $subB= ref $sub eq "CODE"
ABresult
0X0
100
111
410 unless ref $sub and ref $sub eq 'CODE';
411  
412 # catch errors
413 11 eval {
414 11 ▶ if ($format eq 'scalar') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq 'scalar') { } 8 3 11
415 # call
416 8 $sub->($template_ref);
417 } else {
418 # modulate
419 3 my @array = map { $_."\n" } split("\n", $$template_ref);
420 # call
421 3 $sub->(\@array);
422 # demodulate
423 3 $$template_ref = join("", @array);
424 }
425 };
426 11 ▶ croak("HTML::Template->new() : fatal error occured during filter call: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 11 11
427 } else {
428 0 croak("HTML::Template->new() : bad value set for filter parameter - must be code ref or hash ref");
429 }
430 }
431 # all done
432 9 return $template_ref;
433 }
434  
435 14 1;
436 __END__
↑ Summary blib/lib/HTML/Template/Pro/WrapAssociate.pm »