line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Application::Plugin::TmplInnerOuter; |
2
|
2
|
|
|
2
|
|
57695
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
66
|
|
3
|
2
|
|
|
2
|
|
1741
|
use HTML::Template::Default 'get_tmpl'; |
|
2
|
|
|
|
|
48772
|
|
|
2
|
|
|
|
|
134
|
|
4
|
|
|
|
|
|
|
require Exporter; |
5
|
2
|
|
|
2
|
|
16
|
use Carp; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
97
|
|
6
|
2
|
|
|
2
|
|
9
|
use vars qw($VERSION @ISA @EXPORT); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1937
|
|
7
|
|
|
|
|
|
|
@ISA = qw/ Exporter /; |
8
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.13 $ =~ /(\d+)/g; |
9
|
|
|
|
|
|
|
@EXPORT = (qw( |
10
|
|
|
|
|
|
|
_feed_merge |
11
|
|
|
|
|
|
|
_feed_vars |
12
|
|
|
|
|
|
|
_feed_vars_all |
13
|
|
|
|
|
|
|
_get_tmpl_default |
14
|
|
|
|
|
|
|
_get_tmpl_name |
15
|
|
|
|
|
|
|
_get_vars |
16
|
|
|
|
|
|
|
_set_tmpl_default |
17
|
|
|
|
|
|
|
_set_vars |
18
|
|
|
|
|
|
|
_tmpl |
19
|
|
|
|
|
|
|
_tmpl_inner |
20
|
|
|
|
|
|
|
_tmpl_outer |
21
|
|
|
|
|
|
|
tmpl |
22
|
|
|
|
|
|
|
tmpl_main |
23
|
|
|
|
|
|
|
tmpl_output |
24
|
|
|
|
|
|
|
tmpl_inner_name |
25
|
|
|
|
|
|
|
tmpl_inner_name_set |
26
|
|
|
|
|
|
|
tmpl_set |
27
|
|
|
|
|
|
|
_debug_vars |
28
|
|
|
|
|
|
|
)); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
*tmpl_main = \&_tmpl_outer; # includes argument, this pulls outer, main.html template |
32
|
|
|
|
|
|
|
*_tmpl_inner = \&_tmpl; |
33
|
|
|
|
|
|
|
*tmpl = \&_tmpl; # without argument, returns inner template |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _tmpl_outer { |
36
|
3
|
|
|
3
|
|
4
|
my $self = shift; |
37
|
3
|
|
|
|
|
24
|
return $self->_tmpl('main.html'); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _tmpl { |
41
|
5
|
|
|
5
|
|
7
|
my($self,$name) = @_; |
42
|
5
|
|
66
|
|
|
16
|
$name ||= $self->_get_tmpl_name; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#$self->{_tmpl} ||= {}; |
45
|
|
|
|
|
|
|
|
46
|
5
|
100
|
|
|
|
16
|
unless( $self->{_tmpl}->{$name} ) { |
47
|
2
|
|
|
|
|
253
|
my $path = $self->tmpl_path; |
48
|
2
|
|
100
|
|
|
20
|
$path ||= './'; |
49
|
2
|
|
|
|
|
5
|
$self->tmpl_path( $path ); |
50
|
|
|
|
|
|
|
|
51
|
2
|
50
|
|
|
|
18
|
my $tmpl = get_tmpl($name,$self->_get_tmpl_default($name)) |
52
|
|
|
|
|
|
|
or warn("cant get [$name] template"); |
53
|
2
|
|
|
|
|
1169
|
$self->{_tmpl}->{$name} = $tmpl; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
5
|
|
|
|
|
25
|
return $self->{_tmpl}->{$name}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _set_tmpl_default { |
60
|
2
|
|
|
2
|
|
23208
|
my ($self,$default,$name) = @_; |
61
|
2
|
50
|
|
|
|
7
|
defined $default or confess('missing template code arg'); |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
66
|
|
|
12
|
$name ||= $self->_get_tmpl_name; |
64
|
|
|
|
|
|
|
#$self->{_tmpl_default} ||= {}; |
65
|
2
|
|
|
|
|
6
|
$self->{_tmpl_default}->{$name} = \$default; |
66
|
2
|
|
|
|
|
4
|
return $name; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
*tmpl_inner_name_set = \&tmpl_inner_name; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub tmpl_inner_name { |
72
|
3
|
|
|
3
|
1
|
4
|
my ($self,$name) = @_; |
73
|
3
|
50
|
|
|
|
9
|
if( defined $name ){ $self->{__tmpl_inner_name} = $name } |
|
0
|
|
|
|
|
0
|
|
74
|
|
|
|
|
|
|
|
75
|
3
|
50
|
66
|
|
|
18
|
$self->{__tmpl_inner_name} ||= $self->get_current_runmode or die('no runmode'); |
76
|
3
|
|
|
|
|
18
|
return $self->{__tmpl_inner_name}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
3
|
|
|
3
|
|
11
|
sub _get_tmpl_name { $_[0]->tmpl_inner_name . '.html' } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _get_tmpl_default { |
82
|
2
|
|
|
2
|
|
6
|
my ($self,$name) = @_; |
83
|
2
|
|
33
|
|
|
7
|
$name ||= $self->_get_tmpl_name; |
84
|
|
|
|
|
|
|
#$self->{_tmpl_default} ||={}; |
85
|
|
|
|
|
|
|
|
86
|
2
|
100
|
66
|
|
|
12
|
if ($name eq 'main.html' and ! defined $self->{_tmpl_default}->{'main.html'}){ |
87
|
|
|
|
|
|
|
### main.html was not defined, using default hard coded main.html template |
88
|
1
|
|
|
|
|
3
|
$self->_set_tmpl_default( |
89
|
|
|
|
|
|
|
q{
|
90
|
|
|
|
|
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
},'main.html'); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
10
|
return $self->{_tmpl_default}->{$name}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
*tmpl_set = \&_set_vars; |
110
|
|
|
|
|
|
|
*_get_vars = \&_set_vars; |
111
|
|
|
|
|
|
|
sub _set_vars { |
112
|
3
|
|
|
3
|
|
22
|
my $self = shift; |
113
|
|
|
|
|
|
|
#$self->{_tmpl_vars} || = {}; |
114
|
|
|
|
|
|
|
#unless ( @_ ){ |
115
|
|
|
|
|
|
|
# return $self->{_tmpl_vars}; |
116
|
|
|
|
|
|
|
#} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
3
|
|
|
|
|
11
|
my %vars = @_; |
120
|
|
|
|
|
|
|
|
121
|
3
|
|
|
|
|
11
|
for ( keys %vars ){ |
122
|
7
|
100
|
|
|
|
8
|
my $key = $_; my $val = $vars{$key}; defined $val or next; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
14
|
|
123
|
6
|
|
|
|
|
12
|
$self->{_tmpl_vars}->{$key} = $val; |
124
|
|
|
|
|
|
|
}; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
#return 1; |
127
|
3
|
|
|
|
|
8
|
$self->{_tmpl_vars} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _get_vars { |
131
|
|
|
|
|
|
|
my $self = shift; |
132
|
|
|
|
|
|
|
$self->{_tmpl_vars} ||={}; |
133
|
|
|
|
|
|
|
return $self->{_tmpl_vars}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _feed_vars { |
137
|
2
|
|
|
2
|
|
5
|
my $self = shift; |
138
|
2
|
|
|
|
|
1
|
my $tmpl = shift; |
139
|
2
|
50
|
|
|
|
6
|
defined $tmpl or confess('missing arg'); |
140
|
|
|
|
|
|
|
### start |
141
|
2
|
|
|
|
|
6
|
my $vars = $self->_get_vars; |
142
|
2
|
|
|
|
|
6
|
VARS : for( keys %$vars){ |
143
|
12
|
|
|
|
|
206
|
my $key = $_; |
144
|
12
|
|
|
|
|
15
|
my $val = $vars->{$key}; |
145
|
12
|
50
|
|
|
|
23
|
defined $val or next VARS; |
146
|
12
|
|
|
|
|
31
|
$tmpl->param( $_ => $vars->{$_} ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
### ok |
149
|
2
|
|
|
|
|
36
|
return 1; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub _debug_vars { |
154
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
155
|
0
|
|
|
|
|
0
|
my $neat_layout = shift; |
156
|
0
|
|
0
|
|
|
0
|
$neat_layout ||=0; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
0
|
my $v = $self->_get_vars; |
159
|
0
|
|
|
|
|
0
|
my @k = sort keys %$v; |
160
|
0
|
0
|
|
|
|
0
|
scalar @k or return 1; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
### debug vars |
163
|
0
|
0
|
|
|
|
0
|
if($neat_layout){ |
164
|
0
|
|
|
|
|
0
|
map { printf STDERR " %18s : %s\n", $_, $v->{$_} } @k; |
|
0
|
|
|
|
|
0
|
|
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
else { |
168
|
0
|
|
|
|
|
0
|
map { printf STDERR " %s'%s', ", $_, $v->{$_} } @k; |
|
0
|
|
|
|
|
0
|
|
169
|
|
|
|
|
|
|
} |
170
|
0
|
|
|
|
|
0
|
print STDERR "\n"; |
171
|
0
|
|
|
|
|
0
|
return 1; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub tmpl_output { |
177
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
178
|
1
|
|
|
|
|
4
|
$self->_feed_vars_all; |
179
|
1
|
|
|
|
|
3
|
$self->_feed_merge; |
180
|
1
|
|
|
|
|
2
|
return $self->_tmpl_outer->output; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub _feed_vars_all { |
185
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
186
|
1
|
|
|
|
|
3
|
$self->_feed_vars( $self->_tmpl_inner ); |
187
|
1
|
|
|
|
|
4
|
$self->_feed_vars( $self->_tmpl_outer ); |
188
|
1
|
|
|
|
|
2
|
return 1; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub _feed_merge { |
192
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
193
|
1
|
|
|
|
|
2
|
$self->_tmpl_outer->param( BODY => $self->_tmpl_inner->output ); |
194
|
1
|
|
|
|
|
78
|
return 1; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |