line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
########################################################################### |
3
|
|
|
|
|
|
|
# Copyright (c) Nate Wiger http://nateware.com. All Rights Reserved. |
4
|
|
|
|
|
|
|
# Please visit http://formbuilder.org for tutorials, support, and examples. |
5
|
|
|
|
|
|
|
########################################################################### |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package CGI::FormBuilder::Template::TT2; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
CGI::FormBuilder::Template::TT2 - FormBuilder interface to Template Toolkit |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $form = CGI::FormBuilder->new( |
16
|
|
|
|
|
|
|
fields => \@fields, |
17
|
|
|
|
|
|
|
template => { |
18
|
|
|
|
|
|
|
type => 'TT2', |
19
|
|
|
|
|
|
|
template => 'form.tmpl', |
20
|
|
|
|
|
|
|
variable => 'form', |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
51
|
|
27
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
28
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
29
|
1
|
|
|
1
|
|
3
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
3
|
use CGI::FormBuilder::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
32
|
1
|
|
|
1
|
|
3
|
use Template; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
241
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = '3.10'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
38
|
4
|
|
|
4
|
0
|
6
|
my $self = shift; |
39
|
4
|
|
33
|
|
|
14
|
my $class = ref($self) || $self; |
40
|
4
|
|
|
|
|
13
|
my $opt = arghash(@_); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$opt->{engine} = Template->new($opt->{engine} || {}) |
43
|
4
|
50
|
33
|
|
|
51
|
|| puke $Template::ERROR unless UNIVERSAL::isa($opt->{engine}, 'Template'); |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
|
|
17963
|
return bless $opt, $class; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub engine { |
49
|
0
|
|
|
0
|
1
|
0
|
return shift()->{engine}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub render { |
53
|
4
|
|
|
4
|
1
|
6
|
my $self = shift; |
54
|
4
|
|
33
|
|
|
10
|
my $tvar = shift || puke "Missing template expansion hashref (\$form->prepare failed?)"; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $tt2template = $self->{template} |
57
|
4
|
|
33
|
|
|
11
|
|| puke "Template Toolkit template not specified"; |
58
|
4
|
|
50
|
|
|
14
|
my $tt2data = $self->{data} || {}; |
59
|
4
|
|
|
|
|
7
|
my $tt2var = $self->{variable}; # optional var for nesting |
60
|
|
|
|
|
|
|
|
61
|
4
|
50
|
|
|
|
8
|
if ($tt2var) { |
62
|
4
|
|
|
|
|
9
|
$tt2data->{$tt2var} = $tvar; |
63
|
|
|
|
|
|
|
} else { |
64
|
0
|
|
|
|
|
0
|
$tt2data = { %$tt2data, %$tvar }; |
65
|
|
|
|
|
|
|
} |
66
|
4
|
|
|
|
|
4
|
my $tt2output; # growing a scalar is so C-ish |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$self->{engine}->process($tt2template, $tt2data, \$tt2output) |
69
|
4
|
50
|
|
|
|
16
|
|| puke $self->{engine}->error(); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# string HTML output |
72
|
4
|
|
|
|
|
44968
|
return $tt2output; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
__END__ |