Template/Magic.pm

filter: Statementstmt 92.8% 274 / 295 Branchbran 76.7% 89 / 116 Conditioncond 61.2% 60 / 98 MC/DCmcdc 30.1% 16 / 53 Subroutinesub 91.1% 62 / 68 Podpod 67.8% 19 / 28 totaltotal 79.0% 520 / 658 CC 99 SCAR 19.5
CC
99
Cov
83%
new
24.5
find_file
14.0
_parse
13.0
CRAP 7.0
↑ Summary Template/Magic/Zone.pm »
1 package Template::Magic ;
2 31 $VERSION = 1.40 ;
3 31 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 ▶use 5.006_001 ;
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 31 ▶; $Carp::Internal{+__PACKAGE__}++
Subroutine BEGIN: called CC=1 SCAR=0.0
11 ; use warnings::register
12 31 ▶; use Template::Magic::Zone
Subroutine BEGIN: called CC=1 SCAR=0.0
13 31 ▶; use IO::Util
Subroutine BEGIN: called CC=1 SCAR=0.0
14 31 ▶; use Class::Util
Subroutine BEGIN: called CC=1 SCAR=0.0
15 31 ▶; use File::Spec
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 31 ▶; sub NEXT_HANDLER () { 0 }
Subroutine BEGIN: called CC=1 SCAR=0.0
18 ; sub LAST_HANDLER () { 1 }
19  
20 ; sub import
21 34 ▶ { my ($pkg, $pragma) = @_
Subroutine import: called CC=4 SCAR=15.5
22 34 ▶ ; if ( $pragma
Branch: 1 branch
BranchTrueFalseTotal
if ($pragma and $pragma eq '-compile') { } 0 34 34
Condition66%2/3
$pragma and $pragma eq "-compile"
!ll&&!rl&&r
3310
MC/DC0%0/2
$pragma and $pragma eq "-compile"
$pragma $pragma eq "-compile"
Truth table66%2/3
A and B
A= $pragmaB= $pragma eq "-compile"
ABresult
0X0
100
111
23 && $pragma eq '-compile'
24 )
25 0 ▶ { carp "The -compile pragma has no effect since version 1.39"
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
26 if warnings::enabled
27 }
28 else
29 { require Exporter
30 34 ; our @ISA = 'Exporter'
31 34 ; our @EXPORT_OK = qw| NEXT_HANDLER
32 LAST_HANDLER
33 |
34 34 ; $pkg->export_to_level(1, @_)
35 }
36 }
37  
38 ; sub new
39 37 ▶ { my ($c) = shift
Subroutine new: called CC=18 SCAR=32.0
Pod documented
40 37 ; my ($s) = @_
41 37 ▶ ; $s = { @_ } # passing hash backward compatibility
Branch: 1 branch
BranchTrueFalseTotal
unless ref $s eq "HASH" 37 0 37
42 unless ref $s eq 'HASH'
43 37 ; foreach ( keys %$s ) # passing -flag backward compatibility
44 20 ▶ { $$s{$_} = delete $$s{-$_}
Branch: 1 branch
BranchTrueFalseTotal
if s/^-// 0 20 20
45 if s/^-//
46 }
47 37 ; foreach ( values %$s ) # each value should be an ARRAY ref
48 20 ▶ { $_ = [ $_ ]
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "ARRAY" 15 5 20
49 unless ref eq 'ARRAY'
50 }
51 37 ; bless $s, $c
52 37 ▶ ; $$s{markers} ||= $s->DEFAULT_MARKERS
Condition66%2/3
$s->{"markers"} ||= $s->DEFAULT_MARKERS
l!l&&r!l&&!r
5320
MC/DC0%0/2
$s->{"markers"} ||= $s->DEFAULT_MARKERS
$s->{"markers"} $s->DEFAULT_MARKERS
Truth table66%2/3
A ||= B
A= $s->{"markers"}B= $s->DEFAULT_MARKERS
ABresult
1X1
011
000
53 37 ▶ ; $$s{output_handlers} ||= $s->DEFAULT_PRINT_HANDLERS
Condition33%1/3
$s->{"output_handlers"} ||= $s->DEFAULT_PRINT_HANDLERS
l!l&&r!l&&!r
0370
MC/DC0%0/2
$s->{"output_handlers"} ||= $s->DEFAULT_PRINT_HANDLERS
$s->{"output_handlers"} $s->DEFAULT_PRINT_HANDLERS
Truth table33%1/3
A ||= B
A= $s->{"output_handlers"}B= $s->DEFAULT_PRINT_HANDLERS
ABresult
1X1
011
000
54 ; $$s{text_handlers} ||= $s->DEFAULT_TEXT_HANDLERS
55 || $$s{output_handlers}
56 37 ▶ ; $$s{zone_handlers} ||= $s->DEFAULT_ZONE_HANDLERS
Condition44%4/9
$s->{"text_handlers"} ||= $s->DEFAULT_TEXT_HANDLERS || $s->{"output_handlers"}
l!l&&r!l&&!r
0370
$s->DEFAULT_TEXT_HANDLERS || $s->{'output_handlers'}
l!l&&r!l&&!r
0370
$s->{"zone_handlers"} ||= $s->DEFAULT_ZONE_HANDLERS
l!l&&r!l&&!r
5032
MC/DC0%0/3
$s->{"text_handlers"} ||= $s->DEFAULT_TEXT_HANDLERS || $s->{"output_handlers"}
$s->{"text_handlers"} $s->DEFAULT_TEXT_HANDLERS $s->{'output_handlers'}
MC/DC50%1/2
$s->{"zone_handlers"} ||= $s->DEFAULT_ZONE_HANDLERS
$s->{"zone_handlers"} $s->DEFAULT_ZONE_HANDLERS
Truth table0%0/4
A ||= B || C
A= $s->{"text_handlers"}B= $s->DEFAULT_TEXT_HANDLERSC= $s->{'output_handlers'}
ABCresult
1XX1
01X1
0011
0000
Truth table66%2/3
A ||= B
A= $s->{"zone_handlers"}B= $s->DEFAULT_ZONE_HANDLERS
ABresult
1X1
011
000
57 37 ▶ ; $$s{value_handlers} ||= $s->DEFAULT_VALUE_HANDLERS
Condition66%2/3
$s->{"value_handlers"} ||= $s->DEFAULT_VALUE_HANDLERS
l!l&&r!l&&!r
4330
MC/DC0%0/2
$s->{"value_handlers"} ||= $s->DEFAULT_VALUE_HANDLERS
$s->{"value_handlers"} $s->DEFAULT_VALUE_HANDLERS
Truth table66%2/3
A ||= B
A= $s->{"value_handlers"}B= $s->DEFAULT_VALUE_HANDLERS
ABresult
1X1
011
000
58 37 ▶ ; $$s{post_handlers} ||= $s->DEFAULT_POST_HANDLERS
Condition33%1/3
$s->{"post_handlers"} ||= $s->DEFAULT_POST_HANDLERS
l!l&&r!l&&!r
0037
MC/DC0%0/2
$s->{"post_handlers"} ||= $s->DEFAULT_POST_HANDLERS
$s->{"post_handlers"} $s->DEFAULT_POST_HANDLERS
Truth table33%1/3
A ||= B
A= $s->{"post_handlers"}B= $s->DEFAULT_POST_HANDLERS
ABresult
1X1
011
000
59 37 ▶ ; $$s{lookups} ||= [ (caller)[0] ]
Condition100%2/2
$s->{"lookups"} ||= [(caller)[0]]
l!l
532
MC/DC100%1/1
$s->{"lookups"} ||= [(caller)[0]]
$s->{"lookups"}
Truth table100%2/2
A
A= $s->{"lookups"}
Aresult
11
00
60 37 ▶ ; $$s{options} ||= $s->DEFAULT_OPTIONS
Condition33%1/3
$s->{"options"} ||= $s->DEFAULT_OPTIONS
l!l&&r!l&&!r
0370
MC/DC0%0/2
$s->{"options"} ||= $s->DEFAULT_OPTIONS
$s->{"options"} $s->DEFAULT_OPTIONS
Truth table33%1/3
A ||= B
A= $s->{"options"}B= $s->DEFAULT_OPTIONS
ABresult
1X1
011
000
61 37 ; $$s{options} = { map { /^(no_)*(.+)$/
62 37 ▶ ; $2 => $1 ? 0 : 1
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 37 37
63 }
64 37 @{$$s{options}}
65 }
66 37 ; foreach my $n (qw| zone value text output post |)
67 { $$s{$n.'_handlers'}
68 185 ▶ &&= [ $s->_Hload( $$s{$n.'_handlers'}
Condition100%2/2
$$s{$n . '_handlers'} &&= [$s->_Hload($$s{$n . '_handlers'}, $n)]
!ll
69116
MC/DC100%1/1
$$s{$n . '_handlers'} &&= [$s->_Hload($$s{$n . '_handlers'}, $n)]
$$s{$n . '_handlers'}
Truth table100%2/2
A
A= $$s{$n . '_handlers'}
Aresult
00
11
69 , $n
70 )
71 ]
72 }
73 37 ; $s
74 }
75  
76 ; sub _Hload
77 117 ▶ { my ($s, $arr, $n) = @_
Subroutine _Hload: called CC=7 SCAR=20.2
78 ; map
79 117 ▶ { if ( ref eq 'CODE' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ eq 'CODE') { } 286 18 304
elsif (not ref $_) { } 18 0 18
80 286 { $_
81 }
82 elsif ( not ref )
83 18 ▶ { my $C = $s->can($_)
Condition40%2/5
$s->can($_) || $s->can(join('_', $_, uc $n, 'HANDLERS')) || croak(qq[Unknown handler "$_"])
l!l
180
$s->can($_) or $s->can(join("_", $_, uc $n, "HANDLERS"))
l!l&&r!l&&!r
1800
MC/DC0%0/2
$s->can($_) || $s->can(join('_', $_, uc $n, 'HANDLERS')) || croak(qq[Unknown handler "$_"])
$s->can($_) $s->can(join("_", $_, uc $n, "HANDLERS"))
Truth table33%1/3
A or B
A= $s->can($_)B= $s->can(join("_", $_, uc $n, "HANDLERS"))
ABresult
1X1
011
000
84 || $s->can( join ( '_'
85 , $_
86 , uc $n
87 , 'HANDLERS'
88 )
89 )
90 || croak qq(Unknown handler "$_")
91 18 ; my $ref = $s->$C
92 18 ▶ ; if ( ref $ref eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref eq 'ARRAY') { } 1 17 18
elsif (ref $ref eq 'CODE') { } 17 0 17
93 1 { $s->_Hload( $ref, $n )
94 }
95 elsif ( ref $ref eq 'CODE' )
96 17 { $ref
97 }
98 }
99 }
100 @$arr
101 }
102  
103 ; sub _re
104 56 ▶ { my ($s) = @_
Subroutine _re: called CC=6 SCAR=18.0
105 56 ▶ ; unless ( $$s{_re} ) # execute it just the first time AND if it has to parse
Branch: 1 branch
BranchTrueFalseTotal
unless ($s->{"_re"}) 36 20 56
106 36 ▶ { unless ( @{$$s{markers}} == 3 )
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$s->{"markers"};} == 3) 4 32 36
107 31 ▶ { no strict 'refs'
Subroutine BEGIN: called CC=1 SCAR=0.0
108 31 ; my $m = $$s{markers}[0]
109 4 ▶ ; my $M = $s->can($m)
Condition60%3/5
$s->can($m) || $s->can($m . '_MARKERS') || croak(qq[Unknown markers "$m"])
l!l
40
$s->can($m) or $s->can($m . '_MARKERS')
l!l&&r!l&&!r
130
MC/DC0%0/2
$s->can($m) || $s->can($m . '_MARKERS') || croak(qq[Unknown markers "$m"])
$s->can($m) $s->can($m . '_MARKERS')
Truth table66%2/3
A or B
A= $s->can($m)B= $s->can($m . '_MARKERS')
ABresult
1X1
011
000
110 || $s->can($m.'_MARKERS') # backward compatibility
111 || croak qq(Unknown markers "$m")
112 4 ; $$s{markers} = $s->$M
113 }
114 180 ; $$s{markers} = [ map { qr/$_/s
115 }
116 36 ( @{$$s{markers}}
117 36 , '(?:(?!' .$$s{markers}[2]. ').)*'
118 , '\w+'
119 )
120 ]
121 36 ; my ($S, $I, $E, $A, $ID) = @{$$s{markers}}
122 36 ; $$s{_re}{label} = qr/$S$I*$ID$A$E/s
123 36 ; $$s{_re}{start_label} = qr/$S($ID)($A)$E/s
124 36 ; $$s{_re}{end_label} = qr/$S$I($ID)$E/s
125 36 ; $$s{_re}{include_label} = qr/$S\bINCLUDE_TEMPLATE\b($A)$E/s
126 }
127  
128 ; wantarray
129 0 ? @{$$s{markers}}
130 : $$s{_re}
131 56 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 56 56
132
133 ; sub find_file
134 9 ▶ { my ($s, $t) = @_
Subroutine find_file: called CC=7 SCAR=26.4
Pod documented
135 18 ▶ ; my $find = sub{(grep -s, @_)[0]}
Subroutine __ANON__: called CC=1 SCAR=0.0
136 9 ; File::Spec->file_name_is_absolute($t)
137 ? $find->($t)
138 : ( $ENV{TEMPLATE_MAGIC_ROOT}
139 && $find->( File::Spec->catfile( $ENV{TEMPLATE_MAGIC_ROOT}
140 , $t
141 )
142 )
143 || $find->( map File::Spec->catfile( $_
144 , $t
145 )
146 9 ▶ , @{$$s{paths}}
Condition33%1/3
$ENV{"TEMPLATE_MAGIC_ROOT"} and &$find(map("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $_, $t), @{$$s{"paths"};}))
!ll&&!rl&&r
900
MC/DC0%0/2
$ENV{"TEMPLATE_MAGIC_ROOT"} and &$find(map("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $_, $t), @{$$s{"paths"};}))
$ENV{"TEMPLATE_MAGIC_ROOT"} &$find(map("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $_, $t), @{$$s{"paths"};}))
Truth table33%1/3
A and B
A= $ENV{"TEMPLATE_MAGIC_ROOT"}B= &$find(map("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $_, $t), @{$$s{"paths"};}))
ABresult
0X0
100
111
147 )
148 || $ENV{TEMPLATE_MAGIC_ROOT}
149 && $find->( map File::Spec->catfile( $ENV{TEMPLATE_MAGIC_ROOT}
150 , $_
151 , $t
152 )
153 0 ▶ , @{$$s{paths}}
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($t) ? : 0 9 9
Condition33%4/12
$ENV{"TEMPLATE_MAGIC_ROOT"} and &$find("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $t)) or &$find(map("File::Spec"->catfile($_, $t), @{$$s{"paths"};})) or $ENV{"TEMPLATE_MAGIC_ROOT"} and &$find(map("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $_, $t), @{$$s{"paths"};})) or &$find($t)
l!l&&r!l&&!r
090
$ENV{"TEMPLATE_MAGIC_ROOT"} and &$find("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $t)) or &$find(map("File::Spec"->catfile($_, $t), @{$$s{"paths"};})) or $ENV{"TEMPLATE_MAGIC_ROOT"} and &$find(map("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $_, $t), @{$$s{"paths"};}))
l!l&&r!l&&!r
009
$ENV{"TEMPLATE_MAGIC_ROOT"} and &$find("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $t)) or &$find(map("File::Spec"->catfile($_, $t), @{$$s{"paths"};}))
l!l&&r!l&&!r
009
$ENV{"TEMPLATE_MAGIC_ROOT"} and &$find("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $t))
!ll&&!rl&&r
900
MC/DC0%0/5
$ENV{"TEMPLATE_MAGIC_ROOT"} and &$find("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $t)) or &$find(map("File::Spec"->catfile($_, $t), @{$$s{"paths"};})) or $ENV{"TEMPLATE_MAGIC_ROOT"} and &$find(map("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $_, $t), @{$$s{"paths"};})) or &$find($t)
$ENV{"TEMPLATE_MAGIC_ROOT"} &$find("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $t)) &$find(map("File::Spec"->catfile($_, $t), @{$$s{"paths"};})) $ENV{"TEMPLATE_MAGIC_ROOT"} and &$find(map("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $_, $t), @{$$s{"paths"};})) &$find($t)
Truth table0%0/9
A and B or C or D or E
A= $ENV{"TEMPLATE_MAGIC_ROOT"}B= &$find("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $t))C= &$find(map("File::Spec"->catfile($_, $t), @{$$s{"paths"};}))D= $ENV{"TEMPLATE_MAGIC_ROOT"} and &$find(map("File::Spec"->catfile($ENV{"TEMPLATE_MAGIC_ROOT"}, $_, $t), @{$$s{"paths"};}))E= &$find($t)
ABCDEresult
11XXX1
0X1XX1
101XX1
0X01X1
1001X1
0X0011
100011
0X0000
100000
154 )
155 || $find->($t)
156 )
157 }
158
159 ; sub output
160 46 ▶ { my $s = shift
Subroutine output: called CC=2 SCAR=6.9
Pod documented
161 46 ; my $args
162 ; $$args{template} = shift
163 46 ▶ ; $$args{lookups} = [ @_ ] if @_
Branch: 1 branch
BranchTrueFalseTotal
if @_ 6 40 46
164 46 ▶ ; IO::Util::capture { $s->_process( $args ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
165 46 }
166  
167 ; sub print
168 0 ▶ { my $s = shift
Subroutine print: not called CC=2 SCAR=17.9
Pod documented
169 0 ; my $args
170 ; $$args{template} = shift
171 0 ▶ ; $$args{lookups} = [ @_ ] if @_
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
172 0 ; $s->_process( $args )
173 }
174  
175 ; sub noutput
176 1 ▶ { my ($s, %args) = @_
Subroutine noutput: called CC=2 SCAR=7.0
Pod documented
177 ; $args{lookups} = [ $args{lookups} ]
178 1 ▶ unless ref $args{lookups} eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"lookups"} eq "ARRAY" 1 0 1
179 1 ▶ ; IO::Util::capture { $s->_process( \%args ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
180 1 }
181  
182 ; sub nprint
183 0 ▶ { my ($s, %args) = @_
Subroutine nprint: not called CC=2 SCAR=17.9
Pod documented
184 ; $args{lookups} = [ $args{lookups} ]
185 0 ▶ unless ref $args{lookups} eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"lookups"} eq "ARRAY" 0 0 0
186 0 ; $s->_process( \%args )
187 }
188  
189 ; sub _process
190 47 ▶ { my ($s, $args) = @_
Subroutine _process: called CC=4 SCAR=13.9
191 ; $$s{_temp_lookups} = $$args{lookups} if exists $$args{lookups}
192 47 ▶ ; my $t
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"lookups"} 7 40 47
193 47 ▶ ; if ( $t = $$args{container_template}
Branch: 1 branch
BranchTrueFalseTotal
if ($t = $args->{'container_template'} || do { $$s{'container_template'} }->[0]) { } 4 43 47
Condition100%3/3
$args->{'container_template'} || do { $$s{'container_template'} }->[0]
l!l&&r!l&&!r
1343
MC/DC100%2/2
$args->{'container_template'} || do { $$s{'container_template'} }->[0]
$args->{'container_template'} do { $$s{'container_template'} }->[0]
Truth table100%3/3
A || B
A= $args->{'container_template'}B= do { $$s{'container_template'} }->[0]
ABresult
1X1
011
000
194 46 || ${$$s{container_template}}[0]
195 )
196 { $$s{_included_template} = $$args{template}
197 4 }
198 else
199 { $t = $$args{template}
200 43 }
201 47 ; my $z = $s->load( $t )
202 47 ; $$z{tm} = $s
203 47 ; $z->content_process
204 ; delete $$z{tm} # to avoid tm object caching
205 47 ; delete @$s{qw|_included_template _temp_lookups _NOT_lookup|}
206 }
207  
208 ; sub load
209 55 ▶ { my ($s, $t) = @_
Subroutine load: called CC=8 SCAR=21.1
Pod documented
210 55 ; my $main_zone
211 55 ▶ ; if ( not ref $t )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $t) 9 46 55
212 9 ▶ { $t = $s->find_file($t)
Branch: 1 branch
BranchTrueFalseTotal
$t = $s->find_file($t) or croak(qq[Template file "$t" empty or not found]) 9 0 9
213 or croak qq(Template file "$t" empty or not found)
214 9 ▶ ; if ( $$s{options}{cache} )
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"options"}{"cache"}) 9 0 9
215 9 { $main_zone = IO::Util::_get_parsing_cache('magic_zone', $t)
216 9 ▶ ; return $main_zone if $main_zone
Branch: 1 branch
BranchTrueFalseTotal
if $main_zone 0 9 9
217 }
218 }
219 55 ▶ ; my $content = ref $t eq 'SCALAR' ? $t : IO::Util::slurp $t
Branch: 1 branch
BranchTrueFalseTotal
ref $t eq 'SCALAR' ? : 45 10 55
220 55 ; $main_zone = $s->_parse( $content )
221 55 ▶ ; $$s{options}{cache} &&! ref($t) # set cache
Branch: 1 branch
BranchTrueFalseTotal
$s->{"options"}{"cache"} and not ref $t and IO::Util::_set_parsing_cache("magic_zone", $t, $main_zone) 9 46 55
Condition66%2/3
$s->{"options"}{"cache"} and not ref $t
!ll&&!rl&&r
0469
MC/DC50%1/2
$s->{"options"}{"cache"} and not ref $t
$s->{"options"}{"cache"} not ref $t
Truth table66%2/3
A and not(B)
A= $s->{"options"}{"cache"}B= not ref $t
ABresult
0X0
100
111
222 && IO::Util::_set_parsing_cache 'magic_zone', $t, $main_zone
223 55 ; $main_zone
224 }
225  
226 ; sub purge_cache
227 0 ▶ { $_[0] = 'magic_zone'
Subroutine purge_cache: not called CC=1 SCAR=6.9
Pod documented
228 0 ; goto &IO::Util::_purge_parsing_cache
229 }
230  
231 ; sub _parse
232 55 ▶ { my ($s, $content_ref) = @_
Subroutine _parse: called CC=13 SCAR=25.7
233 55 ; my $re = $s->_re
234 ; my @temp
235 55 = map { [ $_
236 413 , do { /$$re{end_label}/ && $1
237 413 ▶ || /$$re{include_label}/ && do{ (my $t = $1) =~ s/^\s+//
Condition91%11/12
/$re->{'end_label'}/s && $1 || /$re->{'include_label'}/s && do { (my $t = $1) =~ s/^\s+//; $t ? $s->load($t) : 'CONTAINER_INCLUDE' } || /$re->{'start_label'}/s && {'id', $1, 'attributes', $2}
l!l&&r!l&&!r
64120229
/$re->{"end_label"}/s and $1 or /$re->{"include_label"}/s and do { (my $t = $1) =~ s/^\s+//; $t ? $s->load($t) : "CONTAINER_INCLUDE" }
l!l&&r!l&&!r
574352
/$re->{"end_label"}/s and $1
!ll&&!rl&&r
356057
/$re->{"include_label"}/s and do { (my $t = $1) =~ s/^\s+//; $t ? $s->load($t) : "CONTAINER_INCLUDE" }
!ll&&!rl&&r
34934
MC/DC60%3/5
/$re->{'end_label'}/s && $1 || /$re->{'include_label'}/s && do { (my $t = $1) =~ s/^\s+//; $t ? $s->load($t) : 'CONTAINER_INCLUDE' } || /$re->{'start_label'}/s && {'id', $1, 'attributes', $2}
/$re->{"end_label"}/s $1 /$re->{"include_label"}/s do { (my $t = $1) =~ s/^\s+//; $t ? $s->load($t) : "CONTAINER_INCLUDE" } /$re->{'start_label'}/s && {'id', $1, 'attributes', $2}
Truth table36%4/11
A and B or C and D || E
A= /$re->{"end_label"}/sB= $1C= /$re->{"include_label"}/sD= do { (my $t = $1) =~ s/^\s+//; $t ? $s->load($t) : "CONTAINER_INCLUDE" }E= /$re->{'start_label'}/s && {'id', $1, 'attributes', $2}
ABCDEresult
11XXX1
0X11X1
1011X1
0X0X11
0X1011
100X11
101011
0X0X00
0X1000
100X00
101000
238 7 ▶ ; $t
Branch: 1 branch
BranchTrueFalseTotal
$t ? : 3 4 7
Condition100%2/2
/$re->{"start_label"}/s and {"id", $1, "attributes", $2}
!ll
229120
MC/DC100%1/1
/$re->{"start_label"}/s and {"id", $1, "attributes", $2}
/$re->{"start_label"}/s
Truth table100%2/2
A
A= /$re->{"start_label"}/s
Aresult
00
11
239 ? $s->load($t)
240 : 'CONTAINER_INCLUDE'
241 }
242 || /$$re{start_label}/ && { id => $1
243 , attributes => $2
244 }
245 }
246 ]
247 }
248 split /($$re{label})/ , $$content_ref
249
250 55 ▶ ; for ( my $i = $#temp # find end
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 413 55 468
251 ; $i >= 0
252 ; $i --
253 )
254 413 { my $id = $temp[$i][1]
255 413 ▶ ; next if ( ref $id or not $id )
Branch: 1 branch
BranchTrueFalseTotal
if ref $id or not $id 352 61 413
Condition100%3/3
ref $id or not $id
l!l&&r!l&&!r
12322961
MC/DC100%2/2
ref $id or not $id
ref $id not $id
Truth table100%3/3
A or not(B)
A= ref $idB= not $id
ABresult
1X1
011
000
256 61 ▶ ; for ( ( my $ii = $i-1 # find THE start
Branch: 1 branch
BranchTrueFalseTotal
if ($ii >= 0) 260 4 264
257 , my $l = 0
258 )
259 ; $ii >= 0 # condition
260 ; ( $ii --
261 , $l ++
262 )
263 )
264 260 { my $the_start = $temp[$ii][1]
265 260 ▶ ; next unless ref($the_start) eq 'HASH' # next if not start
Branch: 1 branch
BranchTrueFalseTotal
unless ref $the_start eq "HASH" 142 118 260
266 118 ▶ ; next unless $$the_start{id} eq $id # next if not THE start
Branch: 1 branch
BranchTrueFalseTotal
unless $the_start->{"id"} eq $id 61 57 118
267 57 ; $$the_start{_s} = $ii + 1
268 57 ; $$the_start{_e} = $ii + $l
269 ; last
270 57 }
271 }
272 # allows to set protected props from outside class
273 55 ; local $Class::props::force = 1
274 55 ; Template::Magic::Zone->new( _s => 0
275 , _e => $#temp
276 , _t => \@temp
277 , is_main => 1
278 )
279 }
280
281  
282 ############################# STANDARD HANDLERS #############################
283  
284 # override these DEFAULT subs in subclasses to change defaults
285  
286 ; sub DEFAULT_ZONE_HANDLERS
287 32 ▶ {
Subroutine DEFAULT_ZONE_HANDLERS: called CC=1 SCAR=0.0
Pod undocumented
288 }
289
290 ; sub DEFAULT_POST_HANDLERS
291 37 ▶ {
Subroutine DEFAULT_POST_HANDLERS: called CC=1 SCAR=0.0
Pod undocumented
292 }
293
294 ; sub DEFAULT_TEXT_HANDLERS
295 37 ▶ {
Subroutine DEFAULT_TEXT_HANDLERS: called CC=1 SCAR=0.0
Pod undocumented
296 }
297  
298 ; sub DEFAULT_VALUE_HANDLERS
299 31 ▶ { my ($s, @args) = @_
Subroutine DEFAULT_VALUE_HANDLERS: called CC=1 SCAR=0.0
Pod undocumented
300 31 ; [ $s->SCALAR
301 , $s->REF
302 , $s->CODE(@args)
303 , $s->ARRAY
304 , $s->HASH
305 , $s->OBJECT
306 ]
307 }
308  
309 ; sub DEFAULT_PRINT_HANDLERS
310 37 ▶ { [ sub
Subroutine DEFAULT_PRINT_HANDLERS: called CC=1 SCAR=0.1
Pod undocumented
311 368 ▶ { print "$_[1]" if defined $_[1]
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 368 0 368
312 368 ; NEXT_HANDLER
313 }
314 37 ]
315 }
316
317 31 ▶; { no warnings 'once'
Subroutine BEGIN: called CC=1 SCAR=0.0
318 31 ; *DEFAULT_OUTPUT_HANDLERS = \&DEFAULT_PRINT_HANDLER # deprecated
319 }
320
321 ; sub DEFAULT_OPTIONS
322 37 ▶ { [ qw| cache | ]
Subroutine DEFAULT_OPTIONS: called CC=1 SCAR=0.0
Pod undocumented
323 }
324
325 ; sub DEFAULT_MARKERS
326 29 ▶ { [ qw| { / } | ]
Subroutine DEFAULT_MARKERS: called CC=1 SCAR=0.0
Pod documented
327 }
328
329 ; sub HTML_MARKERS
330 7 ▶ { [ qw| <!--{ / }--> | ]
Subroutine HTML_MARKERS: called CC=1 SCAR=0.0
Pod documented
331 }
332  
333 ; sub CODE_MARKERS
334 0 ▶ { [ qw| <- / -> | ]
Subroutine CODE_MARKERS: not called CC=1 SCAR=6.9
Pod documented
335 }
336  
337 ; sub HTML_VALUE_HANDLERS # value handler
338 3 ▶ { my ($s, @args) = @_
Subroutine HTML_VALUE_HANDLERS: called CC=1 SCAR=0.0
Pod undocumented
339 3 ; [ $s->SCALAR
340 , $s->REF
341 , $s->CODE(@args)
342 , $s->TableTiler
343 , $s->ARRAY
344 , $s->HASH
345 , $s->FillInForm
346 , $s->OBJECT
347 ]
348 }
349
350 ; sub SCALAR # value handler
351 37 ▶ { sub
Subroutine SCALAR: called CC=1 SCAR=0.0
352 184 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=2 SCAR=6.9
353 184 ; my $v = $z->value
354 184 ▶ ; if ( not ref $v ) # if it's a plain string
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $v) 109 75 184
355 109 { $z->output($v) # set output
356 109 ; $z->output_process( $v ) # process output (requires string)
357 109 ; LAST_HANDLER
358 }
359 }
360 37 }
361  
362 ; sub REF # value handler
363 37 ▶ { sub
Subroutine REF: called CC=1 SCAR=0.8
Pod documented
364 75 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=2 SCAR=9.2
365 75 ; my $v = $z->value
366 75 ▶ ; if (ref($v) =~ /^(SCALAR|REF)$/) # if it's a reference
Branch: 1 branch
BranchTrueFalseTotal
if (ref($v) =~ /^(SCALAR|REF)$/) 0 75 75
367 0 { $z->value($$v) # dereference
368 0 ; $z->value_process # process the new value
369 0 ; LAST_HANDLER
370 }
371 }
372 37 }
373
374 ; sub ARRAY # value handler
375 36 ▶ { sub
Subroutine ARRAY: called CC=1 SCAR=0.0
Pod documented
376 57 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=6 SCAR=17.9
377 57 ▶ ; if (ref $z->value eq 'ARRAY') # if it's an ARRAY
Branch: 1 branch
BranchTrueFalseTotal
if (ref $z->value eq "ARRAY") 9 48 57
378 9 { my ($i, $attr, $val_key, $ix_key, $named) = 0
379 9 ▶ ; if ( $attr = $z->attributes )
Branch: 1 branch
BranchTrueFalseTotal
if ($attr = $z->attributes) 3 6 9
380 3 { $attr =~ s/^\s*(OF\s)*\s*//i
381 3 ; ($val_key, $ix_key, $i) = split /\s+/, $attr
382 3 ; $named = 1
383 }
384 9 ; foreach my $item ( @{$z->value} ) # for each value in the array
385 26 ▶ { $z->value( $named # set the value for the zone
Branch: 2 branches
BranchTrueFalseTotal
$named ? : 12 14 26
$ix_key ? : 8 4 12
386 ? { $val_key => $item
387 , $ix_key ? ($ix_key => $i ++) : ()
388 }
389 : $item
390 )
391 26 ; $z->value_process # process it
392 }
393 9 ; LAST_HANDLER
394 }
395 }
396 36 }
397
398 ; sub HASH # value handler
399 36 ▶ { sub
Subroutine HASH: called CC=1 SCAR=0.0
Pod documented
400 48 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=2 SCAR=6.9
401 48 ▶ ; if (ref $z->value eq 'HASH') # if it's a HASH
Branch: 1 branch
BranchTrueFalseTotal
if (ref $z->value eq "HASH") 43 5 48
402 43 { $z->content_process # start again the process
403 43 ; LAST_HANDLER
404 }
405 }
406 36 }
407
408 ; sub CODE # value handler
409 35 ▶ { my ( undef, @args ) = @_
Subroutine CODE: called CC=1 SCAR=0.0
Pod documented
410 ; sub
411 74 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=6 SCAR=18.0
412 74 ; my $v = $z->value
413 74 ▶ ; if ( ref $v eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "CODE") 16 58 74
414 16 { my $l = $z->location
415 ; my $nv = Class::Util::blessed($l)
416 31 ▶ ? do { no strict 'refs'
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
Class::Util::blessed($l) ? : 5 11 16
417 31 ▶ ; $l->$v( ${ref($l).'::no_template_magic_zone'}
Branch: 1 branch
BranchTrueFalseTotal
${ref($l) . '::no_template_magic_zone';} ? : 0 5 5
418 ? ()
419 : $z
420 , @args
421 )
422 }
423 : $v->( $z , @args )
424 16 ▶ ; if ( $v ne ($nv||'') ) # avoid infinite loop
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne ($nv || "")) 16 0 16
Condition100%2/2
$nv || ''
l!l
133
MC/DC100%1/1
$nv || ''
$nv
Truth table100%2/2
A
A= $nv
Aresult
11
00
425 16 { $z->value($nv)
426 16 ; $z->value_process
427 }
428 16 ; LAST_HANDLER
429 }
430 }
431 35 }
432  
433 ; sub OBJECT
434 34 ▶ { sub
Subroutine OBJECT: called CC=1 SCAR=0.0
Pod documented
435 2 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=2 SCAR=7.0
436 2 ▶ ; if ( Class::Util::blessed($z->value) )
Branch: 1 branch
BranchTrueFalseTotal
if (Class::Util::blessed($z->value)) 2 0 2
437 2 { $z->content_process # process content
438 2 ; LAST_HANDLER
439 }
440 }
441 34 }
442
443 ; sub ID_list
444 1 ▶ { my ($s, $indent, $end) = @_
Subroutine ID_list: called CC=3 SCAR=11.1
Pod documented
445 1 ▶ ; $indent ||= ' ' x 4
Condition50%1/2
$indent ||= " "
l!l
10
MC/DC0%0/1
$indent ||= " "
$indent
Truth table50%1/2
A
A= $indent
Aresult
11
00
446 1 ▶ ; $end ||= '/'
Condition50%1/2
$end ||= "/"
l!l
01
MC/DC0%0/1
$end ||= "/"
$end
Truth table50%1/2
A
A= $end
Aresult
11
00
447 1 ; my $re = $s->_re
448 1 ▶ ; $$s{text_handlers} = [ sub{} ] # does not print any text
Subroutine __ANON__: called CC=1 SCAR=0.0
449 ; $$s{zone_handlers}
450 = [ sub # takes control of the whole process
451 6 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=3 SCAR=11.0
452 6 ; $z->output_process( $indent x $z->level
453 . $z->id
454 . ":\n"
455 )
456 6 ; $z->content_process
457 6 ; my $cont = $z->content
458 6 ▶ ; if ( $z->_e # if it is a block
Branch: 1 branch
BranchTrueFalseTotal
if ($z->_e and $cont =~ /$re->{"label"}/) 2 4 6
Condition66%2/3
$z->_e and $cont =~ /$re->{"label"}/
!ll&&!rl&&r
402
MC/DC50%1/2
$z->_e and $cont =~ /$re->{"label"}/
$z->_e $cont =~ /$re->{"label"}/
Truth table66%2/3
A and B
A= $z->_eB= $cont =~ /$re->{"label"}/
ABresult
0X0
100
111
459 && $cont =~ /$$re{label}/ # and contains labels
460 )
461 2 { $z->output_process( $indent x $z->level # print the end
462 . $end
463 . $z->id
464 . ":\n"
465 )
466 }
467 6 ; LAST_HANDLER
468 }
469 1 ]
470 }
471
472 # START AutoLoaded handlers
473  
474 # 'sub' must be at start of line to be found by AutoSplit
475 # no fancy coding here :-(
476  
477 sub _EVAL_ # zone handler
478 1 ▶ { sub
Subroutine _EVAL_: called CC=1 SCAR=0.0
479 2 ▶ { my ($z) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
480 2 ▶ ; if ( $z->id eq '_EVAL_' )
Branch: 1 branch
BranchTrueFalseTotal
if ($z->id eq "_EVAL_") 1 1 2
481 1 { $z->value( eval $z->content )
482 }
483 2 ; NEXT_HANDLER
484 # lookup is skipped by the defined $z->value
485 # value_process is entered by default
486 }
487 1 }
488  
489 sub _EVAL_ATTRIBUTES_ # zone handler
490 1 ▶ { sub
Subroutine _EVAL_ATTRIBUTES_: called CC=1 SCAR=0.0
491 2 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=2 SCAR=6.9
492 2 ▶ ; if ( $z->attributes )
Branch: 1 branch
BranchTrueFalseTotal
if ($z->attributes) 1 1 2
493 1 { $z->param( eval $z->attributes )
494 }
495 2 ; NEXT_HANDLER
496 # $z->attributes should be a ref to a structure
497 }
498 1 }
499  
500 sub TRACE_DELETIONS # zone handler
501 1 ▶ { sub
Subroutine TRACE_DELETIONS: called CC=1 SCAR=0.0
Pod documented
502 5 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=4 SCAR=13.9
503 # do lookup and value processes as usual
504 5 ; $z->lookup_process
505 5 ; $z->value_process
506 # if they fail to find a true output trace the deletion
507 5 ▶ ; if ( not defined $z->output )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $z->output) { } 2 3 5
elsif (not $z->output) { } 1 2 3
508 2 ▶ { $z->output_process ( '<<' . $z->id . ' not found>>' )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $z->value eq "HASH" 1 1 2
509 unless ref $z->value eq 'HASH'
510 }
511 elsif ( not $z->output )
512 1 { $z->output_process ( '<<' . $z->id . ' found but empty>>' )
513 }
514 5 ; LAST_HANDLER
515 }
516 1 }
517  
518 sub INCLUDE_TEXT # zone handler
519 1 ▶ { sub
Subroutine INCLUDE_TEXT: called CC=1 SCAR=0.0
Pod documented
520 2 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=4 SCAR=13.9
521 2 ▶ ; if ( $z->id eq 'INCLUDE_TEXT' )
Branch: 1 branch
BranchTrueFalseTotal
if ($z->id eq "INCLUDE_TEXT") 1 1 2
522 1 { my $file = $z->attributes
523 1 ▶ ; open my $itxt, $file
Branch: 1 branch
BranchTrueFalseTotal
open my $itxt, $file or croak(qq[Error opening text file "$file": $^E]) 1 0 1
524 or croak qq(Error opening text file "$file": $^E)
525 1 ▶ ; $z->text_process($_) while <$itxt>
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $itxt) and do { $z->text_process($_) } 1 1 2
526 1 ; close $itxt
527 1 ; LAST_HANDLER
528 }
529 }
530 1 }
531  
532 ############### HTML HANDLERS ##############
533  
534 sub TableTiler # value handler
535 4 ▶ { eval
Subroutine TableTiler: called CC=2 SCAR=7.1
Pod undocumented
536 4 { local $SIG{__DIE__}
537 4 ; require HTML::TableTiler
538 4 ; return $HTML::TableTiler::VERSION >= 1.14
539 }
540 4 ▶ ; if ( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 4 4
541 0 { carp qq("HTML::TableTiler" is not installed on this system or it is not current\n)
542 0 ▶ ; return sub {} # no action
Subroutine __ANON__: not called CC=1 SCAR=0.0
543 0 }
544 else
545 { sub # normal handler
546 6 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=4 SCAR=14.0
547 6 ; my $v = $z->value
548 6 ▶ ; if ( ref($v) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "ARRAY" and HTML::TableTiler::is_matrix($v)) 2 4 6
Condition66%2/3
ref $v eq "ARRAY" and HTML::TableTiler::is_matrix($v)
!ll&&!rl&&r
402
MC/DC50%1/2
ref $v eq "ARRAY" and HTML::TableTiler::is_matrix($v)
ref $v eq "ARRAY" HTML::TableTiler::is_matrix($v)
Truth table66%2/3
A and B
A= ref $v eq "ARRAY"B= HTML::TableTiler::is_matrix($v)
ABresult
0X0
100
111
549 && HTML::TableTiler::is_matrix($v) # if matrix
550 )
551 { $z->value
552 2 ( do { my $cont = $z->content
553 2 ▶ ; HTML::TableTiler::tile_table( $v
Condition50%1/2
$cont && \$cont
!ll
02
MC/DC0%0/1
$cont && \$cont
$cont
Truth table50%1/2
A
A= $cont
Aresult
00
11
554 , $cont && \$cont
555 , $z->attributes
556 , 1
557 )
558 }
559 )
560 2 ; $z->value_process
561 2 ; LAST_HANDLER
562 }
563 }
564 4 }
565 }
566  
567 sub FillInForm # value handler
568 4 ▶ { eval
Subroutine FillInForm: called CC=2 SCAR=7.1
Pod undocumented
569 4 { local $SIG{__DIE__}
570 4 ; require HTML::FillInForm
571 4 }
572 4 ▶ ; if ( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 4 4
573 0 { carp qq("HTML::FillInForm" is not installed on this system\n)
574 0 ▶ ; sub {}
Subroutine __ANON__: not called CC=1 SCAR=0.0
575 0 }
576 else
577 { sub
578 2 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=4 SCAR=14.0
579 2 ; my $v = $z->value
580 2 ▶ ; if ( ref($v)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v and defined UNIVERSAL::can($v, "param")) 2 0 2
Condition33%1/3
ref $v and defined UNIVERSAL::can($v, "param")
!ll&&!rl&&r
002
MC/DC0%0/2
ref $v and defined UNIVERSAL::can($v, "param")
ref $v defined UNIVERSAL::can($v, "param")
Truth table33%1/3
A and B
A= ref $vB= defined UNIVERSAL::can($v, "param")
ABresult
0X0
100
111
581 && defined UNIVERSAL::can( $v , 'param' )
582 )
583 2 ▶ { my $cont = IO::Util::capture { $z->content_process }
Subroutine __ANON__: called CC=1 SCAR=0.0
584 2 ; my $attr = $z->attributes
585 2 ; my ($list) = $attr =~ /ignore_fields\s*=>\s*\[(.*)\]/
586 2 ▶ ; my @if = map /(?:'|")(.+)(?:'|")/ #'
Condition100%2/2
$list || ''
l!l
11
MC/DC100%1/1
$list || ''
$list
Truth table100%2/2
A
A= $list
Aresult
11
00
587 , split /\s*,\s*/
588 , $list||''
589 2 ; $z->value( HTML::FillInForm
590 ->new
591 ->fill( scalarref => $cont
592 , fobject => $v
593 , ignore_fields => \@if
594 )
595 )
596 2 ; $z->value_process
597 2 ; LAST_HANDLER
598 }
599 }
600 4 }
601 }
602
603 __END__
↑ Summary Template/Magic/Zone.pm »