| 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)
MC/DC100%1/1
$z->tm->{$n . '_handlers'} || (return)
$z->tm->{$n . '_handlers'}
Truth table100%2/2
A
A= $z->tm->{$n . '_handlers'}
| |||||||||||||||||||||||||||||
| 22 | ; HANDLER: | ||||||||||||||||||||||||||||
| 23 | 396 | foreach my $h ( @$ch ) | |||||||||||||||||||||||||||
| 24 | 396 | ▶ | { return OK if $h->(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $v and length $v
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | ; my $ch = $$tm{value_handlers} || return | ||||||||||||||||||||||||||||
| 67 | 185 | ▶ | ; HANDLER: | ||||||||||||||||||||||||||
|
Condition50%1/2
$tm->{'value_handlers'} || (return)
MC/DC0%0/1
$tm->{'value_handlers'} || (return)
$tm->{'value_handlers'}
Truth table50%1/2
A
A= $tm->{'value_handlers'}
| |||||||||||||||||||||||||||||
| 68 | 185 | foreach my $h ( @$ch ) | |||||||||||||||||||||||||||
| 69 | 450 | ▶ | { return OK if &$h(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 76 | ; @_ == 2 | ||||||||||||||||||||||||||||
| 77 | ? ( $_[0]{__CUSTOM}{$n} = $_[1] ) | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | : $_[0]{__CUSTOM}{$n} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 90 | ; ZONE: | ||||||||||||||||||||||||||||
| 91 | 104 | ▶ | for ( my $i = $z->_s | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 106 | 156 | ▶ | ; next ZONE if $nz->zone_process | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$id ||= $z->id
$id
$z->id
Truth table66%2/3
A ||= B
A= $idB= $z->id
| |||||||||||||||||||||||||||||
| 139 | 150 | ; my $val | |||||||||||||||||||||||||||
| 140 | 150 | ▶ | ; for ( my $az = $z->container | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 153 | 85 | ; $val = $z->_lookup( $l, $id ) | |||||||||||||||||||||||||||
| 154 | 85 | ▶ | ; return $val if defined $val | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 162 | 187 | ; $z->location = $l | |||||||||||||||||||||||||||
| 163 | 187 | ▶ | ; if ( ref $l eq 'HASH' ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||