| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::DBI::Template; |
|
2
|
1
|
|
|
1
|
|
33997
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
44
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
42
|
|
|
4
|
1
|
|
|
1
|
|
2568991
|
use Template; |
|
|
1
|
|
|
|
|
2227403
|
|
|
|
1
|
|
|
|
|
42
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
6
|
1
|
|
|
1
|
|
9
|
use base qw/Class::Data::Inheritable Exporter/; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
763
|
|
|
7
|
|
|
|
|
|
|
use Class::DBI::Template::Stash; |
|
8
|
|
|
|
|
|
|
use Carp qw/cluck croak/; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw/ |
|
11
|
|
|
|
|
|
|
template_define |
|
12
|
|
|
|
|
|
|
template_configure |
|
13
|
|
|
|
|
|
|
template_data |
|
14
|
|
|
|
|
|
|
template_render |
|
15
|
|
|
|
|
|
|
template_build_data |
|
16
|
|
|
|
|
|
|
/; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata("_template_$_") for qw/configure define data/; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _template_hash { |
|
21
|
|
|
|
|
|
|
my $item = shift; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $classdata = "_template_$item"; |
|
24
|
|
|
|
|
|
|
my %data = %{__PACKAGE__->$classdata() || {}}; |
|
25
|
|
|
|
|
|
|
if(@_ > 1) { |
|
26
|
|
|
|
|
|
|
my %new = @_; |
|
27
|
|
|
|
|
|
|
foreach(keys %new) { $data{$_} = $new{$_}; } |
|
28
|
|
|
|
|
|
|
__PACKAGE__->$classdata(\%data); |
|
29
|
|
|
|
|
|
|
} elsif(@_ == 1) { |
|
30
|
|
|
|
|
|
|
return $data{shift()}; |
|
31
|
|
|
|
|
|
|
} else { |
|
32
|
|
|
|
|
|
|
return %data; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
sub template_define { shift; _template_hash('define',@_); } |
|
36
|
|
|
|
|
|
|
sub template_data { shift; _template_hash('data',@_); } |
|
37
|
|
|
|
|
|
|
my %configure_defaults = ( |
|
38
|
|
|
|
|
|
|
stash_order => $Class::DBI::Template::Stash::default_order, |
|
39
|
|
|
|
|
|
|
stash_preload => $Class::DBI::Template::Stash::default_preload, |
|
40
|
|
|
|
|
|
|
stash_cache => 1, |
|
41
|
|
|
|
|
|
|
); |
|
42
|
|
|
|
|
|
|
sub template_configure { |
|
43
|
|
|
|
|
|
|
my $self = shift; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $data = __PACKAGE__->_template_configure(); |
|
46
|
|
|
|
|
|
|
if(! $data) { |
|
47
|
|
|
|
|
|
|
$data = {%configure_defaults}; |
|
48
|
|
|
|
|
|
|
__PACKAGE__->_template_configure($data); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
if(@_ > 1) { |
|
51
|
|
|
|
|
|
|
my %new = @_; |
|
52
|
|
|
|
|
|
|
while(my($var,$val) = each %new) { |
|
53
|
|
|
|
|
|
|
$var =~ s/^\-//; |
|
54
|
|
|
|
|
|
|
$data->{lc($var)} = $val; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
__PACKAGE__->_template_configure($data); |
|
57
|
|
|
|
|
|
|
} elsif(@_ == 1) { |
|
58
|
|
|
|
|
|
|
my $item = lc(shift()); |
|
59
|
|
|
|
|
|
|
$item =~ s/^\-//; |
|
60
|
|
|
|
|
|
|
return $data->{$item}; |
|
61
|
|
|
|
|
|
|
} else { |
|
62
|
|
|
|
|
|
|
return wantarray ? %{$data} : $data; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub template_render { |
|
67
|
|
|
|
|
|
|
my $self = shift; |
|
68
|
|
|
|
|
|
|
my $which = shift; |
|
69
|
|
|
|
|
|
|
my %args = @_; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my %vars = (); |
|
72
|
|
|
|
|
|
|
my $tmpl = $self->template_define($which) || $which; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my @stash_order = Class::DBI::Template::Stash::unfold( |
|
75
|
|
|
|
|
|
|
$self->template_configure('stash_order') |
|
76
|
|
|
|
|
|
|
); |
|
77
|
|
|
|
|
|
|
my %pre = (); |
|
78
|
|
|
|
|
|
|
foreach my $pre (@{$self->template_configure('stash_preload')}) { |
|
79
|
|
|
|
|
|
|
$pre{$pre}++; |
|
80
|
|
|
|
|
|
|
if($pre eq 'columns') { |
|
81
|
|
|
|
|
|
|
foreach($self->columns) { $vars{$_} = $self->get($_); } |
|
82
|
|
|
|
|
|
|
} elsif($pre eq 'template_data') { |
|
83
|
|
|
|
|
|
|
my %new = __PACKAGE__->template_data(); |
|
84
|
|
|
|
|
|
|
@vars{keys %new} = values %new; |
|
85
|
|
|
|
|
|
|
} elsif($pre eq 'environment') { |
|
86
|
|
|
|
|
|
|
@vars{keys %ENV} = values %ENV; |
|
87
|
|
|
|
|
|
|
} elsif($pre eq 'arguments') { |
|
88
|
|
|
|
|
|
|
@vars{keys %args} = values %args; |
|
89
|
|
|
|
|
|
|
} else { |
|
90
|
|
|
|
|
|
|
die "Cannot preload $pre\n"; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
@stash_order = grep { $_ ne $pre } @stash_order; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
$vars{_PRELOADED} = \%pre; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my %opts = %{__PACKAGE__->template_configure('template_options') || {}}; |
|
97
|
|
|
|
|
|
|
$opts{STASH} = Class::DBI::Template::Stash->new({}); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$vars{_SELF} = $self; |
|
100
|
|
|
|
|
|
|
$vars{_ARGS} = \%args; |
|
101
|
|
|
|
|
|
|
$vars{_CONF} = __PACKAGE__->_template_configure; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $out = ''; |
|
104
|
|
|
|
|
|
|
eval { |
|
105
|
|
|
|
|
|
|
my $template = Template->new(\%opts); |
|
106
|
|
|
|
|
|
|
if($out = $self->template_configure('output')) { |
|
107
|
|
|
|
|
|
|
$template->process($tmpl, \%vars, \$out) || die $template->error; |
|
108
|
|
|
|
|
|
|
return; |
|
109
|
|
|
|
|
|
|
} else { |
|
110
|
|
|
|
|
|
|
$template->process($tmpl, \%vars, \$out) || die $template->error; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
}; |
|
113
|
|
|
|
|
|
|
if($@) { |
|
114
|
|
|
|
|
|
|
croak "Template processing failed: $@"; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
if($out) { |
|
117
|
|
|
|
|
|
|
return $out; |
|
118
|
|
|
|
|
|
|
} else { |
|
119
|
|
|
|
|
|
|
die "No output found\n"; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
|
124
|
|
|
|
|
|
|
__END__ |