| 1 | package CGI::Builder::HTMLtmpl ; | ||||||||||||||||||||
| 2 | 1 | $VERSION = 1.21 ; | |||||||||||||||||||
| 3 | 1 | ▶ | use strict ; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | # This file uses the "Perlish" coding style | ||||||||||||||||||||
| 6 | # please read http://perl.4pro.net/perlish_coding_style.html | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | ; use HTML::Template | ||||||||||||||||||||
| 9 | 1 | ▶ | ; use File::Spec | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | ; $Carp::Internal{'HTML::Template'}++ | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ; $Carp::Internal{+__PACKAGE__}++ | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | ; my $print_code | |||||||||||||||||||
| 14 | ; BEGIN | ||||||||||||||||||||
| 15 | 6 | ▶ | { $print_code = sub{ shift()->CGI::Builder::HTMLtmpl::_::ht_print(@_) } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 1 | } | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | ; use Object::props | ||||||||||||||||||||
| 19 | 1 | ▶ | ( { name => 'ht' | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 6 | ▶ | , default => sub{ shift()->ht_new(@_) } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | , { name => 'page_suffix' | ||||||||||||||||||||
| 23 | , default => '.tmpl' | ||||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | , { name => 'page_content' | ||||||||||||||||||||
| 26 | 6 | ▶ | , default => sub{ $print_code } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | ) | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 1 | ▶ | ; use Object::groups qw| ht_new_args ht_param | | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | ; sub ht_new | |||||||||||||||||||
| 33 | 6 | ▶ | { my $s = shift | ||||||||||||||||||
|
Subroutine
ht_new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 34 | ; HTML::Template->new( filename => $s->page_name . $s->page_suffix | ||||||||||||||||||||
| 35 | , path => [ $s->page_path ] | ||||||||||||||||||||
| 36 | 6 | , %{$s->ht_new_args} | |||||||||||||||||||
| 37 | ) | ||||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | ; sub page_content_check | ||||||||||||||||||||
| 41 | 9 | ▶ | { my $s = shift | ||||||||||||||||||
|
Subroutine
page_content_check: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 42 | 9 | ▶ | ; $s->page_content eq $print_code # managed by ht | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | ? $s->CGI::Builder::HTMLtmpl::_::ht_exists | ||||||||||||||||||||
| 44 | : $s->CGI::Builder::page_content_check | ||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | ; sub CGI::Builder::HTMLtmpl::_::ht_print | ||||||||||||||||||||
| 48 | 6 | ▶ | { my $s = shift | ||||||||||||||||||
|
Subroutine
ht_print: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 49 | 6 | ; $s->ht->param( %{$s->ht_param} ) | |||||||||||||||||||
| 50 | 6 | ; print $s->ht->output() | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | # adapted from HTML::Template::_find_file | ||||||||||||||||||||
| 54 | # it implements the same logic | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | ; sub CGI::Builder::HTMLtmpl::_::ht_exists | ||||||||||||||||||||
| 57 | 9 | ▶ | { my $s = shift | ||||||||||||||||||
|
Subroutine
ht_exists: called CC=13 SCAR=32.7
| |||||||||||||||||||||
| 58 | ; my $filename = $$s{ht_new_args}{filename} | ||||||||||||||||||||
| 59 | 9 | ▶ | || $s->page_name.$s->page_suffix | ||||||||||||||||||
|
Condition66%2/3
$s->{'ht_new_args'}{'filename'} || $s->page_name . $s->page_suffix
MC/DC0%0/2
$s->{'ht_new_args'}{'filename'} || $s->page_name . $s->page_suffix
$s->{'ht_new_args'}{'filename'}
$s->page_name . $s->page_suffix
Truth table66%2/3
A || B
A= $s->{'ht_new_args'}{'filename'}B= $s->page_name . $s->page_suffix
| |||||||||||||||||||||
| 60 | ; my $path = $$s{ht_new_args}{path} | ||||||||||||||||||||
| 61 | 9 | ▶ | || [ $s->page_path ] | ||||||||||||||||||
|
Condition100%2/2
$s->{'ht_new_args'}{'path'} || [$s->page_path]
MC/DC100%1/1
$s->{'ht_new_args'}{'path'} || [$s->page_path]
$s->{'ht_new_args'}{'path'}
Truth table100%2/2
A
A= $s->{'ht_new_args'}{'path'}
| |||||||||||||||||||||
| 62 | # first check for a full path | ||||||||||||||||||||
| 63 | 9 | ▶ | ; if ( File::Spec->file_name_is_absolute( $filename ) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | ▶ | { return 1 if -e $filename | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | # try pre-prending HTML_Template_Root | ||||||||||||||||||||
| 67 | 9 | ▶ | ; if ( exists $ENV{HTML_TEMPLATE_ROOT} ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | { return 1 if -e File::Spec->catfile( $ENV{HTML_TEMPLATE_ROOT} | ||||||||||||||||||||
| 69 | 0 | ▶ | , $filename | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | ) | ||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | # try "path" option list.. | ||||||||||||||||||||
| 73 | 9 | ; foreach my $p ( @$path ) | |||||||||||||||||||
| 74 | 9 | ▶ | { return 1 if -e File::Spec->catfile( $p | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | , $filename | ||||||||||||||||||||
| 76 | ) | ||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | # try even a relative path from the current directory... | ||||||||||||||||||||
| 79 | 1 | ▶ | ; return 1 if -e $filename | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | # try "path" option list with HTML_TEMPLATE_ROOT prepended... | ||||||||||||||||||||
| 81 | 1 | ▶ | ; if ( exists $ENV{HTML_TEMPLATE_ROOT} ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 0 | { foreach my $p ( @$path ) | |||||||||||||||||||
| 83 | { return 1 if -e File::Spec->catfile( $ENV{HTML_TEMPLATE_ROOT} | ||||||||||||||||||||
| 84 | 0 | ▶ | , $p | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | , $filename | ||||||||||||||||||||
| 86 | ) | ||||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | ; return undef | ||||||||||||||||||||
| 90 | 1 | } | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 1 | ; 1 | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||