| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $encoding = $args{'encoding'}; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ( defined $encoding ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $encoder = Encode::find_encoding( $encoding ); | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if ( ! $encoder ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ( ! blessed $context || ! $context->isa( 'GX::Context' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($context) and $context->isa("GX::Context")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | complain "Invalid argument (\"context\" must be a GX::Context object)"; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ( defined $parameters ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ( ! ref $parameters eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | complain "Invalid argument (\"parameters\" must be hash reference)"; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ( defined $options ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ( ! ref $options eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $$content = $encoder->encode( $$content ); | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | GX::Exception->complain( | |||||||||||||||||||||||||||||||||||||||||
| 238 | message => "Render error", | ||||||||||||||||||||||||||||||||||||||||||
| 239 | subexception => $@ | ||||||||||||||||||||||||||||||||||||||||||
| 240 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ( defined wantarray ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | return $$content; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if ( ! defined $context ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if ( defined $content_type ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if ( $encoder && substr( $content_type, 0, 5 ) eq 'text/' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$encoder and substr($content_type, 0, 5) eq "text/"
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/"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $directory and -d $directory
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
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 2 | ▶ | if ( $self->file_extensions ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
-f $_ and -r $_ and /$file_regex/
-f $_ and -r $_
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/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $directory and "File::Spec"->file_name_is_absolute($directory)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$templates->{$template} ||= {"file", $file, "content_type", $template =~ /[^.]+\.([^.]+)\.[^.]+$/ ? GX::MIME::Util::format_to_mime_type($1) : undef}
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}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $self->_set_default_encoding( $application->default_encoding ); | |||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | if ( ! defined $self->_get_template_encoding ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $self->_set_template_encoding( $application->default_encoding ); | |||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | if ( defined $self->_get_templates_directory ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if ( ! File::Spec->file_name_is_absolute( $self->_get_templates_directory ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my $base_path = $application->path( 'base' ); | |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | if ( defined $base_path ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 2 | my $content_type = delete $args->{'default_content_type'}; | |||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 2 | ▶ | if ( defined $content_type ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 2 | ▶ | if ( $content_type !~ GX::MIME::Util::REGEX_MIME_TYPE ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 2 | my $encoding = delete $args->{'default_encoding'}; | |||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | 2 | ▶ | if ( defined $encoding ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | my $encoder = Encode::find_encoding( $encoding ); | |||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 2 | ▶ | if ( ! $encoder ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 3 | my $file_extensions = delete $args->{'file_extensions'}; | |||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 3 | ▶ | if ( ref $file_extensions ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 2 | my $options = delete $args->{'options'}; | |||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 2 | ▶ | if ( ref $options ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 2 | ▶ | $self->_get_config->{'preload'} = delete $args->{'preload'} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 3 | ▶ | if ( exists $args->{'template_encoding'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | 2 | my $encoding = delete $args->{'template_encoding'}; | |||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 2 | ▶ | if ( defined $encoding ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 2 | my $encoder = Encode::find_encoding( $encoding ); | |||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 2 | ▶ | if ( ! $encoder ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 3 | my $directory = delete $args->{'templates_directory'}; | |||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 3 | ▶ | if ( defined $directory ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | $self->_preload_templates; | |||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | __END__ | ||||||||||||||||||||||||||||||||||||||||||