| 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 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use CGI::FormBuilder::Util; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use Template; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 1 | our $VERSION = '3.10'; | |||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | sub new { | ||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | my $class = ref($self) || $self; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||
| 40 | 4 | my $opt = arghash(@_); | |||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | $opt->{engine} = Template->new($opt->{engine} || {}) | ||||||||||||||||||||||||||||||||||||||
| 43 | 4 | ▶ | || puke $Template::ERROR unless UNIVERSAL::isa($opt->{engine}, 'Template'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
'Template'->new($opt->{'engine'} || {}) || &puke($Template::ERROR)
$opt->{'engine'} || {}
MC/DC0%0/2
'Template'->new($opt->{'engine'} || {}) || &puke($Template::ERROR)
'Template'->new($opt->{'engine'} || {})
&puke($Template::ERROR)
MC/DC0%0/1
$opt->{'engine'} || {}
$opt->{'engine'}
Truth table33%1/3
A || B
A= 'Template'->new($opt->{'engine'} || {})B= &puke($Template::ERROR)
Truth table50%1/2
A
A= $opt->{'engine'}
| |||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | 4 | return bless $opt, $class; | |||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||
| 48 | sub engine { | ||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return shift()->{engine}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
engine: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||
| 52 | sub render { | ||||||||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=6 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 54 | 4 | ▶ | my $tvar = shift || puke "Missing template expansion hashref (\$form->prepare failed?)"; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || &puke('Missing template expansion hashref ($form->prepare failed?)')
MC/DC0%0/2
shift() || &puke('Missing template expansion hashref ($form->prepare failed?)')
shift()
&puke('Missing template expansion hashref ($form->prepare failed?)')
Truth table33%1/3
A || B
A= shift()B= &puke('Missing template expansion hashref ($form->prepare failed?)')
| |||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | my $tt2template = $self->{template} | ||||||||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | || puke "Template Toolkit template not specified"; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'template'} || &puke('Template Toolkit template not specified')
MC/DC0%0/2
$self->{'template'} || &puke('Template Toolkit template not specified')
$self->{'template'}
&puke('Template Toolkit template not specified')
Truth table33%1/3
A || B
A= $self->{'template'}B= &puke('Template Toolkit template not specified')
| |||||||||||||||||||||||||||||||||||||||
| 58 | 4 | ▶ | my $tt2data = $self->{data} || {}; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'data'} || {}
MC/DC0%0/1
$self->{'data'} || {}
$self->{'data'}
Truth table50%1/2
A
A= $self->{'data'}
| |||||||||||||||||||||||||||||||||||||||
| 59 | 4 | my $tt2var = $self->{variable}; # optional var for nesting | |||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | if ($tt2var) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 62 | 4 | $tt2data->{$tt2var} = $tvar; | |||||||||||||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $tt2data = { %$tt2data, %$tvar }; | |||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||
| 66 | 4 | my $tt2output; # growing a scalar is so C-ish | |||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | $self->{engine}->process($tt2template, $tt2data, \$tt2output) | ||||||||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | || puke $self->{engine}->error(); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | # string HTML output | ||||||||||||||||||||||||||||||||||||||
| 72 | 4 | return $tt2output; | |||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||||||||||||