line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Template::JIT::Base; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
6114
|
use 5.006; |
|
9
|
|
|
|
|
29
|
|
|
9
|
|
|
|
|
356
|
|
4
|
9
|
|
|
9
|
|
48
|
use strict; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
315
|
|
5
|
9
|
|
|
9
|
|
49
|
use warnings; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
462
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
69
|
use Carp qw(croak); |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
1190
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# the param method from HTML::Template ported to ::JIT |
12
|
|
|
|
|
|
|
sub param { |
13
|
0
|
|
|
0
|
0
|
|
my $pkg = shift; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my ($param_hash, $param_map, $case_sensitive); |
16
|
|
|
|
|
|
|
{ |
17
|
9
|
|
|
9
|
|
48
|
no strict 'refs'; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
5626
|
|
|
0
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
$param_map = \%{$pkg . '::param_map'}; |
|
0
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
$param_hash = \%{$pkg . '::param_hash'}; |
|
0
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
$case_sensitive = ${$pkg . '::case_sensitive'}; |
|
0
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# the no-parameter case - return list of parameters in the template. |
24
|
0
|
0
|
|
|
|
|
return keys(%$param_hash) unless scalar(@_); |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $first = shift; |
27
|
0
|
|
|
|
|
|
my $type = ref $first; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# the one-parameter case - could be a parameter value request or a |
30
|
|
|
|
|
|
|
# hash-ref. |
31
|
0
|
0
|
0
|
|
|
|
if (!scalar(@_) and !length($type)) { |
32
|
0
|
0
|
|
|
|
|
my $param = $case_sensitive ? $first : lc $first; |
33
|
0
|
0
|
0
|
|
|
|
return undef unless (exists($param_hash->{$param}) and |
34
|
|
|
|
|
|
|
defined($param_map->{$param})); |
35
|
0
|
|
|
|
|
|
return $param_map->{$param}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
if (!scalar(@_)) { |
39
|
0
|
0
|
0
|
|
|
|
croak("HTML::Template->param() : Single reference arg to param() must be a hash-ref! You gave me a $type.") |
|
|
|
0
|
|
|
|
|
40
|
|
|
|
|
|
|
unless $type eq 'HASH' or |
41
|
|
|
|
|
|
|
(ref($first) and UNIVERSAL::isa($first, 'HASH')); |
42
|
0
|
|
|
|
|
|
push(@_, %$first); |
43
|
|
|
|
|
|
|
} else { |
44
|
0
|
|
|
|
|
|
unshift(@_, $first); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
croak("HTML::Template->param() : You gave me an odd number of parameters to param()!") |
48
|
|
|
|
|
|
|
unless ((@_ % 2) == 0); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# strangely, changing this to a "while(@_) { shift, shift }" type |
51
|
|
|
|
|
|
|
# loop causes perl 5.004_04 to die with some nonsense about a |
52
|
|
|
|
|
|
|
# read-only value. |
53
|
0
|
|
|
|
|
|
for (my $x = 0; $x < $#_; $x += 2) { |
54
|
0
|
0
|
|
|
|
|
my $name = $case_sensitive ? $_[$x] : lc $_[$x]; |
55
|
0
|
|
|
|
|
|
my $value = $_[($x + 1)]; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
next unless $param_hash->{$name}; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
unless (ref $param_hash->{$name}) { |
60
|
|
|
|
|
|
|
# normal val |
61
|
0
|
|
|
|
|
|
$param_map->{$name} = $value; |
62
|
|
|
|
|
|
|
} else { |
63
|
|
|
|
|
|
|
# loop val |
64
|
0
|
|
|
|
|
|
$param_map->{$name} = _massage_loop($value, $param_hash->{$name}, $name, |
65
|
|
|
|
|
|
|
$case_sensitive); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _massage_loop { |
71
|
0
|
|
|
0
|
|
|
my ($array, $hash, $loop_name, $case_sensitive) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
croak("Bad param settings - found non array-ref for loop $loop_name!") |
74
|
|
|
|
|
|
|
unless ref $array eq 'ARRAY'; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
foreach my $row (@$array) { |
77
|
0
|
0
|
0
|
|
|
|
croak("Bad param settings - found non hash-ref for loop row in loop $loop_name!") |
78
|
|
|
|
|
|
|
unless ref $row && UNIVERSAL::isa($row, 'HASH'); |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $lc_name; |
81
|
0
|
|
|
|
|
|
foreach my $name (keys %$row) { |
82
|
0
|
0
|
|
|
|
|
$lc_name = $case_sensitive ? $name : lc $name; |
83
|
0
|
0
|
|
|
|
|
next unless $hash->{$lc_name}; |
84
|
0
|
0
|
|
|
|
|
unless (ref $hash->{$lc_name}) { |
85
|
0
|
|
|
|
|
|
$row->{$lc_name} = $row->{$name}; |
86
|
|
|
|
|
|
|
} else { |
87
|
0
|
|
|
|
|
|
$row->{$lc_name} = _massage_loop($row->{$name}, $hash->{$lc_name}, $loop_name, $case_sensitive); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
return $array; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub clear_params { |
95
|
0
|
|
|
0
|
0
|
|
my $pkg = shift; |
96
|
|
|
|
|
|
|
{ |
97
|
9
|
|
|
9
|
|
63
|
no strict 'refs'; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
677
|
|
|
0
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
%{$pkg . '::param_map'} = (); |
|
0
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |