GX/View/Template/TT.pm

filter: Statementstmt 33.3% 19 / 57 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 54.5% 6 / 11 Podpod n/a totaltotal 27.1% 25 / 92 CC 13 SCAR 28.5
CC
13
Cov
23%
_register
42.0
_process_template_file
20.0
_preload_template_file
12.0
CRAP 17.3
« GX/HTTP/Response/Cookie.pm ↑ Summary GX/Script.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/View/Template/TT.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::View::Template::TT;
7  
8 2 ▶use GX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Template ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 # ----------------------------------------------------------------------------------------------------------------------
15 # Class setup
16 # ----------------------------------------------------------------------------------------------------------------------
17  
18 2 ▶use GX::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 extends 'GX::View::Template';
21  
22 has 'tt' => (
23 isa => 'Scalar',
24 initialize => 1,
25 0 ▶ constraint => sub { blessed $_ && $_->isa( 'Template' ) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) and $_->isa("Template") 0 0 0
26 2 accessors => {
27 '_get_tt' => { type => 'get' },
28 '_set_tt' => { type => 'set' }
29 }
30 );
31  
32 2 build;
33  
34  
35 # ----------------------------------------------------------------------------------------------------------------------
36 # Export mechanism
37 # ----------------------------------------------------------------------------------------------------------------------
38  
39 2 __PACKAGE__->_install_import_method;
40  
41  
42 # ----------------------------------------------------------------------------------------------------------------------
43 # Private methods
44 # ----------------------------------------------------------------------------------------------------------------------
45  
46 0 ▶sub _create_tt {
Subroutine _create_tt: not called CC=2 SCAR=17.9
47  
48 0 my $self = shift;
49  
50 0 my $tt = eval { Template->new( %{$self->_get_options} ) };
51  
52 0 ▶ if ( ! $tt ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tt) 0 0 0
53 0 GX::Exception->throw(
54 message => "Cannot create the Template instance",
55 subexception => $@
56 );
57 }
58  
59 0 return $tt;
60  
61 }
62  
63 2 ▶sub _initialize_file_extensions {
Subroutine _initialize_file_extensions: called CC=1 SCAR=0.0
64  
65 2 return [ 'tt' ];
66  
67 }
68  
69 2 ▶sub _initialize_options {
Subroutine _initialize_options: called CC=1 SCAR=0.0
70  
71 return {
72 2 'ABSOLUTE' => 1,
73 'EVAL_PERL' => 0,
74 'RELATIVE' => 0,
75 'STAT_TTL' => 60 * 60 * 24 * 365 # disable cache check
76 };
77  
78 }
79  
80 0 ▶sub _preload_template_file {
Subroutine _preload_template_file: not called CC=3 SCAR=24.8
81  
82 0 my $self = shift;
83 0 my $file = shift;
84  
85 0 my $tt = $self->_get_tt;
86  
87 0 ▶ if ( ! $tt ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tt) 0 0 0
88 0 throw "No Template instance";
89 }
90  
91 0 ▶ $tt->process( $file, undef, \( my $result ) ) or throw $tt->error;
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($file, undef, \my $result) or &throw(scalar $tt->error) 0 0 0
92  
93 0 return;
94  
95 }
96  
97 0 ▶sub _process_template_file {
Subroutine _process_template_file: not called CC=4 SCAR=30.0
98  
99 0 my $self = shift;
100 0 my $file = shift;
101 0 my $parameters = shift;
102 0 my $options = shift;
103  
104 0 my $result = '';
105  
106 0 my $tt = $self->_get_tt;
107  
108 0 ▶ if ( ! $tt ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tt) 0 0 0
109 0 throw "No Template instance";
110 }
111  
112 0 ▶ $tt->process( $file, $parameters, \$result, ( $options ? $options : () ) ) or throw $tt->error;
Branch: 2 branches
BranchTrueFalseTotal
$tt->process($file, $parameters, \$result, $options ? $options : ()) or &throw(scalar $tt->error) 0 0 0
$options ? : 0 0 0
113  
114 0 return \$result;
115  
116 }
117  
118 0 ▶sub _register {
Subroutine _register: not called CC=6 SCAR=37.4
119  
120 0 my $self = shift;
121 0 my $application = shift;
122  
123 0 $self->SUPER::_register( $application );
124  
125 0 my $options = $self->_get_options;
126  
127 0 ▶ if ( ! exists $options->{'ENCODING'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options->{"ENCODING"}) 0 0 0
128  
129 0 ▶ if ( defined $self->_get_template_encoding ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_get_template_encoding) 0 0 0
130 0 $options->{'ENCODING'} = $self->_get_template_encoding;
131 }
132  
133 }
134  
135 0 ▶ if ( ! exists $options->{'INCLUDE_PATH'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options->{"INCLUDE_PATH"}) 0 0 0
136  
137 0 ▶ if ( defined $self->_get_templates_directory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_get_templates_directory) 0 0 0
138 0 $options->{'INCLUDE_PATH'} = $self->_get_templates_directory;
139 }
140  
141 }
142  
143 0 ▶ if ( ! $self->_get_tt ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_get_tt) 0 0 0
144 0 $self->_set_tt( $self->_create_tt );
145 }
146  
147 0 return;
148  
149 }
150  
151  
152 2 1;
153  
154 __END__
« GX/HTTP/Response/Cookie.pm ↑ Summary GX/Script.pm »