GX/View/Template.pm

filter: Statementstmt 57.5% 122 / 212 Branchbran 29.8% 31 / 104 Conditioncond 39.1% 9 / 23 MC/DCmcdc 21.4% 3 / 14 Subroutinesub 75.7% 25 / 33 Podpod 100% 9 / 9 totaltotal 50.3% 199 / 395 CC 63 SCAR 50.8
CC
63
Cov
48%
render
600.0
_register
42.0
_setup_config
21.1
CRAP 160.4
« GX/Controller.pm ↑ Summary GX/SQL/Builder.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/View/Template.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::View::Template;
7  
8 5 ▶use GX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use GX::MIME::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use File::Spec::Unix ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 # ----------------------------------------------------------------------------------------------------------------------
19 # Constants
20 # ----------------------------------------------------------------------------------------------------------------------
21  
22 5 ▶use constant UNIX_PATHS => ( $File::Spec::ISA[0] eq 'File::Spec::Unix' ) ? 1 : 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$File::Spec::ISA[0] eq 'File::Spec::Unix' ? : 5 0 5
23  
24  
25 # ----------------------------------------------------------------------------------------------------------------------
26 # Class setup
27 # ----------------------------------------------------------------------------------------------------------------------
28  
29 5 ▶use GX::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 5 extends 'GX::View';
32  
33 5 has 'default_content_type' => (
34 isa => 'Scalar',
35 initialize => 1,
36 accessors => {
37 '_get_default_content_type' => { type => 'get' },
38 '_set_default_content_type' => { type => 'set' }
39 }
40 );
41  
42 5 has 'default_encoding' => (
43 isa => 'Scalar',
44 initialize => 1,
45 accessors => {
46 '_get_default_encoding' => { type => 'get' },
47 '_set_default_encoding' => { type => 'set' }
48 }
49 );
50  
51 5 has 'file_extensions' => (
52 isa => 'Array',
53 initialize => 1,
54 initializer => '_initialize_file_extensions',
55 accessors => {
56 '_get_file_extensions' => { type => 'get_reference' }
57 }
58 );
59  
60 5 has 'options' => (
61 isa => 'Hash',
62 initialize => 1,
63 initializer => '_initialize_options',
64 accessors => {
65 '_get_options' => { type => 'get_reference' }
66 }
67 );
68  
69 5 has 'template_encoding' => (
70 isa => 'Scalar',
71 initialize => 1,
72 accessors => {
73 '_get_template_encoding' => { type => 'get' },
74 '_set_template_encoding' => { type => 'set' }
75 }
76 );
77  
78 5 has 'templates' => (
79 isa => 'Hash',
80 initialize => 1,
81 accessors => {
82 '_get_templates' => { type => 'get_reference' }
83 }
84 );
85  
86 5 has 'templates_directory' => (
87 isa => 'Scalar',
88 initialize => 1,
89 accessors => {
90 '_get_templates_directory' => { type => 'get' },
91 '_set_templates_directory' => { type => 'set' }
92 }
93 );
94  
95 5 build;
96  
97  
98 # ----------------------------------------------------------------------------------------------------------------------
99 # Export mechanism
100 # ----------------------------------------------------------------------------------------------------------------------
101  
102 5 __PACKAGE__->_install_import_method;
103  
104  
105 # ----------------------------------------------------------------------------------------------------------------------
106 # Public methods
107 # ----------------------------------------------------------------------------------------------------------------------
108  
109 3 ▶sub default_content_type {
Subroutine default_content_type: called CC=1 SCAR=0.0
Pod documented
110  
111 3 return $_[0]->instance->_get_default_content_type;
112  
113 }
114  
115 3 ▶sub default_encoding {
Subroutine default_encoding: called CC=1 SCAR=0.0
Pod documented
116  
117 3 return $_[0]->instance->_get_default_encoding;
118  
119 }
120  
121 7 ▶sub file_extensions {
Subroutine file_extensions: called CC=1 SCAR=0.0
Pod documented
122  
123 7 return @{$_[0]->instance->_get_file_extensions};
124  
125 }
126  
127 3 ▶sub options {
Subroutine options: called CC=1 SCAR=0.0
Pod documented
128  
129 3 return %{$_[0]->instance->_get_options};
130  
131 }
132  
133 0 ▶sub preloaded_templates {
Subroutine preloaded_templates: not called CC=1 SCAR=6.9
Pod documented
134  
135 0 my $self = shift->instance;
136  
137 0 my $templates = $self->_get_templates;
138  
139 0 return grep { $templates->{$_}{'preloaded'} } keys %$templates;
140  
141 }
142  
143 0 ▶sub render {
Subroutine render: not called CC=24 SCAR=64.0
Pod documented
144  
145 0 my $self = shift->instance;
146 0 my %args = @_;
147  
148 0 ▶ if ( ! defined $args{'template'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"template"}) 0 0 0
149 0 complain "Missing argument (\"template\")";
150 }
151  
152 0 my $template_info = $self->_get_templates->{$args{'template'}};
153  
154 0 ▶ if ( ! $template_info ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($template_info) 0 0 0
155 0 complain "Unknown template \"$args{'template'}\"";
156 }
157  
158 0 my $encoding;
159 my $encoder;
160  
161 0 ▶ if ( exists $args{'encoding'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'encoding'}) { } 0 0 0
162  
163 0 $encoding = $args{'encoding'};
164  
165 0 ▶ if ( defined $encoding ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $encoding) 0 0 0
166  
167 0 $encoder = Encode::find_encoding( $encoding );
168  
169 0 ▶ if ( ! $encoder ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($encoder) 0 0 0
170 0 complain "Unsupported output encoding \"$encoding\"";
171 }
172  
173 }
174  
175 }
176 else {
177  
178 0 $encoding = $self->_get_default_encoding;
179  
180 0 ▶ if ( defined $encoding ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $encoding) 0 0 0
181 0 $encoder = Encode::find_encoding( $encoding );
182 }
183  
184 }
185  
186 0 my $context = $args{'context'};
187 0 my $parameters = $args{'parameters'};
188 0 my $options = $args{'options'};
189  
190 0 ▶ if ( defined $context ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context) 0 0 0
191  
192 0 ▶ if ( ! blessed $context || ! $context->isa( 'GX::Context' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($context) and $context->isa("GX::Context")) 0 0 0
Condition0%0/3
builtin::blessed($context) and $context->isa("GX::Context")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($context) and $context->isa("GX::Context")
builtin::blessed($context) $context->isa("GX::Context")
Truth table0%0/3
A and B
A= builtin::blessed($context)B= $context->isa("GX::Context")
ABresult
0X0
100
111
193 0 complain "Invalid argument (\"context\" must be a GX::Context object)";
194 }
195  
196 }
197  
198 0 ▶ if ( defined $parameters ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parameters) 0 0 0
199  
200 0 ▶ if ( ! ref $parameters eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ref($parameters) eq "HASH") 0 0 0
201 0 complain "Invalid argument (\"parameters\" must be hash reference)";
202 }
203  
204 }
205  
206 0 ▶ if ( defined $options ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options) 0 0 0
207  
208 0 ▶ if ( ! ref $options eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ref($options) eq "HASH") 0 0 0
209 0 complain "Invalid argument (\"options\" must be hash reference)";
210 }
211  
212 }
213  
214 0 my $content;
215  
216 0 eval {
217  
218 $content = $self->_process_template_file(
219 0 ▶ $template_info->{'file'},
Branch: 1 branch
BranchTrueFalseTotal
$encoder ? : 0 0 0
220 $self->_preprocess_template_parameters(
221 $context,
222 $parameters,
223 {
224 'output_charset' => ( $encoder ? $encoder->mime_name : undef )
225 }
226 ),
227 $options
228 );
229  
230 0 ▶ if ( $encoder ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoder) 0 0 0
231 0 $$content = $encoder->encode( $$content );
232 }
233  
234 };
235  
236 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
237 0 GX::Exception->complain(
238 message => "Render error",
239 subexception => $@
240 );
241 }
242  
243 0 ▶ if ( defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 0 0 0
244 0 return $$content;
245 }
246  
247 0 ▶ if ( ! defined $context ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $context) 0 0 0
248 0 complain "Missing argument (\"context\")";
249 }
250  
251 0 my $response = $context->response;
252  
253 0 ▶ if ( ! defined $response->content_type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response->content_type) 0 0 0
254  
255 0 ▶ my $content_type = $template_info->{'content_type'} // $self->_get_default_content_type;
Condition0%0/3
$template_info->{"content_type"} // $self->_get_default_content_type
l!l&&r!l&&!r
000
MC/DC0%0/2
$template_info->{"content_type"} // $self->_get_default_content_type
$template_info->{"content_type"} $self->_get_default_content_type
Truth table0%0/3
A // B
A= $template_info->{"content_type"}B= $self->_get_default_content_type
ABresult
1X1
011
000
256  
257 0 ▶ if ( defined $content_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content_type) 0 0 0
258  
259 0 ▶ if ( $encoder && substr( $content_type, 0, 5 ) eq 'text/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoder and substr($content_type, 0, 5) eq "text/") 0 0 0
Condition0%0/3
$encoder and substr($content_type, 0, 5) eq "text/"
!ll&&!rl&&r
000
MC/DC0%0/2
$encoder and substr($content_type, 0, 5) eq "text/"
$encoder substr($content_type, 0, 5) eq "text/"
Truth table0%0/3
A and B
A= $encoderB= substr($content_type, 0, 5) eq "text/"
ABresult
0X0
100
111
260 0 $content_type .= '; charset=' . $encoder->mime_name;
261 }
262  
263 0 $response->content_type( $content_type );
264  
265 }
266  
267 }
268  
269 0 $response->add( $content );
270  
271 0 return;
272  
273 }
274  
275 3 ▶sub template_encoding {
Subroutine template_encoding: called CC=1 SCAR=0.0
Pod documented
276  
277 3 return $_[0]->instance->_get_template_encoding;
278  
279 }
280  
281 1 ▶sub templates {
Subroutine templates: called CC=1 SCAR=0.0
Pod documented
282  
283 1 return keys %{$_[0]->instance->_get_templates};
284  
285 }
286  
287 3 ▶sub templates_directory {
Subroutine templates_directory: called CC=1 SCAR=0.0
Pod documented
288  
289 3 return $_[0]->instance->_get_templates_directory;
290  
291 }
292  
293  
294 # ----------------------------------------------------------------------------------------------------------------------
295 # Private methods
296 # ----------------------------------------------------------------------------------------------------------------------
297  
298 30 ▶sub _canonicalize_template_name {
Subroutine _canonicalize_template_name: called CC=1 SCAR=0.0
299  
300 30 my $self = shift;
301 30 my $template = shift;
302  
303 30 $template = File::Spec->canonpath( $template );
304  
305 30 if ( ! UNIX_PATHS ) {
306  
307 my @path = File::Spec->splitpath( $template );
308  
309 $template = File::Spec::Unix->catfile(
310 File::Spec->splitdir( $path[1] ),
311 $path[2]
312 );
313  
314 }
315  
316 30 return $template;
317  
318 }
319  
320 3 ▶sub _find_template_files {
Subroutine _find_template_files: called CC=4 SCAR=13.9
321  
322 3 my $self = shift;
323 3 my $directory = shift;
324  
325 3 my @files;
326  
327 3 ▶ if ( defined $directory && -d $directory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $directory and -d $directory) 2 1 3
Condition66%2/3
defined $directory and -d $directory
!ll&&!rl&&r
012
MC/DC50%1/2
defined $directory and -d $directory
defined $directory -d $directory
Truth table66%2/3
A and B
A= defined $directoryB= -d $directory
ABresult
0X0
100
111
328  
329 2 ▶ if ( $self->file_extensions ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->file_extensions) 2 0 2
330  
331 2 my $file_regex = do {
332 2 my $pattern = '[^.]+\.(?:' . join( '|', map { quotemeta } $self->file_extensions ) . ')$';
333 2 qr/$pattern/;
334 };
335  
336 File::Find::find(
337 {
338 50 ▶ 'wanted' => sub { push @files, $_ if -f && -r && /$file_regex/ },
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
if -f $_ and -r $_ and /$file_regex/ 30 20 50
Condition83%5/6
-f $_ and -r $_ and /$file_regex/
!ll&&!rl&&r
101030
-f $_ and -r $_
!ll&&!rl&&r
10040
MC/DC66%2/3
-f $_ and -r $_ and /$file_regex/
-f $_ -r $_ /$file_regex/
Truth table75%3/4
A and B and C
A= -f $_B= -r $_C= /$file_regex/
ABCresult
0XX0
10X0
1100
1111
339 2 'no_chdir' => 1
340 },
341 $directory
342 );
343  
344 }
345  
346 }
347  
348 3 return @files;
349  
350 }
351  
352 3 ▶sub _index_templates {
Subroutine _index_templates: called CC=6 SCAR=18.7
353  
354 3 my $self = shift;
355  
356 3 my $directory = $self->_get_templates_directory;
357  
358 3 ▶ return unless defined $directory && File::Spec->file_name_is_absolute( $directory );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $directory and "File::Spec"->file_name_is_absolute($directory) 0 3 3
Condition33%1/3
defined $directory and "File::Spec"->file_name_is_absolute($directory)
!ll&&!rl&&r
003
MC/DC0%0/2
defined $directory and "File::Spec"->file_name_is_absolute($directory)
defined $directory "File::Spec"->file_name_is_absolute($directory)
Truth table33%1/3
A and B
A= defined $directoryB= "File::Spec"->file_name_is_absolute($directory)
ABresult
0X0
100
111
359  
360 3 my $templates = $self->_get_templates;
361  
362 3 for my $file ( $self->_find_template_files( $directory ) ) {
363  
364 30 my $template = $self->_canonicalize_template_name( File::Spec->abs2rel( $file, $directory ) );
365  
366 30 ▶ $templates->{$template} ||= {
Branch: 1 branch
BranchTrueFalseTotal
$template =~ /[^.]+\.([^.]+)\.[^.]+$/ ? : 6 24 30
Condition50%1/2
$templates->{$template} ||= {"file", $file, "content_type", $template =~ /[^.]+\.([^.]+)\.[^.]+$/ ? GX::MIME::Util::format_to_mime_type($1) : undef}
l!l
030
MC/DC0%0/1
$templates->{$template} ||= {"file", $file, "content_type", $template =~ /[^.]+\.([^.]+)\.[^.]+$/ ? GX::MIME::Util::format_to_mime_type($1) : undef}
$templates->{$template}
Truth table50%1/2
A
A= $templates->{$template}
Aresult
11
00
367 'file' => $file,
368 'content_type' => (
369 $template =~ /[^.]+\.([^.]+)\.[^.]+$/ ? GX::MIME::Util::format_to_mime_type( $1 ) : undef
370 )
371 };
372  
373 }
374  
375 3 return;
376  
377 }
378  
379 3 ▶sub _initialize_config {
Subroutine _initialize_config: called CC=1 SCAR=0.0
380  
381 return {
382 3 'preload' => 1
383 };
384  
385 }
386  
387 2 ▶sub _initialize_file_extensions {
Subroutine _initialize_file_extensions: called CC=1 SCAR=0.0
388  
389 2 return [];
390  
391 }
392  
393 2 ▶sub _initialize_options {
Subroutine _initialize_options: called CC=1 SCAR=0.0
394  
395 2 return {};
396  
397 }
398  
399 0 ▶sub _preload_template_file {
Subroutine _preload_template_file: not called CC=1 SCAR=0.0
400  
401 # Abstract method
402  
403 }
404  
405 0 ▶sub _preload_templates {
Subroutine _preload_templates: not called CC=2 SCAR=17.9
406  
407 0 my $self = shift;
408  
409 0 my $templates = $self->_get_templates;
410  
411 0 for my $template ( keys %$templates ) {
412 0 $self->_preload_template_file( $templates->{$template}{'file'} );
413 0 $templates->{$template}{'preloaded'} = 1;
414 }
415  
416 0 return;
417  
418 }
419  
420 0 ▶sub _preprocess_template_parameters {
Subroutine _preprocess_template_parameters: not called CC=4 SCAR=30.0
421  
422 0 my $self = shift;
423 0 my $context = shift;
424 0 my $parameters = shift;
425 0 my $static_parameters = shift;
426  
427 return {
428 0 ▶ ( $context ? ( %{$context->stash}, 'context' => $context ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
$context ? : 0 0 0
$static_parameters ? : 0 0 0
$parameters ? : 0 0 0
429 ( $static_parameters ? %$static_parameters : () ),
430 ( $parameters ? %$parameters : () )
431 };
432  
433 }
434  
435 0 ▶sub _process_template_file {
Subroutine _process_template_file: not called CC=1 SCAR=0.0
436  
437 # Abstract method
438  
439 }
440  
441 0 ▶sub _register {
Subroutine _register: not called CC=6 SCAR=37.4
442  
443 0 my $self = shift;
444 0 my $application = shift;
445  
446 0 $self->SUPER::_register( $application );
447  
448 0 ▶ if ( ! defined $self->_get_default_encoding ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->_get_default_encoding) 0 0 0
449 0 $self->_set_default_encoding( $application->default_encoding );
450 }
451  
452 0 ▶ if ( ! defined $self->_get_template_encoding ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->_get_template_encoding) 0 0 0
453 0 $self->_set_template_encoding( $application->default_encoding );
454 }
455  
456 0 ▶ if ( defined $self->_get_templates_directory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_get_templates_directory) { } 0 0 0
457  
458 0 ▶ if ( ! File::Spec->file_name_is_absolute( $self->_get_templates_directory ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($self->_get_templates_directory)) 0 0 0
459  
460 0 my $base_path = $application->path( 'base' );
461  
462 0 ▶ if ( defined $base_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $base_path) 0 0 0
463 0 $self->_set_templates_directory( File::Spec->rel2abs( $self->_get_templates_directory, $base_path ) );
464 }
465  
466 }
467  
468 }
469 else {
470 0 $self->_set_templates_directory( $application->path( 'templates' ) );
471 }
472  
473 0 $self->_index_templates;
474  
475 0 return;
476  
477 }
478  
479 3 ▶sub _setup {
Subroutine _setup: called CC=1 SCAR=0.0
480  
481 3 my $self = shift;
482 3 my $config = shift;
483  
484 3 $self->SUPER::_setup( $config );
485  
486 3 $self->_index_templates;
487  
488 3 return;
489  
490 }
491  
492 3 ▶sub _setup_config {
Subroutine _setup_config: called CC=18 SCAR=30.5
493  
494 3 my $self = shift;
495 3 my $args = shift;
496  
497 3 ▶ if ( exists $args->{'default_content_type'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"default_content_type"}) 2 1 3
498  
499 2 my $content_type = delete $args->{'default_content_type'};
500  
501 2 ▶ if ( defined $content_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content_type) 2 0 2
502  
503 2 ▶ if ( $content_type !~ GX::MIME::Util::REGEX_MIME_TYPE ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content_type =~ m[^[\w\+\-\.]+/[\w\+\-\.]+$]) 0 2 2
504 0 throw "Invalid option (\"default_content_type\" must be a valid MIME type)";
505 }
506  
507 2 $self->_set_default_content_type( $content_type );
508  
509 }
510  
511 }
512  
513 3 ▶ if ( exists $args->{'default_encoding'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"default_encoding"}) 2 1 3
514  
515 2 my $encoding = delete $args->{'default_encoding'};
516  
517 2 ▶ if ( defined $encoding ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $encoding) 2 0 2
518  
519 2 my $encoder = Encode::find_encoding( $encoding );
520  
521 2 ▶ if ( ! $encoder ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($encoder) 0 2 2
522 0 throw "Unsupported default encoding \"$encoding\"";
523 }
524  
525 2 $self->_set_default_encoding( $encoder->name );
526  
527 }
528  
529 }
530  
531 3 ▶ if ( exists $args->{'file_extensions'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"file_extensions"}) 3 0 3
532  
533 3 my $file_extensions = delete $args->{'file_extensions'};
534  
535 3 ▶ if ( ref $file_extensions ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file_extensions ne "ARRAY") 0 3 3
536 0 throw "Invalid option (\"file_extensions\" must be an array reference)";
537 }
538  
539 3 @{$self->_get_file_extensions} = map { $_ =~ s/^\.//; $_ } grep { defined } @$file_extensions;
540  
541 }
542  
543 3 ▶ if ( exists $args->{'options'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"options"}) 2 1 3
544  
545 2 my $options = delete $args->{'options'};
546  
547 2 ▶ if ( ref $options ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $options ne "HASH") 0 2 2
548 0 throw "Invalid option (\"options\" must be a hash reference)";
549 }
550  
551 2 %{$self->_get_options} = ( %{$self->_get_options}, %$options );
552  
553 }
554  
555 3 ▶ if ( exists $args->{'preload'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"preload"}) 2 1 3
556 2 ▶ $self->_get_config->{'preload'} = delete $args->{'preload'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $args->{'preload'} ? : 0 2 2
557 }
558  
559 3 ▶ if ( exists $args->{'template_encoding'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"template_encoding"}) 2 1 3
560  
561 2 my $encoding = delete $args->{'template_encoding'};
562  
563 2 ▶ if ( defined $encoding ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $encoding) 2 0 2
564  
565 2 my $encoder = Encode::find_encoding( $encoding );
566  
567 2 ▶ if ( ! $encoder ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($encoder) 0 2 2
568 0 throw "Unsupported template encoding \"$encoding\"";
569 }
570  
571 2 $self->_set_template_encoding( $encoder->name );
572  
573 }
574  
575 }
576  
577 3 ▶ if ( exists $args->{'templates_directory'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"templates_directory"}) 3 0 3
578  
579 3 my $directory = delete $args->{'templates_directory'};
580  
581 3 ▶ if ( defined $directory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $directory) 3 0 3
582 3 $self->_set_templates_directory( File::Spec->canonpath( $directory ) );
583 }
584  
585 }
586  
587 3 $self->SUPER::_setup_config( $args );
588  
589 3 return;
590  
591 }
592  
593 0 ▶sub _start {
Subroutine _start: not called CC=2 SCAR=17.9
594  
595 0 my $self = shift;
596  
597 0 $self->SUPER::_start;
598  
599 0 ▶ if ( $self->_get_config->{'preload'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_config->{"preload"}) 0 0 0
600 0 $self->_preload_templates;
601 }
602  
603 0 return;
604  
605 }
606  
607  
608 5 1;
609  
610 __END__
« GX/Controller.pm ↑ Summary GX/SQL/Builder.pm »