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