line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Magic::Zone ; |
2
|
|
|
|
|
|
|
$VERSION = 1.40 ; |
3
|
31
|
|
|
31
|
|
174
|
use strict ; |
|
31
|
|
|
|
|
63
|
|
|
31
|
|
|
|
|
1094
|
|
4
|
31
|
|
|
31
|
|
557
|
use 5.006_001 ; |
|
31
|
|
|
|
|
106
|
|
|
31
|
|
|
|
|
3482
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# This file uses the "Perlish" coding style |
7
|
|
|
|
|
|
|
# please read http://perl.4pro.net/perlish_coding_style.html |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
; our $AUTOLOAD |
10
|
|
|
|
|
|
|
; $Carp::Internal{+__PACKAGE__}++ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
; BEGIN |
13
|
|
|
|
|
|
|
{ *OK = sub () { 1 } |
14
|
31
|
|
|
31
|
|
1238
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
; BEGIN |
17
|
31
|
|
|
31
|
|
87
|
{ foreach my $n (qw| zone output text post |) |
18
|
31
|
|
|
|
|
5352
|
{ no strict 'refs' |
19
|
31
|
|
|
31
|
|
187
|
; *{$n.'_process'} = sub |
|
31
|
|
|
|
|
192
|
|
|
124
|
|
|
|
|
837
|
|
20
|
677
|
|
|
677
|
|
8632
|
{ my ($z) = @_ |
21
|
677
|
|
100
|
|
|
1328
|
; my $ch = $z->tm->{$n.'_handlers'} || return |
22
|
|
|
|
|
|
|
; HANDLER: |
23
|
396
|
|
|
|
|
760
|
foreach my $h ( @$ch ) |
24
|
396
|
100
|
|
|
|
1055
|
{ return OK if $h->(@_) |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
124
|
|
|
|
|
656
|
} |
28
|
0
|
|
|
0
|
|
0
|
; *mt = sub{shift()->tm(@_)} # backward compatibility |
29
|
31
|
|
|
|
|
829
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
; use Class::constr |
32
|
31
|
|
|
31
|
|
31245
|
; use Object::props |
|
31
|
|
|
|
|
24503
|
|
|
31
|
|
|
|
|
182
|
|
33
|
31
|
|
|
|
|
482
|
( { name => [ qw| id |
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
|
|
|
31
|
|
32399
|
; sub value_process |
|
31
|
|
|
|
|
97444
|
|
56
|
198
|
|
|
198
|
1
|
366
|
{ my ($z) = @_ |
57
|
198
|
|
|
|
|
375
|
; my $tm = $z->tm |
58
|
198
|
|
|
|
|
635
|
; my $v = $z->value |
59
|
198
|
100
|
100
|
|
|
2569
|
; if ( defined $v && length $v ) |
60
|
183
|
|
|
|
|
584
|
{ delete $$tm{_NOT_lookup}{'NOT_'.$z->id} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else |
63
|
15
|
|
|
|
|
64
|
{ $$tm{_NOT_lookup}{'NOT_'.$z->id} = {} |
64
|
15
|
100
|
|
|
|
515
|
; return unless defined($v) |
65
|
|
|
|
|
|
|
} |
66
|
185
|
|
50
|
|
|
4537
|
; my $ch = $$tm{value_handlers} || return |
67
|
|
|
|
|
|
|
; HANDLER: |
68
|
185
|
|
|
|
|
333
|
foreach my $h ( @$ch ) |
69
|
450
|
100
|
|
|
|
1932
|
{ return OK if &$h(@_) |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
; sub AUTOLOAD : lvalue |
74
|
0
|
|
|
0
|
|
0
|
{ (my $n = $AUTOLOAD) =~ s/.*:// |
75
|
0
|
0
|
|
|
|
0
|
; return if $n eq 'DESTROY' |
76
|
0
|
0
|
|
|
|
0
|
; @_ == 2 |
77
|
|
|
|
|
|
|
? ( $_[0]{__CUSTOM}{$n} = $_[1] ) |
78
|
|
|
|
|
|
|
: $_[0]{__CUSTOM}{$n} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
; sub tm |
82
|
965
|
|
|
965
|
1
|
1513
|
{ my ($az) = my ($z) = @_ ; |
83
|
965
|
|
|
|
|
3432
|
; until (defined $$az{tm}){ $az = $az->container } |
|
1382
|
|
|
|
|
15870
|
|
84
|
965
|
|
|
|
|
23559
|
; $$az{tm} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
; sub content_process |
88
|
108
|
|
|
108
|
1
|
177
|
{ my ($z) = @_ |
89
|
108
|
100
|
|
|
|
309
|
; defined $z->_e || return # content or return |
90
|
|
|
|
|
|
|
; ZONE: |
91
|
104
|
|
|
|
|
1304
|
for ( my $i = $z->_s |
92
|
|
|
|
|
|
|
; $i <= $z->_e |
93
|
|
|
|
|
|
|
; $i++ |
94
|
|
|
|
|
|
|
) |
95
|
420
|
|
|
|
|
5826
|
{ my $item = $z->_t->[$i][1] |
96
|
420
|
100
|
|
|
|
13993
|
; if ( not $item ) # just text |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
97
|
257
|
|
|
|
|
664
|
{ $z->text_process( $z->_t->[$i][0] ) |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
elsif ( ref $item eq 'HASH' ) # normal zone |
100
|
156
|
|
|
|
|
930
|
{ my $nz = ref($z)->new( %$item |
101
|
|
|
|
|
|
|
, level => $z->level + 1 |
102
|
|
|
|
|
|
|
, container => $z |
103
|
|
|
|
|
|
|
, _t => $z->_t |
104
|
|
|
|
|
|
|
) |
105
|
156
|
100
|
|
|
|
59618
|
; $i = $nz->_e + 1 if $nz->_e # skip block content |
106
|
156
|
100
|
|
|
|
2814
|
; next ZONE if $nz->zone_process |
107
|
144
|
|
|
|
|
511
|
; $nz->lookup_process |
108
|
144
|
|
|
|
|
1672
|
; $nz->value_process |
109
|
144
|
|
|
|
|
353
|
; $nz->post_process |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif ( $item eq 'CONTAINER_INCLUDE' ) |
112
|
4
|
|
|
|
|
11
|
{ $z->include_template($z->tm->{_included_template}) |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
elsif ( $item->is_main ) # included file |
115
|
3
|
|
|
|
|
104
|
{ $z->_include($item) |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
; sub _include |
121
|
8
|
|
|
8
|
|
13
|
{ my ($z, $iz) = @_ |
122
|
8
|
|
|
|
|
28
|
; @$iz{qw|container level tm|} = ( $z |
123
|
|
|
|
|
|
|
, $z->level |
124
|
|
|
|
|
|
|
, $z->tm |
125
|
|
|
|
|
|
|
) |
126
|
8
|
|
|
|
|
212
|
; $iz->content_process |
127
|
8
|
|
|
|
|
116
|
; delete @$iz{qw|container level tm|} # reset |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
; sub lookup_process |
131
|
149
|
|
|
149
|
1
|
203
|
{ my ($z) = @_ |
132
|
149
|
100
|
|
|
|
674
|
; defined $z->value and return |
133
|
147
|
|
|
|
|
9074
|
; $z->value($z->lookup) |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
; sub lookup |
137
|
150
|
|
|
150
|
1
|
704
|
{ my ( $z, $id ) = @_ |
138
|
150
|
|
66
|
|
|
711
|
; $id ||= $z->id |
139
|
150
|
|
|
|
|
3798
|
; my $val |
140
|
150
|
|
|
|
|
402
|
; for ( my $az = $z->container |
141
|
|
|
|
|
|
|
; $az->container |
142
|
|
|
|
|
|
|
; $az = $az->container |
143
|
|
|
|
|
|
|
) |
144
|
108
|
|
|
|
|
5775
|
{ $val = $z->_lookup( $az->value, $id ) |
145
|
108
|
100
|
|
|
|
548
|
; return $val if defined $val |
146
|
|
|
|
|
|
|
} |
147
|
73
|
|
|
|
|
3876
|
; my $tm = $z->tm |
148
|
73
|
|
|
|
|
138
|
; foreach my $l ( @{$$tm{_temp_lookups}} |
|
73
|
|
|
|
|
168
|
|
|
73
|
|
|
|
|
260
|
|
149
|
|
|
|
|
|
|
, @{$$tm{lookups}} |
150
|
|
|
|
|
|
|
, $$tm{_NOT_lookup} |
151
|
|
|
|
|
|
|
) |
152
|
87
|
100
|
|
|
|
245
|
{ next unless $l |
153
|
85
|
|
|
|
|
263
|
; $val = $z->_lookup( $l, $id ) |
154
|
85
|
100
|
|
|
|
481
|
; return $val if defined $val |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
; undef |
157
|
11
|
|
|
|
|
56
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
; sub _lookup |
160
|
193
|
|
|
193
|
|
1259
|
{ my ($z, $l, $id) = @_ |
161
|
193
|
100
|
|
|
|
447
|
; return unless $l |
162
|
187
|
|
|
|
|
553
|
; $z->location = $l |
163
|
187
|
100
|
|
|
|
2679
|
; if ( ref $l eq 'HASH' ) |
|
|
100
|
|
|
|
|
|
164
|
125
|
|
|
|
|
323
|
{ $$l{$id} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
elsif ( my $code = UNIVERSAL::can( $l, $id ) ) |
167
|
15
|
|
|
|
|
35
|
{ $code |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
else |
170
|
31
|
|
|
|
|
8093
|
{ no strict 'refs','vars' |
171
|
31
|
|
|
31
|
|
37793
|
; local *S = $l.'::'.$id |
|
31
|
|
|
|
|
69
|
|
|
47
|
|
|
|
|
196
|
|
172
|
47
|
100
|
|
|
|
244
|
; defined $S ? $S |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
173
|
|
|
|
|
|
|
: @S ? \@S |
174
|
|
|
|
|
|
|
: %S ? \%S |
175
|
|
|
|
|
|
|
: undef |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
; sub content |
180
|
11
|
|
|
11
|
1
|
48
|
{ my ($z) = @_ |
181
|
11
|
100
|
|
|
|
28
|
; defined $z->_e || return |
182
|
23
|
|
|
|
|
413
|
; join '' , map { $$_[0] |
|
7
|
|
|
|
|
118
|
|
183
|
|
|
|
|
|
|
} |
184
|
7
|
|
|
|
|
101
|
@{$z->_t} [ $z->_s |
185
|
|
|
|
|
|
|
.. |
186
|
|
|
|
|
|
|
$z->_e |
187
|
|
|
|
|
|
|
] |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
; sub include_template |
191
|
5
|
|
|
5
|
1
|
33
|
{ my ($z, $t) = @_ |
192
|
5
|
|
|
|
|
9
|
; my $nz = $z->tm->load($t) |
193
|
5
|
|
|
|
|
19
|
; $z->_include($nz) |
194
|
|
|
|
|
|
|
; return undef |
195
|
5
|
|
|
|
|
86
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
; 1 |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
__END__ |