| 1 | #============================================================= -*-Perl-*- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Template::Stash | ||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Definition of an object class which stores and manages access to | ||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # variables for the Template Toolkit. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Andy Wardley <abw@wardley.org> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # Copyright (C) 1996-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 | #============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | package Template::Stash; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 106 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 106 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 106 | ▶ | use Template::VMethods; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 106 | ▶ | use Template::Exception; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 106 | ▶ | use Scalar::Util qw( blessed reftype ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 106 | our $VERSION = '3.106'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 106 | ▶ | our $DEBUG = 0 unless defined $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 106 | our $PRIVATE = qr/^[_.]/; | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 106 | our $UNDEF_TYPE = 'var.undef'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 106 | our $UNDEF_INFO = 'undefined variable: %s'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # alias _dotop() to dotop() so that we have a consistent method name | ||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # between the Perl and XS stash implementations | ||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 106 | *dotop = \&_dotop; | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Virtual Methods | ||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # If any of $ROOT_OPS, $SCALAR_OPS, $HASH_OPS or $LIST_OPS are already | ||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # defined then we merge their contents with the default virtual methods | ||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # define by Template::VMethods. Otherwise we can directly alias the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # corresponding Template::VMethod package vars. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | our $ROOT_OPS = defined $ROOT_OPS | ||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | ? { %{$Template::VMethods::ROOT_VMETHODS}, %$ROOT_OPS } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | : $Template::VMethods::ROOT_VMETHODS; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | our $SCALAR_OPS = defined $SCALAR_OPS | ||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 106 | ▶ | ? { %{$Template::VMethods::TEXT_VMETHODS}, %$SCALAR_OPS } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | : $Template::VMethods::TEXT_VMETHODS; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | our $HASH_OPS = defined $HASH_OPS | ||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | ? { %{$Template::VMethods::HASH_VMETHODS}, %$HASH_OPS } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | : $Template::VMethods::HASH_VMETHODS; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | our $LIST_OPS = defined $LIST_OPS | ||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 106 | ▶ | ? { %{$Template::VMethods::LIST_VMETHODS}, %$LIST_OPS } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | : $Template::VMethods::LIST_VMETHODS; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # define_vmethod($type, $name, \&sub) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Defines a virtual method of type $type (SCALAR, HASH, or LIST), with | ||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # name $name, that invokes &sub when called. It is expected that &sub | ||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # be able to handle the type that it will be called upon. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 15 | ▶ | sub define_vmethod { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
define_vmethod: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 15 | my ($class, $type, $name, $sub) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 15 | my $op; | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 15 | $type = lc $type; | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 15 | ▶ | if ($type eq 'scalar' || $type eq 'item') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$type eq "scalar" or $type eq "item"
MC/DC100%2/2
$type eq "scalar" or $type eq "item"
$type eq "scalar"
$type eq "item"
Truth table100%3/3
A or B
A= $type eq "scalar"B= $type eq "item"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | $op = $SCALAR_OPS; | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | elsif ($type eq 'hash') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | $op = $HASH_OPS; | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ▶ | elsif ($type eq 'list' || $type eq 'array') { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$type eq "list" or $type eq "array"
MC/DC100%2/2
$type eq "list" or $type eq "array"
$type eq "list"
$type eq "array"
Truth table100%3/3
A or B
A= $type eq "list"B= $type eq "array"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | $op = $LIST_OPS; | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | die "invalid vmethod type: $type\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 14 | $op->{ $name } = $sub; | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 14 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # ----- CLASS METHODS ----- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # new(\%params) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Constructor method which creates a new Template::Stash object. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # An optional hash reference may be passed containing variable | ||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # definitions that will be used to initialise the stash. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # Returns a reference to a newly created Template::Stash. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 293 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 293 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 293 | ▶ | my $params = ref $_[0] eq 'HASH' ? shift(@_) : { @_ }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 293 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | global => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | %$params, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | %$ROOT_OPS, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | '_PARENT' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 293 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # ----- PUBLIC OBJECT METHODS ----- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # clone(\%params) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # Creates a copy of the current stash object to effect localisation | ||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # of variables. The new stash is blessed into the same class as the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # parent (which may be a derived class) and has a '_PARENT' member added | ||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # which contains a reference to the parent stash that created it | ||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # ($self). This member is used in a successive declone() method call to | ||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # return the reference to the parent. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # A parameter may be provided which should reference a hash of | ||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # variable/values which should be defined in the new stash. The | ||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # update() method is called to define these new variables in the cloned | ||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # stash. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # Returns a reference to a cloned Template::Stash. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1702 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1702 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1702 | ▶ | $params ||= { }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params ||= {}
MC/DC100%1/1
$params ||= {}
$params
Truth table100%2/2
A
A= $params
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # look out for magical 'import' argument which imports another hash | ||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1702 | my $import = $params->{ import }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1702 | ▶ | if (ref $import eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | delete $params->{ import }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1700 | undef $import; | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1702 | my $clone = bless { | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | %$self, # copy all parent members | ||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | %$params, # copy all new data | ||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | '_PARENT' => $self, # link to parent | ||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | }, ref $self; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # perform hash import if defined | ||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1702 | ▶ | &{ $HASH_OPS->{ import } }($clone, $import) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | if defined $import; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1702 | return $clone; | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # declone($export) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # Returns a reference to the PARENT stash. When called in the following | ||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # manner: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # $stash = $stash->declone(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # the reference count on the current stash will drop to 0 and be "freed" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # and the caller will be left with a reference to the parent. This | ||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # contains the state of the stash before it was cloned. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1698 | ▶ | sub declone { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
declone: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1698 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1698 | ▶ | $self->{ _PARENT } || $self; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # get($ident) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # Returns the value for an variable stored in the stash. The variable | ||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # may be specified as a simple string, e.g. 'foo', or as an array | ||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # reference representing compound variables. In the latter case, each | ||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # pair of successive elements in the list represent a node in the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # compound variable. The first is the variable name, the second a | ||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # list reference of arguments or 0 if undefined. So, the compound | ||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # variable [% foo.bar('foo').baz %] would be represented as the list | ||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # [ 'foo', 0, 'bar', ['foo'], 'baz', 0 ]. Returns the value of the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # identifier or an empty string if undefined. Errors are thrown via | ||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # die(). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 667 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 667 | my ($self, $ident, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 667 | my ($root, $result); | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 667 | $root = $self; | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 667 | ▶ | if (ref $ident eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
ref $ident eq "ARRAY" or (index($ident, ".") != -1) and $ident = [map({s/\(.*$//;
$_, 0;} split(/\./, $ident, 0))]
(index($ident, ".") != -1) and $ident = [map({s/\(.*$//;
$_, 0;} split(/\./, $ident, 0))]
MC/DC100%2/2
ref $ident eq "ARRAY" or (index($ident, ".") != -1) and $ident = [map({s/\(.*$//;
$_, 0;} split(/\./, $ident, 0))]
ref $ident eq "ARRAY"
(index($ident, ".") != -1)
Truth table100%3/3
A or B
A= ref $ident eq "ARRAY"B= (index($ident, ".") != -1)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | || (index($ident,'.') > -1) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 16 | && ($ident = [ map { s/\(.*$//; ($_, 0) } split(/\./, $ident) ])) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 334 | my $size = $#$ident; | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # if $ident is a list reference, then we evaluate each item in the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # identifier against the previous result, using the root stash | ||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # ($self) as the first implicit 'result'... | ||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 334 | ▶ | foreach (my $i = 0; $i <= $size; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 737 | $result = $self->_dotop($root, @$ident[$i, $i+1]); | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 736 | ▶ | last unless defined $result; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 728 | $root = $result; | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 333 | $result = $self->_dotop($root, $ident, $args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 664 | ▶ | return $result // $self->undefined($ident, $args); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$result // $self->undefined($ident, $args)
MC/DC0%0/2
$result // $self->undefined($ident, $args)
$result
$self->undefined($ident, $args)
Truth table66%2/3
A // B
A= $resultB= $self->undefined($ident, $args)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # set($ident, $value, $default) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # Updates the value for a variable in the stash. The first parameter | ||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # should be the variable name or array, as per get(). The second | ||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # parameter should be the intended value for the variable. The third, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # optional parameter is a flag which may be set to indicate 'default' | ||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # mode. When set true, the variable will only be updated if it is | ||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # currently undefined or has a false value. The magical 'IMPORT' | ||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # variable identifier may be used to indicate that $value is a hash | ||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # reference whose values should be imported. Returns the value set, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # or an empty string if not set (e.g. default mode). In the case of | ||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # IMPORT, returns the number of items imported from the hash. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 562 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 562 | my ($self, $ident, $value, $default) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 562 | my ($root, $result, $error); | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 562 | $root = $self; | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | ELEMENT: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 562 | ▶ | if (ref $ident eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
ref $ident eq "ARRAY" or (index($ident, ".") != -1) and $ident = [map({s/\(.*$//;
$_, 0;} split(/\./, $ident, 0))]
(index($ident, ".") != -1) and $ident = [map({s/\(.*$//;
$_, 0;} split(/\./, $ident, 0))]
MC/DC100%2/2
ref $ident eq "ARRAY" or (index($ident, ".") != -1) and $ident = [map({s/\(.*$//;
$_, 0;} split(/\./, $ident, 0))]
ref $ident eq "ARRAY"
(index($ident, ".") != -1)
Truth table100%3/3
A or B
A= ref $ident eq "ARRAY"B= (index($ident, ".") != -1)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | || (index($ident,'.') != -1) # has a '.' in it somewhere | ||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | && ($ident = [ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | map { s/\(.*$//; ($_, 0) } | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | split(/\./, $ident) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | ])) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # a compound identifier may contain multiple elements (e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # foo.bar.baz) and we must first resolve all but the last, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # using _dotop() with the $lvalue flag set which will create | ||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # intermediate hashes if necessary... | ||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 14 | my $size = $#$ident; | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 14 | ▶ | foreach (my $i = 0; $i < $size - 2; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 16 | $result = $self->_dotop($root, @$ident[$i, $i+1], 1); | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 16 | ▶ | last ELEMENT unless defined $result; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 16 | $root = $result; | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # then we call _assign() to assign the value to the last element | ||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 14 | $result = $self->_assign( | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | $root, @$ident[$size-1, $size], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | $value, $default | ||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 548 | $result = $self->_assign($root, $ident, 0, $value, $default); | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 562 | ▶ | return $result // ''; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$result // ""
MC/DC0%0/1
$result // ""
$result
Truth table50%1/2
A
A= $result
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # getref($ident) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # Returns a "reference" to a particular item. This is represented as a | ||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # closure which will return the actual stash item when called. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 6 | ▶ | sub getref { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getref: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 6 | my ($self, $ident, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 6 | my ($root, $item, $result); | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 6 | $root = $self; | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 6 | ▶ | if (ref $ident eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 3 | my $size = $#$ident; | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 3 | ▶ | foreach (my $i = 0; $i <= $size; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 6 | ($item, $args) = @$ident[$i, $i + 1]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 6 | ▶ | last if $i >= $size - 2; # don't evaluate last node | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | last unless defined | ||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 3 | ▶ | ($root = $self->_dotop($root, $item, $args)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 3 | $item = $ident; | |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 6 | ▶ | if (defined $root) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 11 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 11 | ▶ | my @args = (@{$args||[]}, @_); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args || []
MC/DC100%1/1
$args || []
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 11 | $self->_dotop($root, $item, \@args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 6 | } | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | return sub { '' }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # update(\%params) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # Update multiple variables en masse. No magic is performed. Simple | ||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # variable names only. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1499 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 1499 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # look out for magical 'import' argument to import another hash | ||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1499 | my $import = $params->{ import }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1499 | ▶ | if (ref $import eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | @$self{ keys %$import } = values %$import; | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | delete $params->{ import }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 1499 | @$self{ keys %$params } = values %$params; | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # undefined($ident, $args) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # Method called when a get() returns an undefined value. Can be redefined | ||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # in a subclass to implement alternate handling. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1730 | ▶ | sub undefined { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
undefined: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1730 | my ($self, $ident, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1730 | ▶ | if ($self->{ _STRICT }) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # .defined must work on undefined values even in STRICT mode — | ||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # it would be nonsensical to throw "undefined variable" when the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # user is explicitly testing whether a variable is defined (GH #170) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 26 | ▶ | if (ref $ident eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 8 | my $last_item = $ident->[$#$ident - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 8 | ▶ | return '' if defined $last_item && $last_item eq 'defined'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $last_item and $last_item eq "defined"
MC/DC50%1/2
defined $last_item and $last_item eq "defined"
defined $last_item
$last_item eq "defined"
Truth table66%2/3
A and B
A= defined $last_itemB= $last_item eq "defined"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | # Sorry, but we can't provide a sensible source file and line without | ||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | # re-designing the whole architecture of TT (see TT3) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | die Template::Exception->new( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | $UNDEF_TYPE, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | $UNDEF_INFO, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | $self->_reconstruct_ident($ident) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 22 | ▶ | ) if $self->{ _STRICT }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # There was a time when I thought this was a good idea. But it's not. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1704 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 22 | ▶ | sub _reconstruct_ident { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reconstruct_ident: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 22 | my ($self, $ident) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 22 | my ($name, $args, @output); | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 22 | ▶ | my @input = ref $ident eq 'ARRAY' ? @$ident : ($ident); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 22 | ▶ | while (@input) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 26 | $name = shift @input; | |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 26 | ▶ | $args = shift @input || 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift @input || 0
MC/DC100%1/1
shift @input || 0
shift @input
Truth table100%2/2
A
A= shift @input
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 26 | ▶ | $name .= '(' . join(', ', map { /^\d+$/ ? $_ : "'$_'" } @$args) . ')' | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$args and ref $args eq "ARRAY"
MC/DC50%1/2
$args and ref $args eq "ARRAY"
$args
ref $args eq "ARRAY"
Truth table66%2/3
A and B
A= $argsB= ref $args eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | if $args && ref $args eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 26 | push(@output, $name); | |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 22 | return join('.', @output); | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # ----- PRIVATE OBJECT METHODS ----- | ||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # _dotop($root, $item, \@args, $lvalue) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # This is the core 'dot' operation method which evaluates elements of | ||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # variables against their root. All variables have an implicit root | ||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # which is the stash object itself (a hash). Thus, a non-compound | ||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # variable 'foo' is actually '(stash.)foo', the compound 'foo.bar' is | ||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # '(stash.)foo.bar'. The first parameter is a reference to the current | ||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # root, initially the stash itself. The second parameter contains the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # name of the variable element, e.g. 'foo'. The third optional | ||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # parameter is a reference to a list of any parenthesised arguments | ||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # specified for the variable, which are passed to sub-routines, object | ||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # methods, etc. The final parameter is an optional flag to indicate | ||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # if this variable is being evaluated on the left side of an assignment | ||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # (e.g. foo.bar.baz = 10). When set true, intermediated hashes will | ||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # be created (e.g. bar) if necessary. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # Returns the result of evaluating the item against the root, having | ||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # performed any variable "magic". The value returned can then be used | ||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # as the root of the next _dotop() in a compound sequence. Returns | ||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # undef if the variable is undefined. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 1118 | ▶ | sub _dotop { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dotop: called CC=50 SCAR=45.7
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 1118 | my ($self, $root, $item, $args, $lvalue) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1118 | my $rootref = ref $root; | |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 1118 | ▶ | my $atroot = (blessed $root && $root->isa(ref $self)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
builtin::blessed($root) && $root->isa(ref $self)
MC/DC100%2/2
builtin::blessed($root) && $root->isa(ref $self)
builtin::blessed($root)
$root->isa(ref $self)
Truth table100%3/3
A && B
A= builtin::blessed($root)B= $root->isa(ref $self)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 1118 | my ($value, @result); | |||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 1118 | ▶ | $args ||= [ ]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args ||= []
MC/DC100%1/1
$args ||= []
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 1118 | ▶ | $lvalue ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$lvalue ||= 0
MC/DC100%1/1
$lvalue ||= 0
$lvalue
Truth table100%2/2
A
A= $lvalue
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # print STDERR "_dotop(root=$root, item=$item, args=[@$args])\n" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # return undef without an error if either side of the dot is unviable | ||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 1118 | ▶ | return undef unless defined($root) and defined($item); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $root and defined $item
MC/DC0%0/2
defined $root and defined $item
defined $root
defined $item
Truth table33%1/3
A and B
A= defined $rootB= defined $item
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # or if an attempt is made to access a private member, starting _ or . | ||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1118 | ▶ | return undef if $PRIVATE && $item =~ /$PRIVATE/; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Template::Stash::PRIVATE and $item =~ /$Template::Stash::PRIVATE/
MC/DC0%0/2
$Template::Stash::PRIVATE and $item =~ /$Template::Stash::PRIVATE/
$Template::Stash::PRIVATE
$item =~ /$Template::Stash::PRIVATE/
Truth table33%1/3
A and B
A= $Template::Stash::PRIVATEB= $item =~ /$Template::Stash::PRIVATE/
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 1118 | ▶ | if ($atroot || $rootref eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition100%3/3
$atroot or $rootref eq "HASH"
MC/DC100%2/2
$atroot or $rootref eq "HASH"
$atroot
$rootref eq "HASH"
Truth table100%3/3
A or B
A= $atrootB= $rootref eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # if $root is a regular HASH or a Template::Stash kinda HASH (the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # *real* root of everything). We first lookup the named key | ||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # in the hash, or create an empty hash in its place if undefined | ||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # and the $lvalue flag is set. Otherwise, we check the HASH_OPS | ||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # pseudo-methods table, calling the code if found, or return undef. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 810 | ▶ | if (defined($value = $root->{ $item })) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 547 | ▶ | return $value unless ref $value eq 'CODE'; ## RETURN | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 17 | @result = &$value(@$args); ## @result | |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | elsif ($lvalue) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # we create an intermediate hash if this is an lvalue | ||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 2 | return $root->{ $item } = { }; ## RETURN | |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # ugly hack: only allow import vmeth to be called on root stash | ||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | ▶ | elsif (($value = $HASH_OPS->{ $item }) | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$value = $Template::Stash::HASH_OPS->{$item} and !$atroot || $item eq "import"
not $atroot or $item eq "import"
MC/DC100%3/3
$value = $Template::Stash::HASH_OPS->{$item} and !$atroot || $item eq "import"
$value = $Template::Stash::HASH_OPS->{$item}
not $atroot
$item eq "import"
Truth table100%4/4
A and not(B) or C
A= $value = $Template::Stash::HASH_OPS->{$item}B= not $atrootC= $item eq "import"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | && (! $atroot || $item eq 'import')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 43 | @result = &$value($root, @$args); ## @result | |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | elsif ( ref $item eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # hash slice | ||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 2 | return [@$root{@$item}]; ## RETURN | |||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | elsif ($rootref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # if root is an ARRAY then we check for a LIST_OPS pseudo-method | ||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # or return the numerical index into the array, or undef | ||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 168 | ▶ | if ($value = $LIST_OPS->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 151 | @result = &$value($root, @$args); ## @result | |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | elsif ($item =~ /^-?\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 16 | $value = $root->[$item]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 16 | ▶ | return $value unless ref $value eq 'CODE'; ## RETURN | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | @result = &$value(@$args); ## @result | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | elsif ( ref $item eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # array slice | ||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | return [@$root[@$item]]; ## RETURN | |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # NOTE: we do the can-can because UNIVSERAL::isa($something, 'UNIVERSAL') | ||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # doesn't appear to work with CGI, returning true for the first call | ||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # and false for all subsequent calls. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # UPDATE: that doesn't appear to be the case any more | ||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | ▶ | elsif (blessed($root) && $root->can('can')) { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($root) and $root->can("can")
MC/DC50%1/2
builtin::blessed($root) and $root->can("can")
builtin::blessed($root)
$root->can("can")
Truth table66%2/3
A and B
A= builtin::blessed($root)B= $root->can("can")
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | # if $root is a blessed reference (i.e. inherits from the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | # UNIVERSAL object base class) then we call the item as a method. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # If that fails then we try to fallback on HASH behaviour if | ||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | # possible. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 39 | eval { @result = $root->$item(@$args); }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 39 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # temporary hack - required to propagate errors thrown | ||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | # by views; if $@ is a ref (e.g. Template::Exception | ||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # object then we assume it's a real error that needs | ||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # real throwing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 13 | ▶ | my $class = ref($root) || $root; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $root || $root
MC/DC0%0/2
ref $root || $root
ref $root
$root
Truth table33%1/3
A || B
A= ref $rootB= $root
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # Fail only if the function exists | ||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 13 | ▶ | die $@ if ( ref($@) || $root->can($item) ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $@ or $root->can($item)
MC/DC50%1/2
ref $@ or $root->can($item)
ref $@
$root->can($item)
Truth table66%2/3
A or B
A= ref $@B= $root->can($item)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | # failed to call object method, so try some fallbacks | ||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 12 | ▶ | if (reftype $root eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 7 | ▶ | if( defined($value = $root->{ $item })) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 3 | ▶ | return $value unless ref $value eq 'CODE'; ## RETURN | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | @result = &$value(@$args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | elsif ($value = $HASH_OPS->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 2 | @result = &$value($root, @$args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | elsif ($value = $LIST_OPS->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 1 | @result = &$value([$root], @$args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | elsif (reftype $root eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 5 | ▶ | if( $value = $LIST_OPS->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 3 | @result = &$value($root, @$args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | elsif( $item =~ /^-?\d+$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 2 | $value = $root->[$item]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 2 | ▶ | return $value unless ref $value eq 'CODE'; ## RETURN | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | @result = &$value(@$args); ## @result | |||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | elsif ( ref $item eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | # array slice | ||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | return [@$root[@$item]]; ## RETURN | |||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | elsif ($value = $SCALAR_OPS->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | @result = &$value($root, @$args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | elsif ($value = $LIST_OPS->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | @result = &$value([$root], @$args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | elsif ($self->{ _DEBUG }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | @result = (undef, $@); | |||||||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | ▶ | elsif (($value = $SCALAR_OPS->{ $item }) && ! $lvalue) { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$value = $Template::Stash::SCALAR_OPS->{$item} and not $lvalue
MC/DC50%1/2
$value = $Template::Stash::SCALAR_OPS->{$item} and not $lvalue
$value = $Template::Stash::SCALAR_OPS->{$item}
not $lvalue
Truth table66%2/3
A and not(B)
A= $value = $Template::Stash::SCALAR_OPS->{$item}B= not $lvalue
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # at this point, it doesn't look like we've got a reference to | ||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # anything we know about, so we try the SCALAR_OPS pseudo-methods | ||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # table (but not for l-values) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 100 | @result = &$value($root, @$args); ## @result | |||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | ▶ | elsif (($value = $LIST_OPS->{ $item }) && ! $lvalue) { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$value = $Template::Stash::LIST_OPS->{$item} and not $lvalue
MC/DC0%0/2
$value = $Template::Stash::LIST_OPS->{$item} and not $lvalue
$value = $Template::Stash::LIST_OPS->{$item}
not $lvalue
Truth table33%1/3
A and not(B)
A= $value = $Template::Stash::LIST_OPS->{$item}B= not $lvalue
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # last-ditch: can we promote a scalar to a one-element | ||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # list and apply a LIST_OPS virtual method? | ||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 1 | @result = &$value([$root], @$args); | |||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | elsif ($self->{ _DEBUG }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | die "don't know how to access [ $root ].$item\n"; ## DIE | |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | @result = (); | |||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # fold multiple return items into a list unless first item is undef | ||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 561 | ▶ | if (defined $result[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | return ## RETURN | ||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 337 | ▶ | scalar @result > 1 ? [ @result ] : $result[0]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | elsif (defined $result[1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | die $result[1]; ## DIE | |||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | elsif ($self->{ _DEBUG }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 2 | die "$item is undefined\n"; ## DIE | |||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 222 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # _assign($root, $item, \@args, $value, $default) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | # Similar to _dotop() above, but assigns a value to the given variable | ||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | # instead of simply returning it. The first three parameters are the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # root item, the item and arguments, as per _dotop(), followed by the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | # value to which the variable should be set and an optional $default | ||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | # flag. If set true, the variable will only be set if currently false | ||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | # (undefined/zero) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 562 | ▶ | sub _assign { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assign: called CC=19 SCAR=37.3
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 562 | my ($self, $root, $item, $args, $value, $default) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 562 | my $rootref = ref $root; | |||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 562 | ▶ | my $atroot = (blessed $root && $root->isa(ref $self)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($root) && $root->isa(ref $self)
MC/DC50%1/2
builtin::blessed($root) && $root->isa(ref $self)
builtin::blessed($root)
$root->isa(ref $self)
Truth table66%2/3
A && B
A= builtin::blessed($root)B= $root->isa(ref $self)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 562 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 562 | ▶ | $args ||= [ ]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args ||= []
MC/DC0%0/1
$args ||= []
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 562 | ▶ | $default ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$default ||= 0
MC/DC100%1/1
$default ||= 0
$default
Truth table100%2/2
A
A= $default
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | # return undef without an error if either side of the dot is unviable | ||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 562 | ▶ | return undef unless $root and defined $item; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$root and defined $item
MC/DC0%0/2
$root and defined $item
$root
defined $item
Truth table33%1/3
A and B
A= $rootB= defined $item
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # or if an attempt is made to update a private member, starting _ or . | ||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 562 | ▶ | return undef if $PRIVATE && $item =~ /$PRIVATE/; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Template::Stash::PRIVATE and $item =~ /$Template::Stash::PRIVATE/
MC/DC0%0/2
$Template::Stash::PRIVATE and $item =~ /$Template::Stash::PRIVATE/
$Template::Stash::PRIVATE
$item =~ /$Template::Stash::PRIVATE/
Truth table33%1/3
A and B
A= $Template::Stash::PRIVATEB= $item =~ /$Template::Stash::PRIVATE/
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 562 | ▶ | if ($rootref eq 'HASH' || $atroot) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$rootref eq "HASH" or $atroot
MC/DC100%2/2
$rootref eq "HASH" or $atroot
$rootref eq "HASH"
$atroot
Truth table100%3/3
A or B
A= $rootref eq "HASH"B= $atroot
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | # if the root is a hash we set the named key | ||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | return ($root->{ $item } = $value) ## RETURN | ||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 559 | ▶ | unless $default && $root->{ $item }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$default and $root->{$item}
MC/DC0%0/2
$default and $root->{$item}
$default
$root->{$item}
Truth table33%1/3
A and B
A= $defaultB= $root->{$item}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | ▶ | elsif ($rootref eq 'ARRAY' && $item =~ /^-?\d+$/) { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$rootref eq "ARRAY" and $item =~ /^-?\d+$/
MC/DC0%0/2
$rootref eq "ARRAY" and $item =~ /^-?\d+$/
$rootref eq "ARRAY"
$item =~ /^-?\d+$/
Truth table33%1/3
A and B
A= $rootref eq "ARRAY"B= $item =~ /^-?\d+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | # or set a list item by index number | ||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 3 | ▶ | return ($root->[$item] = $value) ## RETURN | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$default and $root->[$item]
MC/DC100%2/2
$default and $root->[$item]
$default
$root->[$item]
Truth table100%3/3
A and B
A= $defaultB= $root->[$item]
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | unless $default && $root->[$item]; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | elsif (blessed($root)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | # try to call the item as a method of an object | ||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | ▶ | return $root->$item(@$args, $value) ## RETURN | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$default and $root->$item
MC/DC0%0/2
$default and $root->$item
$default
$root->$item
Truth table0%0/3
A and B
A= $defaultB= $root->$item
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | unless $default && $root->$item(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # 2 issues: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | # - method call should be wrapped in eval { } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | # - fallback on hash methods if object method not found | ||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | # eval { $result = $root->$item(@$args, $value); }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | # if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | # die $@ if ref($@) || ($@ !~ /Can't locate object method/); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | # # failed to call object method, so try some fallbacks | ||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | # if (UNIVERSAL::isa($root, 'HASH') && exists $root->{ $item }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | # $result = ($root->{ $item } = $value) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | # unless $default && $root->{ $item }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | # return $result; ## RETURN | ||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | die "don't know how to assign to [$root].[$item]\n"; ## DIE | |||||||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 106 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||