lib/CGI/FormBuilder/Template/TT2.pm

filter: Statementstmt 94.5% 35 / 37 Branchbran 50.0% 3 / 6 Conditioncond 37.5% 6 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 88.8% 8 / 9 Podpod 66.6% 2 / 3 totaltotal 66.6% 54 / 81 SCAR 24.5
CC
10
Cov
75%
render
7.5
new
6.6
engine
2.0
CRAP 11.6
« blib/lib/CGI/FormBuilder/Template/TT2.pm ↑ Summary blib/lib/CGI/FormBuilder/Field/file.pm »
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
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless UNIVERSAL::isa($opt->{"engine"}, "Template") 4 0 4
Condition40%2/5
'Template'->new($opt->{'engine'} || {}) || &puke($Template::ERROR)
l!l&&r!l&&!r
400
$opt->{'engine'} || {}
l!l
04
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)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $opt->{'engine'}
Aresult
11
00
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?)')
l!l&&r!l&&!r
400
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?)')
ABresult
1X1
011
000
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')
l!l&&r!l&&!r
400
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')
ABresult
1X1
011
000
58 4 ▶ my $tt2data = $self->{data} || {};
Condition50%1/2
$self->{'data'} || {}
l!l
04
MC/DC0%0/1
$self->{'data'} || {}
$self->{'data'}
Truth table50%1/2
A
A= $self->{'data'}
Aresult
11
00
59 4 my $tt2var = $self->{variable}; # optional var for nesting
60  
61 4 ▶ if ($tt2var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tt2var) { } 4 0 4
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
BranchTrueFalseTotal
$self->{"engine"}->process($tt2template, $tt2data, \$tt2output) or &puke($self->{"engine"}->error) 0 4 4
70  
71 # string HTML output
72 4 return $tt2output;
73 }
74  
75 1 1;
76 __END__
« blib/lib/CGI/FormBuilder/Template/TT2.pm ↑ Summary blib/lib/CGI/FormBuilder/Field/file.pm »