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
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
27
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
28
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
29
|
1
|
|
|
1
|
|
5
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
5
|
use CGI::FormBuilder::Util; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
144
|
|
32
|
1
|
|
|
1
|
|
6
|
use Template; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
404
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = '3.09'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
38
|
4
|
|
|
4
|
0
|
10
|
my $self = shift; |
39
|
4
|
|
33
|
|
|
21
|
my $class = ref($self) || $self; |
40
|
4
|
|
|
|
|
18
|
my $opt = arghash(@_); |
41
|
|
|
|
|
|
|
|
42
|
4
|
50
|
33
|
|
|
80
|
$opt->{engine} = Template->new($opt->{engine} || {}) |
43
|
|
|
|
|
|
|
|| puke $Template::ERROR unless UNIVERSAL::isa($opt->{engine}, 'Template'); |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
|
|
33926
|
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
|
9
|
my $self = shift; |
54
|
4
|
|
33
|
|
|
14
|
my $tvar = shift || puke "Missing template expansion hashref (\$form->prepare failed?)"; |
55
|
|
|
|
|
|
|
|
56
|
4
|
|
33
|
|
|
14
|
my $tt2template = $self->{template} |
57
|
|
|
|
|
|
|
|| puke "Template Toolkit template not specified"; |
58
|
4
|
|
50
|
|
|
104
|
my $tt2data = $self->{data} || {}; |
59
|
4
|
|
|
|
|
12
|
my $tt2var = $self->{variable}; # optional var for nesting |
60
|
|
|
|
|
|
|
|
61
|
4
|
50
|
|
|
|
13
|
if ($tt2var) { |
62
|
4
|
|
|
|
|
15
|
$tt2data->{$tt2var} = $tvar; |
63
|
|
|
|
|
|
|
} else { |
64
|
0
|
|
|
|
|
0
|
$tt2data = { %$tt2data, %$tvar }; |
65
|
|
|
|
|
|
|
} |
66
|
4
|
|
|
|
|
7
|
my $tt2output; # growing a scalar is so C-ish |
67
|
|
|
|
|
|
|
|
68
|
4
|
50
|
|
|
|
23
|
$self->{engine}->process($tt2template, $tt2data, \$tt2output) |
69
|
|
|
|
|
|
|
|| puke $self->{engine}->error(); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# string HTML output |
72
|
4
|
|
|
|
|
92251
|
return $tt2output; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
__END__ |