line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Template::HashWrapper; |
2
|
1
|
|
|
1
|
|
26338
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
3
|
1
|
|
|
1
|
|
6
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
409
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.3'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
6
|
|
|
6
|
0
|
5360
|
my $class = shift; |
9
|
6
|
|
|
|
|
8
|
my $wrapped = shift; |
10
|
6
|
50
|
|
|
|
45
|
unless ( UNIVERSAL::isa($wrapped, 'HASH') ) { |
11
|
0
|
|
|
|
|
0
|
croak "Wrapped object is not a hash reference"; |
12
|
|
|
|
|
|
|
} |
13
|
6
|
|
|
|
|
17
|
my %args = @_; |
14
|
6
|
|
|
|
|
8
|
my $at_isa = $class; |
15
|
6
|
|
|
|
|
23
|
my $pkgname = $class->_GENERATE_PACKAGENAME(); |
16
|
6
|
100
|
|
|
|
27
|
if ( UNIVERSAL::isa( $wrapped, 'UNIVERSAL' ) ) { |
17
|
|
|
|
|
|
|
# $wrapped is already blessed: add its ref to @ISA |
18
|
2
|
|
|
|
|
13
|
$at_isa .= " " . ref($wrapped); |
19
|
|
|
|
|
|
|
} |
20
|
1
|
|
|
1
|
|
8
|
eval "{package $pkgname; use strict; our \@ISA=qw($at_isa); 1;}"; |
|
1
|
|
|
1
|
|
1
|
|
|
1
|
|
|
1
|
|
50
|
|
|
1
|
|
|
1
|
|
9
|
|
|
1
|
|
|
1
|
|
4
|
|
|
1
|
|
|
1
|
|
77
|
|
|
1
|
|
|
|
|
28
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
640
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
|
6
|
|
|
|
|
630
|
|
21
|
6
|
50
|
|
|
|
19
|
die $@ if $@; |
22
|
6
|
|
|
|
|
30
|
return bless $wrapped, $pkgname; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# If you don't like my anonymous packagename generation, you can roll your own. |
26
|
|
|
|
|
|
|
sub _GENERATE_PACKAGENAME { |
27
|
6
|
|
|
6
|
|
10
|
my $class = shift; |
28
|
6
|
|
|
|
|
90
|
my $uniq = "ANON_".$$.time().int(rand()*10000); |
29
|
6
|
|
|
|
|
14
|
my $pkgname = "$ {class}::$ {uniq}"; |
30
|
6
|
|
|
|
|
13
|
return $pkgname; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# todo: according to H::T, param() can also support: |
34
|
|
|
|
|
|
|
# set multiple params: hash input |
35
|
|
|
|
|
|
|
# set multuple params from a hashref input |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Standard behavior: $self is a hashref |
38
|
|
|
|
|
|
|
sub param { |
39
|
24
|
|
|
24
|
0
|
10288
|
my $self = shift; |
40
|
24
|
|
|
|
|
45
|
my($name, $value) = @_; |
41
|
24
|
100
|
|
|
|
58
|
if ( defined($name) ) { |
42
|
16
|
100
|
|
|
|
32
|
if (defined($value)) { |
43
|
4
|
|
|
|
|
16
|
return $self->{$name} = $value; |
44
|
|
|
|
|
|
|
} else { |
45
|
12
|
|
|
|
|
62
|
return $self->{$name}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} else { |
48
|
8
|
|
|
|
|
9
|
return keys %{$self}; |
|
8
|
|
|
|
|
49
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
package HTML::Template::HashWrapper::Plain; |
56
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
33
|
|
57
|
1
|
|
|
1
|
|
5
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
227
|
|
58
|
|
|
|
|
|
|
our @ISA=('HTML::Template::HashWrapper'); # everything is overridden, though |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new { |
61
|
4
|
|
|
4
|
|
3133
|
my $class = shift; |
62
|
4
|
|
|
|
|
8
|
my $target = shift; |
63
|
4
|
50
|
|
|
|
20
|
unless ( UNIVERSAL::isa($target, 'HASH') ) { |
64
|
0
|
|
|
|
|
0
|
croak "Wrapped object is not a hash reference"; |
65
|
|
|
|
|
|
|
} |
66
|
4
|
|
|
|
|
25
|
return bless { _ref => $target }, $class; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Un-reblessing behavior: $self contains a reference to the reference |
70
|
|
|
|
|
|
|
sub param { |
71
|
24
|
|
|
24
|
|
8719
|
my $self = shift; |
72
|
24
|
|
|
|
|
37
|
my($name, $value) = @_; |
73
|
24
|
100
|
|
|
|
53
|
if ( defined($name) ) { |
74
|
16
|
100
|
|
|
|
31
|
if (defined($value)) { |
75
|
4
|
|
|
|
|
14
|
return $self->{_ref}->{$name} = $value; |
76
|
|
|
|
|
|
|
} else { |
77
|
12
|
|
|
|
|
56
|
return $self->{_ref}->{$name}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} else { |
80
|
8
|
|
|
|
|
15
|
return keys %{ $self->{_ref} }; |
|
8
|
|
|
|
|
62
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
__END__ |