| 1 | #============================================================= -*-Perl-*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Template::View | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # A custom view of a template processing context. Can be used to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # implement custom "skins". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Andy Wardley <abw@kfs.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # Copyright (C) 2000-2022 Andy Wardley. All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # This module is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # TODO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # * allowing print to have a hash ref as final args will cause problems | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # if you do this: [% view.print(hash1, hash2, hash3) %]. Current | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # work-around is to do [% view.print(hash1); view.print(hash2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # view.print(hash3) %] or [% view.print(hash1, hash2, hash3, { }) %] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | #============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | package Template::View; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | use base 'Template::Base'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | our $VERSION = '3.106'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | ▶ | our $DEBUG = 0 unless defined $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | our @BASEARGS = qw( context ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | our $MAP = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | HASH => 'hash', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ARRAY => 'list', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | TEXT => 'text', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | default => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # _init(\%config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Initialisation method called by the Template::Base class new() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # constructor. $self->{ context } has already been set, by virtue of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # being named in @BASEARGS. Remaining config arguments are presented | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # as a hash reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 66 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 66 | my ($self, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # move 'context' somewhere more private | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 66 | $self->{ _CONTEXT } = $self->{ context }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 66 | delete $self->{ context }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # generate table mapping object types to templates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 66 | ▶ | my $map = $config->{ map } || { }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{'map'} || {}
MC/DC100%1/1
$config->{'map'} || {}
$config->{'map'}
Truth table100%2/2
A
A= $config->{'map'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 66 | ▶ | $map->{ default } //= $config->{ default }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$map->{"default"} //= $config->{"default"}
MC/DC100%2/2
$map->{"default"} //= $config->{"default"}
$map->{"default"}
$config->{"default"}
Truth table100%3/3
A //= B
A= $map->{"default"}B= $config->{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | $self->{ map } = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 66 | %$MAP, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | %$map, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # local BLOCKs definition table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 66 | ▶ | $self->{ _BLOCKS } = $config->{ blocks } || { }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{'blocks'} || {}
MC/DC100%1/1
$config->{'blocks'} || {}
$config->{'blocks'}
Truth table100%2/2
A
A= $config->{'blocks'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # name of presentation method which printed objects might provide | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 66 | ▶ | $self->{ method } = $config->{ method } // 'present'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{"method"} // "present"
MC/DC0%0/1
$config->{"method"} // "present"
$config->{"method"}
Truth table50%1/2
A
A= $config->{"method"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # view is sealed by default preventing variable update after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # definition, however we don't actually seal a view until the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # END of the view definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 66 | my $sealed = $config->{ sealed }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 66 | ▶ | $sealed //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$sealed //= 1
MC/DC100%1/1
$sealed //= 1
$sealed
Truth table100%2/2
A
A= $sealed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 66 | ▶ | $self->{ sealed } = $sealed ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # copy remaining config items from $config or set defaults | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 66 | foreach my $arg (qw( base prefix suffix notfound silent )) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 330 | ▶ | $self->{ $arg } = $config->{ $arg } || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{$arg} || ''
MC/DC100%1/1
$config->{$arg} || ''
$config->{$arg}
Truth table100%2/2
A
A= $config->{$arg}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # check that any base specified is defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | return $self->error('Invalid base specified for view') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 66 | ▶ | if exists $config->{ base } && ! $self->{ base }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $config->{"base"} and not $self->{"base"}
MC/DC100%2/2
exists $config->{"base"} and not $self->{"base"}
exists $config->{"base"}
not $self->{"base"}
Truth table100%3/3
A and not(B)
A= exists $config->{"base"}B= not $self->{"base"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # name of data item used by view() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 65 | ▶ | $self->{ item } = $config->{ item } || 'item'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{'item'} || 'item'
MC/DC100%1/1
$config->{'item'} || 'item'
$config->{'item'}
Truth table100%2/2
A
A= $config->{'item'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # map methods of form ${include_prefix}_foobar() to include('foobar')? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 65 | ▶ | $self->{ include_prefix } = $config->{ include_prefix } || 'include_'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'include_prefix'} || 'include_'
MC/DC0%0/1
$config->{'include_prefix'} || 'include_'
$config->{'include_prefix'}
Truth table50%1/2
A
A= $config->{'include_prefix'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # what about mapping foobar() to include('foobar')? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 65 | ▶ | $self->{ include_naked } = $config->{ include_naked } // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{"include_naked"} // 1
MC/DC100%1/1
$config->{"include_naked"} // 1
$config->{"include_naked"}
Truth table100%2/2
A
A= $config->{"include_naked"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # map methods of form ${view_prefix}_foobar() to include('foobar')? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 65 | ▶ | $self->{ view_prefix } = $config->{ view_prefix } || 'view_'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'view_prefix'} || 'view_'
MC/DC0%0/1
$config->{'view_prefix'} || 'view_'
$config->{'view_prefix'}
Truth table50%1/2
A
A= $config->{'view_prefix'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # what about mapping foobar() to view('foobar')? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 65 | ▶ | $self->{ view_naked } = $config->{ view_naked } || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{'view_naked'} || 0
MC/DC100%1/1
$config->{'view_naked'} || 0
$config->{'view_naked'}
Truth table100%2/2
A
A= $config->{'view_naked'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # the view is initially unsealed, allowing directives in the initial | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # view template to create data items via the AUTOLOAD; once sealed via | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # call to seal(), the AUTOLOAD will not update any internal items. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 65 | delete @$config{ qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | base method map default prefix suffix notfound item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | include_prefix include_naked silent sealed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | view_prefix view_naked blocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | $config = { %{ $self->{ base }->{ data } }, %$config } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 65 | ▶ | if $self->{ base }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 65 | $self->{ data } = $config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 65 | $self->{ SEALED } = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 65 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # seal() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # unseal() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # Seal or unseal the view to allow/prevent new data items from being | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # automatically created by the AUTOLOAD method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 63 | ▶ | sub seal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seal: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 63 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 63 | $self->{ SEALED } = $self->{ sealed }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub unseal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unseal: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $self->{ SEALED } = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # clone(\%config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # Cloning method which takes a copy of $self and then applies to it any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # modifications specified in the $config hash passed as an argument. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # Configuration items may also be specified as a list of "name => $value" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # arguments. Returns a reference to the cloned Template::View object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # NOTE: may need to copy BLOCKS??? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 13 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 13 | my $clone = bless { %$self }, ref $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 13 | ▶ | my $config = ref $_[0] eq 'HASH' ? shift : { @_ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # merge maps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | $clone->{ map } = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 13 | %{ $self->{ map } }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 13 | ▶ | %{ $config->{ map } || { } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'map'} || {}
MC/DC0%0/1
$config->{'map'} || {}
$config->{'map'}
Truth table50%1/2
A
A= $config->{'map'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # "map => { default=>'xxx' }" can be specified as "default => 'xxx'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | $clone->{ map }->{ default } = $config->{ default } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 13 | ▶ | if defined $config->{ default }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # update any remaining config items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 13 | my @args = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | base prefix suffix notfound item method include_prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | include_naked view_prefix view_naked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 13 | foreach my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 130 | ▶ | $clone->{ $arg } = $config->{ $arg } if defined $config->{ $arg }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 13 | push(@args, qw( default map )); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 13 | delete @$config{ @args }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # anything left is data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 13 | my $data = $clone->{ data } = { %{ $self->{ data } } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 13 | @$data{ keys %$config } = values %$config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 13 | return $clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # print(@items, ..., \%config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # Prints @items in turn by mapping each to an appropriate template using | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # the internal 'map' hash. If an entry isn't found and the item is an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # object that implements the method named in the internal 'method' item, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # (default: 'present'), then the method will be called passing a reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # to $self, against which the presenter method may make callbacks (e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # to view_item()). If the presenter method isn't implemented, then the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # 'default' map entry is consulted and used if defined. The final argument | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # may be a reference to a hash array providing local overrides to the internal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # defaults for various items (prefix, suffix, etc). In the presence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # of this parameter, a clone of the current object is first made, applying | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # any configuration updates, and control is then delegated to it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 43 | ▶ | sub print { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=20 SCAR=33.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 43 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # if final config hash is specified then create a clone and delegate to it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # NOTE: potential problem when called print(\%data_hash1, \%data_hash2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 43 | ▶ | if ((scalar @_ > 1) && (ref $_[-1] eq 'HASH')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @_ > 1 and ref $_[-1] eq "HASH"
MC/DC50%1/2
scalar @_ > 1 and ref $_[-1] eq "HASH"
scalar @_ > 1
ref $_[-1] eq "HASH"
Truth table66%2/3
A and B
A= scalar @_ > 1B= ref $_[-1] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 5 | my $cfg = pop @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 5 | ▶ | my $clone = $self->clone($cfg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->clone($cfg) || (return)
MC/DC0%0/1
$self->clone($cfg) || (return)
$self->clone($cfg)
Truth table50%1/2
A
A= $self->clone($cfg)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 5 | ▶ | return $clone->print(@_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$clone->print(@_) || $self->error($clone->error)
MC/DC0%0/2
$clone->print(@_) || $self->error($clone->error)
$clone->print(@_)
$self->error($clone->error)
Truth table33%1/3
A || B
A= $clone->print(@_)B= $self->error($clone->error)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | || $self->error($clone->error()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 38 | my ($item, $type, $template, $present); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 38 | my $method = $self->{ method }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 38 | my $map = $self->{ map }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 38 | my $output = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # print each argument | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 38 | foreach $item (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 38 | my $newtype; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 38 | ▶ | if (! ($type = ref $item)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # non-references are TEXT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 9 | $type = 'TEXT'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 9 | $template = $map->{ $type }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | elsif (! defined ($template = $map->{ $type })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # no specific map entry for object, maybe it implements a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # 'present' (or other) method? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 18 | ▶ | if ( $method && UNIVERSAL::can($item, $method) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$method and UNIVERSAL::can($item, $method)
MC/DC50%1/2
$method and UNIVERSAL::can($item, $method)
$method
UNIVERSAL::can($item, $method)
Truth table66%2/3
A and B
A= $methodB= UNIVERSAL::can($item, $method)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | $present = $item->$method($self); ## call item method | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # undef returned indicates error, note that we expect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # $item to have called error() on the view | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | ▶ | return unless defined $present; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | $output .= $present; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | next; ## NEXT | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | ▶ | elsif ( ref($item) eq 'HASH' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
ref $item eq "HASH" and defined($newtype = $item->{$method}) and defined($template = $$map{"$method=>$newtype"})
ref $item eq "HASH" and defined($newtype = $item->{$method})
MC/DC0%0/3
ref $item eq "HASH" and defined($newtype = $item->{$method}) and defined($template = $$map{"$method=>$newtype"})
ref $item eq "HASH"
defined($newtype = $item->{$method})
defined($template = $$map{"$method=>$newtype"})
Truth table25%1/4
A and B and C
A= ref $item eq "HASH"B= defined($newtype = $item->{$method})C= defined($template = $$map{"$method=>$newtype"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | && defined($newtype = $item->{$method}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | && defined($template = $map->{"$method=>$newtype"})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | ▶ | elsif ( defined($newtype) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $newtype and defined($template = $$map{"$method=>*"})
MC/DC0%0/2
defined $newtype and defined($template = $$map{"$method=>*"})
defined $newtype
defined($template = $$map{"$method=>*"})
Truth table33%1/3
A and B
A= defined $newtypeB= defined($template = $$map{"$method=>*"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | && defined($template = $map->{"$method=>*"}) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $template =~ s/\*/$newtype/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | elsif (! ($template = $map->{ default }) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # default not defined, so construct template name from type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 7 | ($template = $type) =~ s/\W+/_/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # $self->DEBUG("defined map type for $type: $template\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 35 | ▶ | $self->DEBUG("printing view '", $template || '', "', $item\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$template || ''
MC/DC0%0/1
$template || ''
$template
Truth table0%0/2
A
A= $template
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 35 | ▶ | $output .= $self->view($template, $item) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | if $template; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 37 | return $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # view($template, $item, \%vars) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # Wrapper around include() which expects a template name, $template, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # followed by a data item, $item, and optionally, a further hash array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # of template variables. The $item is added as an entry to the $vars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # hash (which is created empty if not passed as an argument) under the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # name specified by the internal 'item' member, which is appropriately | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # 'item' by default. Thus an external object present() method can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # callback against this object method, simply passing a data item to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # be displayed. The external object doesn't have to know what the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # view expects the item to be called in the $vars hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 54 | ▶ | sub view { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
view: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 54 | my ($self, $template, $item) = splice(@_, 0, 3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 54 | ▶ | my $vars = ref $_[0] eq 'HASH' ? shift : { @_ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 54 | ▶ | $vars->{ $self->{ item } } = $item if defined $item; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 54 | $self->include($template, $vars); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # include($template, \%vars) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # INCLUDE a template, $template, mapped according to the current prefix, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # suffix, default, etc., where $vars is an optional hash reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # containing template variable definitions. If the template isn't found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # then the method will default to any 'notfound' template, if defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # as an internal item. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 85 | ▶ | sub include { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
include: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 85 | my ($self, $template, $vars) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 85 | my $context = $self->{ _CONTEXT }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 85 | $template = $self->template($template); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 84 | ▶ | $vars = { } unless ref $vars eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 84 | ▶ | $vars->{ view } ||= $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$vars->{"view"} ||= $self
MC/DC0%0/2
$vars->{"view"} ||= $self
$vars->{"view"}
$self
Truth table33%1/3
A ||= B
A= $vars->{"view"}B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 84 | $context->include( $template, $vars ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # DEBUGGING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # my $out = $context->include( $template, $vars ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # print STDERR "VIEW return [$out]\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # return $out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # template($template) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # Returns a compiled template for the specified template name, according | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # to the current configuration parameters. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 92 | ▶ | sub template { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
template: called CC=14 SCAR=26.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 92 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 92 | my $context = $self->{ _CONTEXT }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 92 | ▶ | return $context->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | Template::Constants::ERROR_VIEW, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | "no view template specified" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | ) unless $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 92 | my $notfound = $self->{ notfound }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 92 | my $base = $self->{ base }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 92 | my ($template, $block, $error); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | return $block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 92 | ▶ | if ($block = $self->{ _BLOCKS }->{ $name }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # try the named template | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 56 | $template = $self->template_name($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 56 | ▶ | $self->DEBUG("looking for $template\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 56 | eval { $template = $context->template($template) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # try asking the base view if not found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 56 | ▶ | if (($error = $@) && $base) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$error = $@ and $base
MC/DC100%2/2
$error = $@ and $base
$error = $@
$base
Truth table100%3/3
A and B
A= $error = $@B= $base
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 6 | ▶ | $self->DEBUG("asking base for $name\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 6 | eval { $template = $base->template($name) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # try the 'notfound' template (if defined) if that failed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 56 | ▶ | if (($error = $@) && $notfound) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$error = $@ and $notfound
MC/DC100%2/2
$error = $@ and $notfound
$error = $@
$notfound
Truth table100%3/3
A and B
A= $error = $@B= $notfound
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 5 | ▶ | unless ($template = $self->{ _BLOCKS }->{ $notfound }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 4 | $notfound = $self->template_name($notfound); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 4 | ▶ | $self->DEBUG("not found, looking for $notfound\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 4 | eval { $template = $context->template($notfound) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 4 | ▶ | return $context->throw(Template::Constants::ERROR_VIEW, $error) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | if $@; # return first error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | elsif ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | ▶ | $self->DEBUG("no 'notfound'\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | return $context->throw(Template::Constants::ERROR_VIEW, $error); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 55 | return $template; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # template_name($template) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # Returns the name of the specified template with any appropriate prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # and/or suffix added. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 62 | ▶ | sub template_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
template_name: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 62 | my ($self, $template) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | $template = $self->{ prefix } . $template . $self->{ suffix } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 62 | ▶ | if $template; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 62 | ▶ | $self->DEBUG("template name: $template\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 62 | return $template; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # default($val) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # Special case accessor to retrieve/update 'default' as an alias for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # '$map->{ default }'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 7 | ▶ | sub default { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | return @_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | ? ($self->{ map }->{ default } = shift) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 7 | ▶ | : $self->{ map }->{ default }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # Returns/updates public internal data items (i.e. not prefixed '_' or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # '.') or presents a view if the method matches the view_prefix item, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # e.g. view_foo(...) => view('foo', ...). Similarly, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | # include_prefix is used, if defined, to map include_foo(...) to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # include('foo', ...). If that fails then the entire method name will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # be used as the name of a template to include iff the include_named | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | # parameter is set (default: 1). Last attempt is to match the entire | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # method name to a view() call, iff view_naked is set. Otherwise, a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # 'view' exception is raised reporting the error "no such view member: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # $method". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 120 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=27 SCAR=34.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 120 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 120 | my $item = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 120 | $item =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 120 | ▶ | return if $item eq 'DESTROY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 120 | my $starts_with = substr($item,0,1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 120 | ▶ | if ($starts_with eq '.' || $starts_with eq '_') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
Condition33%1/3
$starts_with eq "." or $starts_with eq "_"
MC/DC0%0/2
$starts_with eq "." or $starts_with eq "_"
$starts_with eq "."
$starts_with eq "_"
Truth table33%1/3
A or B
A= $starts_with eq "."B= $starts_with eq "_"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | return $self->{ _CONTEXT }->throw(Template::Constants::ERROR_VIEW, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | "attempt to view private member: $item"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | elsif (exists $self->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # update existing config item (e.g. 'prefix') if unsealed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | return $self->{ _CONTEXT }->throw(Template::Constants::ERROR_VIEW, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | "cannot update config item in sealed view: $item") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 20 | ▶ | if @_ && $self->{ SEALED }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and $self->{"SEALED"}
MC/DC100%2/2
@_ and $self->{"SEALED"}
@_
$self->{"SEALED"}
Truth table100%3/3
A and B
A= @_B= $self->{"SEALED"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 19 | ▶ | $self->DEBUG("accessing item: $item\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 19 | ▶ | return @_ ? ($self->{ $item } = shift) : $self->{ $item }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | elsif (exists $self->{ data }->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # get/update existing data item (must be unsealed to update) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 48 | ▶ | if (@_ && $self->{ SEALED }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and $self->{"SEALED"}
MC/DC100%2/2
@_ and $self->{"SEALED"}
@_
$self->{"SEALED"}
Truth table100%3/3
A and B
A= @_B= $self->{"SEALED"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | return $self->{ _CONTEXT }->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | Template::Constants::ERROR_VIEW, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | "cannot update item in sealed view: $item" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 3 | ▶ | ) unless $self->{ silent }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # ignore args if silent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 2 | @_ = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | $self->DEBUG(@_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 47 | ▶ | ? "updating data item: $item <= $_[0]\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | : "returning data item: $item\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | ) if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | return @_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | ? ($self->{ data }->{ $item } = shift) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 47 | ▶ | : $self->{ data }->{ $item }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | ▶ | elsif (@_ && ! $self->{ SEALED }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
@_ and not $self->{"SEALED"}
MC/DC100%2/2
@_ and not $self->{"SEALED"}
@_
not $self->{"SEALED"}
Truth table100%3/3
A and not(B)
A= @_B= not $self->{"SEALED"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # set data item if unsealed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 6 | ▶ | $self->DEBUG("setting unsealed data: $item => @_\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 6 | $self->{ data }->{ $item } = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | elsif ($item =~ s/^$self->{ view_prefix }//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 15 | ▶ | $self->DEBUG("returning view($item)\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 15 | return $self->view($item, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | elsif ($item =~ s/^$self->{ include_prefix }//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 3 | ▶ | $self->DEBUG("returning include($item)\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 3 | return $self->include($item, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | elsif ($self->{ include_naked }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 26 | ▶ | $self->DEBUG("returning naked include($item)\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 26 | return $self->include($item, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | elsif ($self->{ view_naked }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 1 | ▶ | $self->DEBUG("returning naked view($item)\n") if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | return $self->view($item, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | return $self->{ _CONTEXT }->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 1 | Template::Constants::ERROR_VIEW, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | "no such view member: $item" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||