line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Template::Nest; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
34112
|
use 5.020001; |
|
2
|
|
|
|
|
11
|
|
4
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
58
|
|
5
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
73
|
|
6
|
2
|
|
|
2
|
|
12
|
use File::Spec; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
51
|
|
7
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
171
|
|
8
|
2
|
|
|
2
|
|
994
|
use Data::Dumper; |
|
2
|
|
|
|
|
14248
|
|
|
2
|
|
|
|
|
125
|
|
9
|
2
|
|
|
2
|
|
431
|
use HTML::Template; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new{ |
15
|
|
|
|
|
|
|
my ($class,%opts) = @_; |
16
|
|
|
|
|
|
|
my $self = {%opts}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#defaults |
19
|
|
|
|
|
|
|
$self->{comment_tokens} = [ '' ] unless $self->{comment_tokens}; |
20
|
|
|
|
|
|
|
$self->{name_label} = 'NAME' unless $self->{name_label}; |
21
|
|
|
|
|
|
|
$self->{template_dir} = '' unless defined $self->{template_dir}; |
22
|
|
|
|
|
|
|
$self->{template_ext} = '.html' unless defined $self->{template_ext}; |
23
|
|
|
|
|
|
|
$self->{show_labels} = 0 unless defined $self->{show_labels}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
bless $self,$class; |
26
|
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub template_dir{ |
31
|
|
|
|
|
|
|
my($self,$dir) = @_; |
32
|
|
|
|
|
|
|
confess "Expected a scalar directory name but got a ".ref($dir) if $dir && ref($dir); |
33
|
|
|
|
|
|
|
$self->{template_dir} = $dir if $dir; |
34
|
|
|
|
|
|
|
return $self->{template_dir}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub comment_tokens{ |
39
|
|
|
|
|
|
|
my ($self,$token1,$token2) = @_; |
40
|
|
|
|
|
|
|
if (defined $token1 ){ |
41
|
|
|
|
|
|
|
$token2 = $token2 || ''; |
42
|
|
|
|
|
|
|
$self->{'comment_tokens'} = [ $token1, $token2 ]; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
return $self->{'comment_tokens'}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub show_labels{ |
52
|
|
|
|
|
|
|
my ($self,$show) = @_; |
53
|
|
|
|
|
|
|
confess "Expected a boolean but got $show" if $show && ! ( $show == 0 || $show == 1 ); |
54
|
|
|
|
|
|
|
$self->{show_labels} = $show if $show; |
55
|
|
|
|
|
|
|
return $self->{show_labels}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub template_ext{ |
60
|
|
|
|
|
|
|
my ($self,$ext) = @_; |
61
|
|
|
|
|
|
|
confess "Expected a scalar extension name but got a ".ref($ext) if defined $ext && ref($ext); |
62
|
|
|
|
|
|
|
$self->{template_ext} = $ext if defined $ext; |
63
|
|
|
|
|
|
|
return $self->{template_ext}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub name_label{ |
68
|
|
|
|
|
|
|
my ($self,$label) = @_; |
69
|
|
|
|
|
|
|
confess "Expected a scalar name label but got a ".ref($label) if defined $label && ref($label); |
70
|
|
|
|
|
|
|
$self->{name_label} = $label if $label; |
71
|
|
|
|
|
|
|
return $self->{name_label}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub to_html{ |
76
|
|
|
|
|
|
|
my ($self,$comp) = @_; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $html; |
79
|
|
|
|
|
|
|
if ( ref($comp) =~ /array/i ){ |
80
|
|
|
|
|
|
|
$html = $self->_array_to_html( $comp ); |
81
|
|
|
|
|
|
|
} elsif( ref( $comp ) =~ /hash/i ){ |
82
|
|
|
|
|
|
|
$html = $self->_hash_to_html( $comp ); |
83
|
|
|
|
|
|
|
} else { |
84
|
|
|
|
|
|
|
$html = $comp; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return $html; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _hash_to_html{ |
93
|
|
|
|
|
|
|
my ($self,$h) = @_; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
confess "Expected a hashref. Instead got a ".ref($h) unless ref($h) =~ /hash/i; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $template_name = $h->{ $self->name_label }; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
confess 'Encountered hash with no name_label ("'.$self->name_label.'"): '.Dumper( $h ) unless $template_name; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $param = {}; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
foreach my $k ( keys %$h ){ |
104
|
|
|
|
|
|
|
next if $k eq $self->name_label; |
105
|
|
|
|
|
|
|
$param->{$k} = $self->to_html( $h->{$k} ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $filename = File::Spec->catdir( |
109
|
|
|
|
|
|
|
$self->template_dir, |
110
|
|
|
|
|
|
|
$template_name.$self->template_ext |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $temp = HTML::Template->new( filename => $filename ); |
114
|
|
|
|
|
|
|
$temp->param( $_ => $param->{$_} ) foreach keys %$param; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $html = $temp->output; |
117
|
|
|
|
|
|
|
if ( $self->show_labels ){ |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $ca = $self->{comment_tokens}->[0]; |
120
|
|
|
|
|
|
|
my $cb = $self->{comment_tokens}->[1]; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$html = "$ca BEGIN $template_name $cb\n$html\n$ca END $template_name $cb\n"; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
return $html; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _array_to_html{ |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my ($self, $arr, $delim) = @_; |
135
|
|
|
|
|
|
|
die "Expected an array. Instead got a ".ref($arr) unless ref($arr) =~ /array/i; |
136
|
|
|
|
|
|
|
my $html = ''; |
137
|
|
|
|
|
|
|
foreach my $comp (@$arr){ |
138
|
|
|
|
|
|
|
$html.= $delim if ($delim && $html); |
139
|
|
|
|
|
|
|
$html.= $self->to_html( $comp ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
return $html; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
__END__ |