Template/Magic/Zone.pm

filter: Statementstmt 98.0% 98 / 100 Branchbran 92.5% 50 / 54 Conditioncond 80.0% 8 / 10 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 95.0% 19 / 20 Podpod 100% 7 / 7 totaltotal 93.9% 185 / 197 CC 36 SCAR 16.5
CC
36
Cov
95%
content_process
9.0
value_process
7.0
lookup
7.0
CRAP 5.2
« Template/Magic.pm ↑ Summary Bundle/Template/Magic.pm »
1 package Template::Magic::Zone ;
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 31 ; our $AUTOLOAD
10 31 ; $Carp::Internal{+__PACKAGE__}++
11  
12 ; BEGIN
13 31 ▶ { *OK = sub () { 1 }
Subroutine BEGIN: called CC=1 SCAR=0.0
14 31 }
15  
16 ; BEGIN
17 31 ▶ { foreach my $n (qw| zone output text post |)
Subroutine BEGIN: called CC=2 SCAR=6.9
18 31 ▶ { no strict 'refs'
Subroutine BEGIN: called CC=1 SCAR=0.0
19 31 ; *{$n.'_process'} = sub
20 677 ▶ { my ($z) = @_
Subroutine __ANON__: called CC=4 SCAR=13.9
21 677 ▶ ; my $ch = $z->tm->{$n.'_handlers'} || return
Condition100%2/2
$z->tm->{$n . '_handlers'} || (return)
l!l
396281
MC/DC100%1/1
$z->tm->{$n . '_handlers'} || (return)
$z->tm->{$n . '_handlers'}
Truth table100%2/2
A
A= $z->tm->{$n . '_handlers'}
Aresult
11
00
22 ; HANDLER:
23 396 foreach my $h ( @$ch )
24 396 ▶ { return OK if $h->(@_)
Branch: 1 branch
BranchTrueFalseTotal
if &$h(@_) 12 384 396
25 }
26 }
27 124 }
28 0 ▶ ; *mt = sub{shift()->tm(@_)} # backward compatibility
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 31 }
30
31 ; use Class::constr
32 31 ▶; use Object::props
Subroutine BEGIN: called CC=1 SCAR=0.0
33 31 ▶ ( { name => [ qw| id
Subroutine BEGIN: called CC=1 SCAR=0.0
34 attributes
35 is_main
36 _t
37 container
38 output
39 |
40 ]
41 , protected => 1
42 }
43 , { name => 'level'
44 , protected => 1
45 , default => -1
46 }
47 , qw| param
48 location
49 value
50 _s
51 _e
52 |
53 )
54  
55 31 ; sub value_process
56 198 ▶ { my ($z) = @_
Subroutine value_process: called CC=7 SCAR=19.5
Pod documented
57 198 ; my $tm = $z->tm
58 198 ; my $v = $z->value
59 198 ▶ ; if ( defined $v && length $v )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and length $v) { } 183 15 198
Condition100%3/3
defined $v and length $v
!ll&&!rl&&r
132183
MC/DC100%2/2
defined $v and length $v
defined $v length $v
Truth table100%3/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
60 183 { delete $$tm{_NOT_lookup}{'NOT_'.$z->id}
61 }
62 else
63 15 { $$tm{_NOT_lookup}{'NOT_'.$z->id} = {}
64 15 ▶ ; return unless defined($v)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 13 2 15
65 }
66 ; my $ch = $$tm{value_handlers} || return
67 185 ▶ ; HANDLER:
Condition50%1/2
$tm->{'value_handlers'} || (return)
l!l
1850
MC/DC0%0/1
$tm->{'value_handlers'} || (return)
$tm->{'value_handlers'}
Truth table50%1/2
A
A= $tm->{'value_handlers'}
Aresult
11
00
68 185 foreach my $h ( @$ch )
69 450 ▶ { return OK if &$h(@_)
Branch: 1 branch
BranchTrueFalseTotal
if &$h(@_) 184 266 450
70 }
71 }
72
73 207 ▶; sub AUTOLOAD : lvalue
Subroutine AUTOLOAD: called CC=3 SCAR=15.4
74 207 { (my $n = $AUTOLOAD) =~ s/.*://
75 207 ▶ ; return if $n eq 'DESTROY'
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "DESTROY" 207 0 207
76 ; @_ == 2
77 ? ( $_[0]{__CUSTOM}{$n} = $_[1] )
78 0 ▶ : $_[0]{__CUSTOM}{$n}
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
79 }
80  
81 ; sub tm
82 965 ▶ { my ($az) = my ($z) = @_ ;
Subroutine tm: called CC=2 SCAR=6.9
Pod documented
83 965 ▶ ; until (defined $$az{tm}){ $az = $az->container }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $az->{"tm"}) 1382 965 2347
84 ; $$az{tm}
85 965 }
86
87 ; sub content_process
88 108 ▶ { my ($z) = @_
Subroutine content_process: called CC=9 SCAR=22.0
Pod documented
89 108 ▶ ; defined $z->_e || return # content or return
Branch: 1 branch
BranchTrueFalseTotal
defined $z->_e or return 104 4 108
90 ; ZONE:
91 104 ▶ for ( my $i = $z->_s
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $z->_e) 420 104 524
92 ; $i <= $z->_e
93 ; $i++
94 )
95 420 { my $item = $z->_t->[$i][1]
96 420 ▶ ; if ( not $item ) # just text
Branch: 4 branches
BranchTrueFalseTotal
if (not $item) { } 257 163 420
elsif (ref $item eq 'HASH') { } 156 7 163
elsif ($item eq 'CONTAINER_INCLUDE') { } 4 3 7
elsif ($item->is_main) { } 3 0 3
97 257 { $z->text_process( $z->_t->[$i][0] )
98 }
99 elsif ( ref $item eq 'HASH' ) # normal zone
100 156 { my $nz = ref($z)->new( %$item
101 , level => $z->level + 1
102 , container => $z
103 , _t => $z->_t
104 )
105 156 ▶ ; $i = $nz->_e + 1 if $nz->_e # skip block content
Branch: 1 branch
BranchTrueFalseTotal
if $nz->_e 60 96 156
106 156 ▶ ; next ZONE if $nz->zone_process
Branch: 1 branch
BranchTrueFalseTotal
if $nz->zone_process 12 144 156
107 144 ; $nz->lookup_process
108 144 ; $nz->value_process
109 144 ; $nz->post_process
110 }
111 elsif ( $item eq 'CONTAINER_INCLUDE' )
112 { $z->include_template($z->tm->{_included_template})
113 4 }
114 elsif ( $item->is_main ) # included file
115 3 { $z->_include($item)
116 }
117 }
118 }
119
120 ; sub _include
121 8 ▶ { my ($z, $iz) = @_
Subroutine _include: called CC=1 SCAR=0.0
122 8 ; @$iz{qw|container level tm|} = ( $z
123 , $z->level
124 , $z->tm
125 )
126 8 ; $iz->content_process
127 8 ; delete @$iz{qw|container level tm|} # reset
128 }
129
130 ; sub lookup_process
131 149 ▶ { my ($z) = @_
Subroutine lookup_process: called CC=2 SCAR=6.9
Pod documented
132 149 ▶ ; defined $z->value and return
Branch: 1 branch
BranchTrueFalseTotal
defined $z->value and return 2 147 149
133 147 ; $z->value($z->lookup)
134 }
135  
136 ; sub lookup
137 150 ▶ { my ( $z, $id ) = @_
Subroutine lookup: called CC=7 SCAR=19.5
Pod documented
138 150 ▶ ; $id ||= $z->id
Condition66%2/3
$id ||= $z->id
l!l&&r!l&&!r
31470
MC/DC0%0/2
$id ||= $z->id
$id $z->id
Truth table66%2/3
A ||= B
A= $idB= $z->id
ABresult
1X1
011
000
139 150 ; my $val
140 150 ▶ ; for ( my $az = $z->container
Branch: 1 branch
BranchTrueFalseTotal
if ($az->container) 108 73 181
141 ; $az->container
142 ; $az = $az->container
143 )
144 108 { $val = $z->_lookup( $az->value, $id )
145 108 ▶ ; return $val if defined $val
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 77 31 108
146 }
147 73 ; my $tm = $z->tm
148 73 ; foreach my $l ( @{$$tm{_temp_lookups}}
149 73 , @{$$tm{lookups}}
150 , $$tm{_NOT_lookup}
151 )
152 87 ▶ { next unless $l
Branch: 1 branch
BranchTrueFalseTotal
unless $l 2 85 87
153 85 ; $val = $z->_lookup( $l, $id )
154 85 ▶ ; return $val if defined $val
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 62 23 85
155 }
156 ; undef
157 11 }
158
159 ; sub _lookup
160 193 ▶ { my ($z, $l, $id) = @_
Subroutine _lookup: called CC=7 SCAR=19.5
161 193 ▶ ; return unless $l
Branch: 1 branch
BranchTrueFalseTotal
unless $l 6 187 193
162 187 ; $z->location = $l
163 187 ▶ ; if ( ref $l eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $l eq 'HASH') { } 125 62 187
elsif (my $code = UNIVERSAL::can($l, $id)) { } 15 47 62
164 125 { $$l{$id}
165 }
166 elsif ( my $code = UNIVERSAL::can( $l, $id ) )
167 15 { $code
168 }
169 else
170 31 ▶ { no strict 'refs','vars'
Subroutine BEGIN: called CC=1 SCAR=0.0
171 31 ; local *S = $l.'::'.$id
172 47 ▶ ; defined $S ? $S
Branch: 3 branches
BranchTrueFalseTotal
defined $S ? : 30 17 47
@S ? : 3 14 17
%S ? : 1 13 14
173 : @S ? \@S
174 : %S ? \%S
175 : undef
176 }
177 }
178
179 ; sub content
180 11 ▶ { my ($z) = @_
Subroutine content: called CC=2 SCAR=6.9
Pod documented
181 11 ▶ ; defined $z->_e || return
Branch: 1 branch
BranchTrueFalseTotal
defined $z->_e or return 7 4 11
182 23 ; join '' , map { $$_[0]
183 }
184 7 @{$z->_t} [ $z->_s
185 ..
186 $z->_e
187 ]
188 }
189  
190 ; sub include_template
191 5 ▶ { my ($z, $t) = @_
Subroutine include_template: called CC=1 SCAR=0.0
Pod documented
192 5 ; my $nz = $z->tm->load($t)
193 5 ; $z->_include($nz)
194 ; return undef
195 5 }
196  
197 31 ; 1
198  
199 __END__
« Template/Magic.pm ↑ Summary Bundle/Template/Magic.pm »