| 1 | #================================================================= -*-Perl-*- | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Template::Directive | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||
| 6 | # Factory module for constructing templates from Perl code. | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # AUTHOR | ||||||||||||||||||||||||||||
| 9 | # Andy Wardley <abw@wardley.org> | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # WARNING | ||||||||||||||||||||||||||||
| 12 | # Much of this module is hairy, even furry in places. It needs | ||||||||||||||||||||||||||||
| 13 | # a lot of tidying up and may even be moved into a different place | ||||||||||||||||||||||||||||
| 14 | # altogether. The generator code is often inefficient, particularly in | ||||||||||||||||||||||||||||
| 15 | # being very anal about pretty-printing the Perl code all neatly, but | ||||||||||||||||||||||||||||
| 16 | # at the moment, that's still high priority for the sake of easier | ||||||||||||||||||||||||||||
| 17 | # debugging. | ||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||
| 19 | # COPYRIGHT | ||||||||||||||||||||||||||||
| 20 | # Copyright (C) 1996-2022 Andy Wardley. All Rights Reserved. | ||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||
| 22 | # This module is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 23 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||
| 25 | #============================================================================ | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | package Template::Directive; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 106 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 106 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 106 | ▶ | use base 'Template::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 106 | ▶ | use Template::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 106 | ▶ | use Template::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 106 | our $VERSION = '3.106'; | |||||||||||||||||||||||||||
| 36 | 106 | ▶ | our $DEBUG = 0 unless defined $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 106 | ▶ | our $WHILE_MAX = 1000 unless defined $WHILE_MAX; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 106 | ▶ | our $PRETTY = 0 unless defined $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 106 | our $OUTPUT = '$output .= '; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 236 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 236 | my ($self, $config) = @_; | |||||||||||||||||||||||||||
| 44 | 236 | $self->{ NAMESPACE } = $config->{ NAMESPACE }; | |||||||||||||||||||||||||||
| 45 | 236 | return $self; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub trace_vars { | ||||||||||||||||||||||||||
|
Subroutine
trace_vars: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 50 | return @_ | ||||||||||||||||||||||||||||
| 51 | ? ($self->{ TRACE_VARS } = shift) | ||||||||||||||||||||||||||||
| 52 | 1 | ▶ | : $self->{ TRACE_VARS }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub pad { | ||||||||||||||||||||||||||
|
Subroutine
pad: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 0 | my ($text, $pad) = @_; | |||||||||||||||||||||||||||
| 57 | 0 | $pad = ' ' x ($pad * 4); | |||||||||||||||||||||||||||
| 58 | 0 | $text =~ s/^(?!#line)/$pad/gm; | |||||||||||||||||||||||||||
| 59 | 0 | $text; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | #======================================================================== | ||||||||||||||||||||||||||||
| 63 | # FACTORY METHODS | ||||||||||||||||||||||||||||
| 64 | # | ||||||||||||||||||||||||||||
| 65 | # These methods are called by the parser to construct directive instances. | ||||||||||||||||||||||||||||
| 66 | #======================================================================== | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 69 | # template($block) | ||||||||||||||||||||||||||||
| 70 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1651 | ▶ | sub template { | ||||||||||||||||||||||||||
|
Subroutine
template: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | 1651 | my ($self, $block) = @_; | |||||||||||||||||||||||||||
| 74 | 1651 | ▶ | $block = pad($block, 2) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1651 | ▶ | return "sub { return '' }" unless $block =~ /\S/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1640 | return <<EOF; | |||||||||||||||||||||||||||
| 79 | sub { | ||||||||||||||||||||||||||||
| 80 | my \$context = shift || die "template sub called without context\\n"; | ||||||||||||||||||||||||||||
| 81 | my \$stash = \$context->stash; | ||||||||||||||||||||||||||||
| 82 | my \$output = ''; | ||||||||||||||||||||||||||||
| 83 | my \$_tt_error; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | eval { BLOCK: { | ||||||||||||||||||||||||||||
| 86 | $block | ||||||||||||||||||||||||||||
| 87 | } }; | ||||||||||||||||||||||||||||
| 88 | if (\$@) { | ||||||||||||||||||||||||||||
| 89 | \$_tt_error = \$context->catch(\$@, \\\$output); | ||||||||||||||||||||||||||||
| 90 | die \$_tt_error unless \$_tt_error->type eq 'return'; | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | return \$output; | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | EOF | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 100 | # anon_block($block) [% BLOCK %] ... [% END %] | ||||||||||||||||||||||||||||
| 101 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub anon_block { | ||||||||||||||||||||||||||
|
Subroutine
anon_block: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 0 | my ($self, $block) = @_; | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | $block = pad($block, 2) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | return <<EOF; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # BLOCK | ||||||||||||||||||||||||||||
| 110 | $OUTPUT do { | ||||||||||||||||||||||||||||
| 111 | my \$output = ''; | ||||||||||||||||||||||||||||
| 112 | my \$_tt_error; | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | eval { BLOCK: { | ||||||||||||||||||||||||||||
| 115 | $block | ||||||||||||||||||||||||||||
| 116 | } }; | ||||||||||||||||||||||||||||
| 117 | if (\$@) { | ||||||||||||||||||||||||||||
| 118 | \$_tt_error = \$context->catch(\$@, \\\$output); | ||||||||||||||||||||||||||||
| 119 | die \$_tt_error unless \$_tt_error->type eq 'return'; | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | \$output; | ||||||||||||||||||||||||||||
| 123 | }; | ||||||||||||||||||||||||||||
| 124 | EOF | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 129 | # block($blocktext) | ||||||||||||||||||||||||||||
| 130 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 2479 | ▶ | sub block { | ||||||||||||||||||||||||||
|
Subroutine
block: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 133 | 2479 | my ($self, $block) = @_; | |||||||||||||||||||||||||||
| 134 | 2479 | ▶ | return join("\n", @{ $block || [] }); | ||||||||||||||||||||||||||
|
Condition100%2/2
$block || []
MC/DC100%1/1
$block || []
$block
Truth table100%2/2
A
A= $block
| |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 139 | # textblock($text) | ||||||||||||||||||||||||||||
| 140 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 3406 | ▶ | sub textblock { | ||||||||||||||||||||||||||
|
Subroutine
textblock: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 143 | 3406 | my ($self, $text) = @_; | |||||||||||||||||||||||||||
| 144 | 3406 | return "$OUTPUT " . &text($self, $text) . ';'; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 149 | # text($text) | ||||||||||||||||||||||||||||
| 150 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 3666 | ▶ | sub text { | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 153 | 3666 | my ( $self, $text ) = @_; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 3666 | ▶ | return '' if !length $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 3666 | ▶ | if ( $text =~ tr{$@\\}{} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 31 | $text =~ s/(["\$\@\\])/\\$1/g; | |||||||||||||||||||||||||||
| 159 | 31 | $text =~ s/\n/\\n/g; | |||||||||||||||||||||||||||
| 160 | 31 | return '"' . $text . '"'; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 3635 | ▶ | $text =~ s{'}{\\'}g if index( $text, q{'} ) != -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 3635 | return q{'} . $text . q{'}; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 168 | # quoted(\@items) "foo$bar" | ||||||||||||||||||||||||||||
| 169 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 173 | ▶ | sub quoted { | ||||||||||||||||||||||||||
|
Subroutine
quoted: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 172 | 173 | my ($self, $items) = @_; | |||||||||||||||||||||||||||
| 173 | 173 | ▶ | return '' unless @$items; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 173 | ▶ | return ("('' . " . $items->[0] . ')') if scalar @$items == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 121 | return '(' . join(' . ', @$items) . ')'; | |||||||||||||||||||||||||||
| 176 | # my $r = '(' . join(' . ', @$items) . ' . "")'; | ||||||||||||||||||||||||||||
| 177 | # print STDERR "[$r]\n"; | ||||||||||||||||||||||||||||
| 178 | # return $r; | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 183 | # ident(\@ident) foo.bar(baz) | ||||||||||||||||||||||||||||
| 184 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 3480 | ▶ | sub ident { | ||||||||||||||||||||||||||
|
Subroutine
ident: called CC=13 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 187 | 3480 | my ($self, $ident) = @_; | |||||||||||||||||||||||||||
| 188 | 3480 | ▶ | return "''" unless @$ident; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 3480 | my $ns; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | # Careful! Template::Parser always creates a Template::Directive object | ||||||||||||||||||||||||||||
| 192 | # (as of v2.22_1) so $self is usually an object. However, we used to | ||||||||||||||||||||||||||||
| 193 | # allow Template::Directive methods to be called as class methods and | ||||||||||||||||||||||||||||
| 194 | # Template::Namespace::Constants module takes advantage of this fact | ||||||||||||||||||||||||||||
| 195 | # by calling Template::Directive->ident() when it needs to generate an | ||||||||||||||||||||||||||||
| 196 | # identifier. This hack guards against Mr Fuckup from coming to town | ||||||||||||||||||||||||||||
| 197 | # when that happens. | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 3480 | ▶ | if (ref $self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | # trace variable usage | ||||||||||||||||||||||||||||
| 201 | 3479 | ▶ | if ($self->{ TRACE_VARS }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 9 | my $root = $self->{ TRACE_VARS }; | |||||||||||||||||||||||||||
| 203 | 9 | my $n = 0; | |||||||||||||||||||||||||||
| 204 | 9 | my $v; | |||||||||||||||||||||||||||
| 205 | 9 | ▶ | while ($n < @$ident) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 13 | $v = $ident->[$n]; | |||||||||||||||||||||||||||
| 207 | 13 | for ($v) { s/^'//; s/'$// }; | |||||||||||||||||||||||||||
| 208 | 13 | ▶ | $root = $root->{ $v } ||= { }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$root->{$v} ||= {}
MC/DC0%0/1
$root->{$v} ||= {}
$root->{$v}
Truth table50%1/2
A
A= $root->{$v}
| |||||||||||||||||||||||||||||
| 209 | 13 | $n += 2; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | # does the first element of the identifier have a NAMESPACE | ||||||||||||||||||||||||||||
| 214 | # handler defined? | ||||||||||||||||||||||||||||
| 215 | 3479 | ▶ | if (@$ident > 2 && ($ns = $self->{ NAMESPACE })) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$ident > 2 and $ns = $self->{"NAMESPACE"}
MC/DC100%2/2
@$ident > 2 and $ns = $self->{"NAMESPACE"}
@$ident > 2
$ns = $self->{"NAMESPACE"}
Truth table100%3/3
A and B
A= @$ident > 2B= $ns = $self->{"NAMESPACE"}
| |||||||||||||||||||||||||||||
| 216 | 56 | my $key = $ident->[0]; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | # a faster alternate to $key =~ s/^'(.+)'$/$1/s | ||||||||||||||||||||||||||||
| 219 | 56 | ▶ | if ( index( $key, q[']) == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 56 | substr( $key, 0, 1, '' ); | |||||||||||||||||||||||||||
| 221 | 56 | substr( $key, -1, 1, '' ); # remove the last char blindly | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 56 | ▶ | if ($ns = $ns->{ $key }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 39 | return $ns->ident($ident); | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 3441 | ▶ | if (scalar @$ident <= 2 && ! $ident->[1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @$ident <= 2 and not $ident->[1]
MC/DC100%2/2
scalar @$ident <= 2 and not $ident->[1]
scalar @$ident <= 2
not $ident->[1]
Truth table100%3/3
A and not(B)
A= scalar @$ident <= 2B= not $ident->[1]
| |||||||||||||||||||||||||||||
| 231 | 1867 | $ident = $ident->[0]; | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | else { | ||||||||||||||||||||||||||||
| 234 | 1574 | $ident = '[' . join(', ', @$ident) . ']'; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | 3441 | return "\$stash->get($ident)"; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 240 | # identref(\@ident) \foo.bar(baz) | ||||||||||||||||||||||||||||
| 241 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 6 | ▶ | sub identref { | ||||||||||||||||||||||||||
|
Subroutine
identref: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 244 | 6 | my ($self, $ident) = @_; | |||||||||||||||||||||||||||
| 245 | 6 | ▶ | return "''" unless @$ident; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 6 | ▶ | if (scalar @$ident <= 2 && ! $ident->[1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @$ident <= 2 and not $ident->[1]
MC/DC100%2/2
scalar @$ident <= 2 and not $ident->[1]
scalar @$ident <= 2
not $ident->[1]
Truth table100%3/3
A and not(B)
A= scalar @$ident <= 2B= not $ident->[1]
| |||||||||||||||||||||||||||||
| 247 | 3 | $ident = $ident->[0]; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | else { | ||||||||||||||||||||||||||||
| 250 | 3 | $ident = '[' . join(', ', @$ident) . ']'; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | 6 | return "\$stash->getref($ident)"; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 257 | # assign(\@ident, $value, $default) foo = bar | ||||||||||||||||||||||||||||
| 258 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 541 | ▶ | sub assign { | ||||||||||||||||||||||||||
|
Subroutine
assign: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 261 | 541 | my ($self, $var, $val, $default) = @_; | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 541 | ▶ | if (ref $var) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 537 | ▶ | if (scalar @$var == 2 && ! $var->[1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @$var == 2 and not $var->[1]
MC/DC50%1/2
scalar @$var == 2 and not $var->[1]
scalar @$var == 2
not $var->[1]
Truth table66%2/3
A and not(B)
A= scalar @$var == 2B= not $var->[1]
| |||||||||||||||||||||||||||||
| 265 | 468 | $var = $var->[0]; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | else { | ||||||||||||||||||||||||||||
| 268 | 69 | $var = '[' . join(', ', @$var) . ']'; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | 541 | ▶ | $val .= ', 1' if $default; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 541 | return "\$stash->set($var, $val)"; | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 277 | # args(\@args) foo, bar, baz = qux | ||||||||||||||||||||||||||||
| 278 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 979 | ▶ | sub args { | ||||||||||||||||||||||||||
|
Subroutine
args: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 281 | 979 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 282 | 979 | my $hash = shift @$args; | |||||||||||||||||||||||||||
| 283 | 979 | ▶ | push(@$args, '{ ' . join(', ', @$hash) . ' }') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | if @$hash; | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 979 | ▶ | return '0' unless @$args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 806 | return '[ ' . join(', ', @$args) . ' ]'; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 291 | # filenames(\@names) | ||||||||||||||||||||||||||||
| 292 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 210 | ▶ | sub filenames { | ||||||||||||||||||||||||||
|
Subroutine
filenames: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 295 | 210 | my ($self, $names) = @_; | |||||||||||||||||||||||||||
| 296 | 210 | ▶ | if (@$names > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 4 | $names = '[ ' . join(', ', @$names) . ' ]'; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | else { | ||||||||||||||||||||||||||||
| 300 | 206 | $names = shift @$names; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | 210 | return $names; | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 307 | # get($expr) [% foo %] | ||||||||||||||||||||||||||||
| 308 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 2304 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 311 | 2304 | my ($self, $expr) = @_; | |||||||||||||||||||||||||||
| 312 | 2304 | return "$OUTPUT $expr;"; | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 317 | # call($expr) [% CALL bar %] | ||||||||||||||||||||||||||||
| 318 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 30 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 321 | 30 | my ($self, $expr) = @_; | |||||||||||||||||||||||||||
| 322 | 30 | $expr .= ';'; | |||||||||||||||||||||||||||
| 323 | 30 | return $expr; | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 328 | # set(\@setlist) [% foo = bar, baz = qux %] | ||||||||||||||||||||||||||||
| 329 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 440 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 332 | 440 | my ($self, $setlist) = @_; | |||||||||||||||||||||||||||
| 333 | 440 | my $output; | |||||||||||||||||||||||||||
| 334 | 440 | ▶ | while (my ($var, $val) = splice(@$setlist, 0, 2)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | 502 | $output .= &assign($self, $var, $val) . ";\n"; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | 440 | chomp $output; | |||||||||||||||||||||||||||
| 338 | 440 | return $output; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 343 | # default(\@setlist) [% DEFAULT foo = bar, baz = qux %] | ||||||||||||||||||||||||||||
| 344 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 26 | ▶ | sub default { | ||||||||||||||||||||||||||
|
Subroutine
default: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 347 | 26 | my ($self, $setlist) = @_; | |||||||||||||||||||||||||||
| 348 | 26 | my $output; | |||||||||||||||||||||||||||
| 349 | 26 | ▶ | while (my ($var, $val) = splice(@$setlist, 0, 2)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 33 | $output .= &assign($self, $var, $val, 1) . ";\n"; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | 26 | chomp $output; | |||||||||||||||||||||||||||
| 353 | 26 | return $output; | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 358 | # insert(\@nameargs) [% INSERT file %] | ||||||||||||||||||||||||||||
| 359 | # # => [ [ $file, ... ], \@args ] | ||||||||||||||||||||||||||||
| 360 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 15 | ▶ | sub insert { | ||||||||||||||||||||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 363 | 15 | my ($self, $nameargs) = @_; | |||||||||||||||||||||||||||
| 364 | 15 | my ($file, $args) = @$nameargs; | |||||||||||||||||||||||||||
| 365 | 15 | $file = $self->filenames($file); | |||||||||||||||||||||||||||
| 366 | 15 | return "$OUTPUT \$context->insert($file);"; | |||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 371 | # include(\@nameargs) [% INCLUDE template foo = bar %] | ||||||||||||||||||||||||||||
| 372 | # # => [ [ $file, ... ], \@args ] | ||||||||||||||||||||||||||||
| 373 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 158 | ▶ | sub include { | ||||||||||||||||||||||||||
|
Subroutine
include: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 376 | 158 | my ($self, $nameargs) = @_; | |||||||||||||||||||||||||||
| 377 | 158 | my ($file, $args) = @$nameargs; | |||||||||||||||||||||||||||
| 378 | 158 | my $hash = shift @$args; | |||||||||||||||||||||||||||
| 379 | 158 | $file = $self->filenames($file); | |||||||||||||||||||||||||||
| 380 | 158 | ▶ | $file .= @$hash ? ', { ' . join(', ', @$hash) . ' }' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 381 | 158 | return "$OUTPUT \$context->include($file);"; | |||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 386 | # process(\@nameargs) [% PROCESS template foo = bar %] | ||||||||||||||||||||||||||||
| 387 | # # => [ [ $file, ... ], \@args ] | ||||||||||||||||||||||||||||
| 388 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 37 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 391 | 37 | my ($self, $nameargs) = @_; | |||||||||||||||||||||||||||
| 392 | 37 | my ($file, $args) = @$nameargs; | |||||||||||||||||||||||||||
| 393 | 37 | my $hash = shift @$args; | |||||||||||||||||||||||||||
| 394 | 37 | $file = $self->filenames($file); | |||||||||||||||||||||||||||
| 395 | 37 | ▶ | $file .= @$hash ? ', { ' . join(', ', @$hash) . ' }' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 396 | 37 | return "$OUTPUT \$context->process($file);"; | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 401 | # if($expr, $block, $else) [% IF foo < bar %] | ||||||||||||||||||||||||||||
| 402 | # ... | ||||||||||||||||||||||||||||
| 403 | # [% ELSE %] | ||||||||||||||||||||||||||||
| 404 | # ... | ||||||||||||||||||||||||||||
| 405 | # [% END %] | ||||||||||||||||||||||||||||
| 406 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 87 | ▶ | sub if { | ||||||||||||||||||||||||||
|
Subroutine
if: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 409 | 87 | my ($self, $expr, $block, $else) = @_; | |||||||||||||||||||||||||||
| 410 | 87 | ▶ | my @else = $else ? @$else : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | 87 | $else = pop @else; | |||||||||||||||||||||||||||
| 412 | 87 | ▶ | $block = pad($block, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 87 | my $output = "if ($expr) {\n$block\n}\n"; | |||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 87 | foreach my $elsif (@else) { | |||||||||||||||||||||||||||
| 417 | 8 | ($expr, $block) = @$elsif; | |||||||||||||||||||||||||||
| 418 | 8 | ▶ | $block = pad($block, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 419 | 8 | $output .= "elsif ($expr) {\n$block\n}\n"; | |||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | 87 | ▶ | if (defined $else) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 422 | 38 | ▶ | $else = pad($else, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | 38 | $output .= "else {\n$else\n}\n"; | |||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 87 | return $output; | |||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 431 | # foreach($target, $list, $args, $block) [% FOREACH x = [ foo bar ] %] | ||||||||||||||||||||||||||||
| 432 | # ... | ||||||||||||||||||||||||||||
| 433 | # [% END %] | ||||||||||||||||||||||||||||
| 434 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 251 | ▶ | sub foreach { | ||||||||||||||||||||||||||
|
Subroutine
foreach: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 437 | 251 | my ($self, $target, $list, $args, $block, $label) = @_; | |||||||||||||||||||||||||||
| 438 | 251 | $args = shift @$args; | |||||||||||||||||||||||||||
| 439 | 251 | ▶ | $args = @$args ? ', { ' . join(', ', @$args) . ' }' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | 251 | ▶ | $label ||= 'LOOP'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$label ||= "LOOP"
MC/DC100%1/1
$label ||= "LOOP"
$label
Truth table100%2/2
A
A= $label
| |||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 251 | my ($loop_save, $loop_set, $loop_restore, $setiter); | |||||||||||||||||||||||||||
| 443 | 251 | ▶ | if ($target) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | 239 | $loop_save = 'eval { $_tt_oldloop = ' . &ident($self, ["'loop'"]) . ' }'; | |||||||||||||||||||||||||||
| 445 | 239 | $loop_set = "\$stash->{'$target'} = \$_tt_value"; | |||||||||||||||||||||||||||
| 446 | 239 | $loop_restore = "\$stash->set('loop', \$_tt_oldloop)"; | |||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | else { | ||||||||||||||||||||||||||||
| 449 | 12 | $loop_save = '$stash = $context->localise()'; | |||||||||||||||||||||||||||
| 450 | # $loop_set = "\$stash->set('import', \$_tt_value) " | ||||||||||||||||||||||||||||
| 451 | # . "if ref \$value eq 'HASH'"; | ||||||||||||||||||||||||||||
| 452 | 12 | $loop_set = "\$stash->get(['import', [\$_tt_value]]) " | |||||||||||||||||||||||||||
| 453 | . "if ref \$_tt_value eq 'HASH'"; | ||||||||||||||||||||||||||||
| 454 | 12 | $loop_restore = '$stash = $context->delocalise()'; | |||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||
| 456 | 251 | ▶ | $block = pad($block, 3) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 251 | return <<EOF; | |||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | # FOREACH | ||||||||||||||||||||||||||||
| 461 | do { | ||||||||||||||||||||||||||||
| 462 | my (\$_tt_value, \$_tt_error, \$_tt_oldloop); | ||||||||||||||||||||||||||||
| 463 | my \$_tt_list = $list; | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | unless (UNIVERSAL::isa(\$_tt_list, 'Template::Iterator')) { | ||||||||||||||||||||||||||||
| 466 | \$_tt_list = Template::Config->iterator(\$_tt_list) | ||||||||||||||||||||||||||||
| 467 | || die \$Template::Config::ERROR, "\\n"; | ||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | (\$_tt_value, \$_tt_error) = \$_tt_list->get_first(); | ||||||||||||||||||||||||||||
| 471 | $loop_save; | ||||||||||||||||||||||||||||
| 472 | \$stash->set('loop', \$_tt_list); | ||||||||||||||||||||||||||||
| 473 | eval { | ||||||||||||||||||||||||||||
| 474 | $label: while (! \$_tt_error) { | ||||||||||||||||||||||||||||
| 475 | $loop_set; | ||||||||||||||||||||||||||||
| 476 | $block; | ||||||||||||||||||||||||||||
| 477 | (\$_tt_value, \$_tt_error) = \$_tt_list->get_next(); | ||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||
| 479 | }; | ||||||||||||||||||||||||||||
| 480 | $loop_restore; | ||||||||||||||||||||||||||||
| 481 | die \$@ if \$@; | ||||||||||||||||||||||||||||
| 482 | \$_tt_error = 0 if \$_tt_error && \$_tt_error eq Template::Constants::STATUS_DONE; | ||||||||||||||||||||||||||||
| 483 | die \$_tt_error if \$_tt_error; | ||||||||||||||||||||||||||||
| 484 | }; | ||||||||||||||||||||||||||||
| 485 | EOF | ||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 489 | # next() [% NEXT %] | ||||||||||||||||||||||||||||
| 490 | # | ||||||||||||||||||||||||||||
| 491 | # Next iteration of a FOREACH loop (experimental) | ||||||||||||||||||||||||||||
| 492 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | 10 | ▶ | sub next { | ||||||||||||||||||||||||||
|
Subroutine
next: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 495 | 10 | my ($self, $label) = @_; | |||||||||||||||||||||||||||
| 496 | 10 | ▶ | $label ||= 'LOOP'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$label ||= "LOOP"
MC/DC0%0/1
$label ||= "LOOP"
$label
Truth table50%1/2
A
A= $label
| |||||||||||||||||||||||||||||
| 497 | 10 | return <<EOF; | |||||||||||||||||||||||||||
| 498 | (\$_tt_value, \$_tt_error) = \$_tt_list->get_next(); | ||||||||||||||||||||||||||||
| 499 | next $label; | ||||||||||||||||||||||||||||
| 500 | EOF | ||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 505 | # wrapper(\@nameargs, $block) [% WRAPPER template foo = bar %] | ||||||||||||||||||||||||||||
| 506 | # # => [ [$file,...], \@args ] | ||||||||||||||||||||||||||||
| 507 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 13 | ▶ | sub wrapper { | ||||||||||||||||||||||||||
|
Subroutine
wrapper: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 510 | 13 | my ($self, $nameargs, $block) = @_; | |||||||||||||||||||||||||||
| 511 | 13 | my ($file, $args) = @$nameargs; | |||||||||||||||||||||||||||
| 512 | 13 | my $hash = shift @$args; | |||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | 13 | local $" = ', '; | |||||||||||||||||||||||||||
| 515 | # print STDERR "wrapper([@$file], { @$hash })\n"; | ||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | 13 | ▶ | return $self->multi_wrapper($file, $hash, $block) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 518 | if @$file > 1; | ||||||||||||||||||||||||||||
| 519 | 11 | $file = shift @$file; | |||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | 11 | ▶ | $block = pad($block, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 522 | 11 | push(@$hash, "'content'", '$output'); | |||||||||||||||||||||||||||
| 523 | 11 | ▶ | $file .= @$hash ? ', { ' . join(', ', @$hash) . ' }' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | 11 | return <<EOF; | |||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | # WRAPPER | ||||||||||||||||||||||||||||
| 528 | $OUTPUT do { | ||||||||||||||||||||||||||||
| 529 | my \$output = ''; | ||||||||||||||||||||||||||||
| 530 | $block | ||||||||||||||||||||||||||||
| 531 | \$context->include($file); | ||||||||||||||||||||||||||||
| 532 | }; | ||||||||||||||||||||||||||||
| 533 | EOF | ||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | 2 | ▶ | sub multi_wrapper { | ||||||||||||||||||||||||||
|
Subroutine
multi_wrapper: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 538 | 2 | my ($self, $file, $hash, $block) = @_; | |||||||||||||||||||||||||||
| 539 | 2 | ▶ | $block = pad($block, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | 2 | push(@$hash, "'content'", '$output'); | |||||||||||||||||||||||||||
| 542 | 2 | ▶ | $hash = @$hash ? ', { ' . join(', ', @$hash) . ' }' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 2 | $file = join(', ', reverse @$file); | |||||||||||||||||||||||||||
| 545 | # print STDERR "multi wrapper: $file\n"; | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | 2 | return <<EOF; | |||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | # WRAPPER | ||||||||||||||||||||||||||||
| 550 | $OUTPUT do { | ||||||||||||||||||||||||||||
| 551 | my \$output = ''; | ||||||||||||||||||||||||||||
| 552 | $block | ||||||||||||||||||||||||||||
| 553 | foreach ($file) { | ||||||||||||||||||||||||||||
| 554 | \$output = \$context->include(\$_$hash); | ||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | \$output; | ||||||||||||||||||||||||||||
| 557 | }; | ||||||||||||||||||||||||||||
| 558 | EOF | ||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 563 | # while($expr, $block) [% WHILE x < 10 %] | ||||||||||||||||||||||||||||
| 564 | # ... | ||||||||||||||||||||||||||||
| 565 | # [% END %] | ||||||||||||||||||||||||||||
| 566 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | 18 | ▶ | sub while { | ||||||||||||||||||||||||||
|
Subroutine
while: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 569 | 18 | my ($self, $expr, $block, $label) = @_; | |||||||||||||||||||||||||||
| 570 | 18 | ▶ | $block = pad($block, 2) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 571 | 18 | ▶ | $label ||= 'LOOP'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$label ||= "LOOP"
MC/DC100%1/1
$label ||= "LOOP"
$label
Truth table100%2/2
A
A= $label
| |||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | 18 | return <<EOF; | |||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | # WHILE | ||||||||||||||||||||||||||||
| 576 | do { | ||||||||||||||||||||||||||||
| 577 | my \$_tt_failsafe = $WHILE_MAX; | ||||||||||||||||||||||||||||
| 578 | $label: | ||||||||||||||||||||||||||||
| 579 | while (($expr) && --\$_tt_failsafe >= 0) { | ||||||||||||||||||||||||||||
| 580 | $block | ||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | \$context->throw('while', "WHILE loop terminated (> $WHILE_MAX iterations)") | ||||||||||||||||||||||||||||
| 583 | if \$_tt_failsafe < 0; | ||||||||||||||||||||||||||||
| 584 | }; | ||||||||||||||||||||||||||||
| 585 | EOF | ||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 590 | # switch($expr, \@case) [% SWITCH %] | ||||||||||||||||||||||||||||
| 591 | # [% CASE foo %] | ||||||||||||||||||||||||||||
| 592 | # ... | ||||||||||||||||||||||||||||
| 593 | # [% END %] | ||||||||||||||||||||||||||||
| 594 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | 20 | ▶ | sub switch { | ||||||||||||||||||||||||||
|
Subroutine
switch: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 597 | 20 | my ($self, $expr, $case) = @_; | |||||||||||||||||||||||||||
| 598 | 20 | my @case = @$case; | |||||||||||||||||||||||||||
| 599 | 20 | my ($match, $block, $default); | |||||||||||||||||||||||||||
| 600 | 20 | my $caseblock = ''; | |||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | 20 | $default = pop @case; | |||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | 20 | foreach $case (@case) { | |||||||||||||||||||||||||||
| 605 | 31 | $match = $case->[0]; | |||||||||||||||||||||||||||
| 606 | 31 | $block = $case->[1]; | |||||||||||||||||||||||||||
| 607 | 31 | ▶ | $block = pad($block, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 608 | 31 | $caseblock .= <<EOF; | |||||||||||||||||||||||||||
| 609 | \$_tt_match = $match; | ||||||||||||||||||||||||||||
| 610 | \$_tt_match = [ \$_tt_match ] unless ref \$_tt_match eq 'ARRAY'; | ||||||||||||||||||||||||||||
| 611 | if (grep(/^\\Q\$_tt_result\\E\$/, \@\$_tt_match)) { | ||||||||||||||||||||||||||||
| 612 | $block | ||||||||||||||||||||||||||||
| 613 | last SWITCH; | ||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||
| 615 | EOF | ||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | 20 | ▶ | $caseblock .= $default | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 619 | if defined $default; | ||||||||||||||||||||||||||||
| 620 | 20 | ▶ | $caseblock = pad($caseblock, 2) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | 20 | return <<EOF; | |||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | # SWITCH | ||||||||||||||||||||||||||||
| 625 | do { | ||||||||||||||||||||||||||||
| 626 | my \$_tt_result = $expr; | ||||||||||||||||||||||||||||
| 627 | my \$_tt_match; | ||||||||||||||||||||||||||||
| 628 | SWITCH: { | ||||||||||||||||||||||||||||
| 629 | $caseblock | ||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||
| 631 | }; | ||||||||||||||||||||||||||||
| 632 | EOF | ||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 637 | # try($block, \@catch) [% TRY %] | ||||||||||||||||||||||||||||
| 638 | # ... | ||||||||||||||||||||||||||||
| 639 | # [% CATCH %] | ||||||||||||||||||||||||||||
| 640 | # ... | ||||||||||||||||||||||||||||
| 641 | # [% END %] | ||||||||||||||||||||||||||||
| 642 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||
| 644 | 136 | ▶ | sub try { | ||||||||||||||||||||||||||
|
Subroutine
try: called CC=13 SCAR=26.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 645 | 136 | my ($self, $block, $catch) = @_; | |||||||||||||||||||||||||||
| 646 | 136 | my @catch = @$catch; | |||||||||||||||||||||||||||
| 647 | 136 | my ($match, $mblock, $default, $final, $n); | |||||||||||||||||||||||||||
| 648 | 136 | my $catchblock = ''; | |||||||||||||||||||||||||||
| 649 | 136 | my $handlers = []; | |||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||
| 651 | 136 | ▶ | $block = pad($block, 2) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 652 | 136 | $final = pop @catch; | |||||||||||||||||||||||||||
| 653 | 136 | ▶ | $final = "# FINAL\n" . ($final ? "$final\n" : '') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 654 | . 'die $_tt_error if $_tt_error;' . "\n" . '$output;'; | ||||||||||||||||||||||||||||
| 655 | 136 | ▶ | $final = pad($final, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | 136 | $n = 0; | |||||||||||||||||||||||||||
| 658 | 136 | foreach $catch (@catch) { | |||||||||||||||||||||||||||
| 659 | 181 | ▶ | $match = $catch->[0] || do { | ||||||||||||||||||||||||||
|
Condition100%3/3
$catch->[0] || do {
$default ||= $catch->[1];
next
}
MC/DC0%0/2
$catch->[0] || do {
$default ||= $catch->[1];
next
}
$catch->[0]
do {
$default ||= $catch->[1];
next
}
Truth table33%1/3
A || B
A= $catch->[0]B= do {
$default ||= $catch->[1];
next
}
| |||||||||||||||||||||||||||||
| 660 | 111 | ▶ | $default ||= $catch->[1]; | ||||||||||||||||||||||||||
|
Condition33%1/3
$default ||= $catch->[1]
MC/DC0%0/2
$default ||= $catch->[1]
$default
$catch->[1]
Truth table33%1/3
A ||= B
A= $defaultB= $catch->[1]
| |||||||||||||||||||||||||||||
| 661 | 111 | next; | |||||||||||||||||||||||||||
| 662 | }; | ||||||||||||||||||||||||||||
| 663 | 70 | $mblock = $catch->[1]; | |||||||||||||||||||||||||||
| 664 | 70 | ▶ | $mblock = pad($mblock, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 665 | 70 | push(@$handlers, "'$match'"); | |||||||||||||||||||||||||||
| 666 | 70 | ▶ | $catchblock .= $n++ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 667 | ? "elsif (\$_tt_handler eq '$match') {\n$mblock\n}\n" | ||||||||||||||||||||||||||||
| 668 | : "if (\$_tt_handler eq '$match') {\n$mblock\n}\n"; | ||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||
| 670 | 136 | $catchblock .= "\$_tt_error = 0;"; | |||||||||||||||||||||||||||
| 671 | 136 | ▶ | $catchblock = pad($catchblock, 3) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 672 | 136 | ▶ | if ($default) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 673 | 111 | ▶ | $default = pad($default, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 674 | 111 | $default = "else {\n # DEFAULT\n$default\n \$_tt_error = '';\n}"; | |||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||
| 676 | else { | ||||||||||||||||||||||||||||
| 677 | 25 | $default = '# NO DEFAULT'; | |||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||
| 679 | 136 | ▶ | $default = pad($default, 2) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||
| 681 | 136 | $handlers = join(', ', @$handlers); | |||||||||||||||||||||||||||
| 682 | 136 | return <<EOF; | |||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||
| 684 | # TRY | ||||||||||||||||||||||||||||
| 685 | $OUTPUT do { | ||||||||||||||||||||||||||||
| 686 | my \$output = ''; | ||||||||||||||||||||||||||||
| 687 | my (\$_tt_error, \$_tt_handler); | ||||||||||||||||||||||||||||
| 688 | eval { | ||||||||||||||||||||||||||||
| 689 | $block | ||||||||||||||||||||||||||||
| 690 | }; | ||||||||||||||||||||||||||||
| 691 | if (\$@) { | ||||||||||||||||||||||||||||
| 692 | \$_tt_error = \$context->catch(\$@, \\\$output); | ||||||||||||||||||||||||||||
| 693 | die \$_tt_error if \$_tt_error->type =~ /^(return|stop)\$/; | ||||||||||||||||||||||||||||
| 694 | \$stash->set('error', \$_tt_error); | ||||||||||||||||||||||||||||
| 695 | \$stash->set('e', \$_tt_error); | ||||||||||||||||||||||||||||
| 696 | if (defined (\$_tt_handler = \$_tt_error->select_handler($handlers))) { | ||||||||||||||||||||||||||||
| 697 | $catchblock | ||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||
| 699 | $default | ||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||
| 701 | $final | ||||||||||||||||||||||||||||
| 702 | }; | ||||||||||||||||||||||||||||
| 703 | EOF | ||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||
| 707 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 708 | # throw(\@nameargs) [% THROW foo "bar error" %] | ||||||||||||||||||||||||||||
| 709 | # # => [ [$type], \@args ] | ||||||||||||||||||||||||||||
| 710 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||
| 712 | 37 | ▶ | sub throw { | ||||||||||||||||||||||||||
|
Subroutine
throw: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 713 | 37 | my ($self, $nameargs) = @_; | |||||||||||||||||||||||||||
| 714 | 37 | my ($type, $args) = @$nameargs; | |||||||||||||||||||||||||||
| 715 | 37 | my $hash = shift(@$args); | |||||||||||||||||||||||||||
| 716 | 37 | my $info = shift(@$args); | |||||||||||||||||||||||||||
| 717 | 37 | $type = shift @$type; # uses same parser production as INCLUDE | |||||||||||||||||||||||||||
| 718 | # etc., which allow multiple names | ||||||||||||||||||||||||||||
| 719 | # e.g. INCLUDE foo+bar+baz | ||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | 37 | ▶ | if (! $info) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 722 | 5 | $args = "$type, undef"; | |||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||
| 724 | ▶ | elsif (@$hash || @$args) { | |||||||||||||||||||||||||||
|
Condition66%2/3
@$hash or @$args
MC/DC50%1/2
@$hash or @$args
@$hash
@$args
Truth table66%2/3
A or B
A= @$hashB= @$args
| |||||||||||||||||||||||||||||
| 725 | 4 | local $" = ', '; | |||||||||||||||||||||||||||
| 726 | 4 | my $i = 0; | |||||||||||||||||||||||||||
| 727 | $args = "$type, { args => [ " | ||||||||||||||||||||||||||||
| 728 | . join(', ', $info, @$args) | ||||||||||||||||||||||||||||
| 729 | . ' ], ' | ||||||||||||||||||||||||||||
| 730 | . join(', ', | ||||||||||||||||||||||||||||
| 731 | 4 | (map { "'" . $i++ . "' => $_" } ($info, @$args)), | |||||||||||||||||||||||||||
| 732 | @$hash) | ||||||||||||||||||||||||||||
| 733 | . ' }'; | ||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||
| 735 | else { | ||||||||||||||||||||||||||||
| 736 | 28 | $args = "$type, $info"; | |||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | 37 | return "\$context->throw($args, \\\$output);"; | |||||||||||||||||||||||||||
| 740 | } | ||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||
| 743 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 744 | # clear() [% CLEAR %] | ||||||||||||||||||||||||||||
| 745 | # | ||||||||||||||||||||||||||||
| 746 | # NOTE: this is redundant, being hard-coded (for now) into Parser.yp | ||||||||||||||||||||||||||||
| 747 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||
| 749 | 0 | ▶ | sub clear { | ||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 750 | 0 | return "\$output = '';"; | |||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||
| 753 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 754 | # break() [% BREAK %] | ||||||||||||||||||||||||||||
| 755 | # | ||||||||||||||||||||||||||||
| 756 | # NOTE: this is redundant, being hard-coded (for now) into Parser.yp | ||||||||||||||||||||||||||||
| 757 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||
| 759 | 0 | ▶ | sub OLD_break { | ||||||||||||||||||||||||||
|
Subroutine
OLD_break: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 760 | 0 | return 'last LOOP;'; | |||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||
| 763 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 764 | # return() [% RETURN %] | ||||||||||||||||||||||||||||
| 765 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||
| 767 | 2 | ▶ | sub return { | ||||||||||||||||||||||||||
|
Subroutine
return: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 768 | 2 | return "\$context->throw('return', '', \\\$output);"; | |||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||
| 771 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 772 | # stop() [% STOP %] | ||||||||||||||||||||||||||||
| 773 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||
| 775 | 4 | ▶ | sub stop { | ||||||||||||||||||||||||||
|
Subroutine
stop: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 776 | 4 | return "\$context->throw('stop', '', \\\$output);"; | |||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||
| 780 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 781 | # use(\@lnameargs) [% USE alias = plugin(args) %] | ||||||||||||||||||||||||||||
| 782 | # # => [ [$file, ...], \@args, $alias ] | ||||||||||||||||||||||||||||
| 783 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||
| 785 | 253 | ▶ | sub use { | ||||||||||||||||||||||||||
|
Subroutine
use: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 786 | 253 | my ($self, $lnameargs) = @_; | |||||||||||||||||||||||||||
| 787 | 253 | my ($file, $args, $alias) = @$lnameargs; | |||||||||||||||||||||||||||
| 788 | 253 | $file = shift @$file; # same production rule as INCLUDE | |||||||||||||||||||||||||||
| 789 | 253 | ▶ | $alias ||= $file; | ||||||||||||||||||||||||||
|
Condition66%2/3
$alias ||= $file
MC/DC0%0/2
$alias ||= $file
$alias
$file
Truth table66%2/3
A ||= B
A= $aliasB= $file
| |||||||||||||||||||||||||||||
| 790 | 253 | $args = &args($self, $args); | |||||||||||||||||||||||||||
| 791 | 253 | ▶ | $file .= ", $args" if $args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 792 | # my $set = &assign($self, $alias, '$plugin'); | ||||||||||||||||||||||||||||
| 793 | 253 | return "# USE\n" | |||||||||||||||||||||||||||
| 794 | . "\$stash->set($alias,\n" | ||||||||||||||||||||||||||||
| 795 | . " \$context->plugin($file));"; | ||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||
| 798 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 799 | # view(\@nameargs, $block) [% VIEW name args %] | ||||||||||||||||||||||||||||
| 800 | # # => [ [$file, ... ], \@args ] | ||||||||||||||||||||||||||||
| 801 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||
| 803 | 31 | ▶ | sub view { | ||||||||||||||||||||||||||
|
Subroutine
view: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 804 | 31 | my ($self, $nameargs, $block, $defblocks) = @_; | |||||||||||||||||||||||||||
| 805 | 31 | my ($name, $args) = @$nameargs; | |||||||||||||||||||||||||||
| 806 | 31 | my $hash = shift @$args; | |||||||||||||||||||||||||||
| 807 | 31 | $name = shift @$name; # same production rule as INCLUDE | |||||||||||||||||||||||||||
| 808 | 31 | ▶ | $block = pad($block, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||
| 810 | 31 | ▶ | if (%$defblocks) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 811 | 16 | $defblocks = join(",\n", map { "'$_' => $defblocks->{ $_ }" } | |||||||||||||||||||||||||||
| 812 | keys %$defblocks); | ||||||||||||||||||||||||||||
| 813 | 16 | ▶ | $defblocks = pad($defblocks, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 814 | 16 | $defblocks = "{\n$defblocks\n}"; | |||||||||||||||||||||||||||
| 815 | 16 | push(@$hash, "'blocks'", $defblocks); | |||||||||||||||||||||||||||
| 816 | } | ||||||||||||||||||||||||||||
| 817 | 31 | ▶ | $hash = @$hash ? '{ ' . join(', ', @$hash) . ' }' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||
| 819 | 31 | return <<EOF; | |||||||||||||||||||||||||||
| 820 | # VIEW | ||||||||||||||||||||||||||||
| 821 | do { | ||||||||||||||||||||||||||||
| 822 | my \$output = ''; | ||||||||||||||||||||||||||||
| 823 | my \$_tt_oldv = \$stash->get('view'); | ||||||||||||||||||||||||||||
| 824 | my \$_tt_view = \$context->view($hash); | ||||||||||||||||||||||||||||
| 825 | \$stash->set($name, \$_tt_view); | ||||||||||||||||||||||||||||
| 826 | \$stash->set('view', \$_tt_view); | ||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||
| 828 | $block | ||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||
| 830 | \$stash->set('view', \$_tt_oldv); | ||||||||||||||||||||||||||||
| 831 | \$_tt_view->seal(); | ||||||||||||||||||||||||||||
| 832 | # \$output; # not used - commented out to avoid warning | ||||||||||||||||||||||||||||
| 833 | }; | ||||||||||||||||||||||||||||
| 834 | EOF | ||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||
| 838 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 839 | # perl($block) | ||||||||||||||||||||||||||||
| 840 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||
| 842 | 14 | ▶ | sub perl { | ||||||||||||||||||||||||||
|
Subroutine
perl: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 843 | 14 | my ($self, $block) = @_; | |||||||||||||||||||||||||||
| 844 | 14 | ▶ | $block = pad($block, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||
| 846 | 14 | return <<EOF; | |||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||
| 848 | # PERL | ||||||||||||||||||||||||||||
| 849 | \$context->throw('perl', 'EVAL_PERL not set') | ||||||||||||||||||||||||||||
| 850 | unless \$context->eval_perl(); | ||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||
| 852 | $OUTPUT do { | ||||||||||||||||||||||||||||
| 853 | my \$output = "package Template::Perl;\\n"; | ||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||
| 855 | $block | ||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||
| 857 | local(\$Template::Perl::context) = \$context; | ||||||||||||||||||||||||||||
| 858 | local(\$Template::Perl::stash) = \$stash; | ||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||
| 860 | my \$_tt_result = ''; | ||||||||||||||||||||||||||||
| 861 | tie *Template::Perl::PERLOUT, 'Template::TieString', \\\$_tt_result; | ||||||||||||||||||||||||||||
| 862 | my \$_tt_save_stdout = select *Template::Perl::PERLOUT; | ||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||
| 864 | eval \$output; | ||||||||||||||||||||||||||||
| 865 | select \$_tt_save_stdout; | ||||||||||||||||||||||||||||
| 866 | \$context->throw(\$@) if \$@; | ||||||||||||||||||||||||||||
| 867 | \$_tt_result; | ||||||||||||||||||||||||||||
| 868 | }; | ||||||||||||||||||||||||||||
| 869 | EOF | ||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||
| 873 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 874 | # no_perl() | ||||||||||||||||||||||||||||
| 875 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||
| 877 | 4 | ▶ | sub no_perl { | ||||||||||||||||||||||||||
|
Subroutine
no_perl: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 878 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 879 | 4 | return "\$context->throw('perl', 'EVAL_PERL not set');"; | |||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||
| 883 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 884 | # rawperl($block) | ||||||||||||||||||||||||||||
| 885 | # | ||||||||||||||||||||||||||||
| 886 | # NOTE: perhaps test context EVAL_PERL switch at compile time rather than | ||||||||||||||||||||||||||||
| 887 | # runtime? | ||||||||||||||||||||||||||||
| 888 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||
| 890 | 2 | ▶ | sub rawperl { | ||||||||||||||||||||||||||
|
Subroutine
rawperl: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 891 | 2 | my ($self, $block, $line) = @_; | |||||||||||||||||||||||||||
| 892 | 2 | for ($block) { | |||||||||||||||||||||||||||
| 893 | 2 | s/^\n+//; | |||||||||||||||||||||||||||
| 894 | 2 | s/\n+$//; | |||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||
| 896 | 2 | ▶ | $block = pad($block, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 897 | 2 | ▶ | $line = $line ? " (starting line $line)" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||
| 899 | 2 | return <<EOF; | |||||||||||||||||||||||||||
| 900 | # RAWPERL | ||||||||||||||||||||||||||||
| 901 | #line 1 "RAWPERL block$line" | ||||||||||||||||||||||||||||
| 902 | $block | ||||||||||||||||||||||||||||
| 903 | EOF | ||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||
| 908 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 909 | # filter() | ||||||||||||||||||||||||||||
| 910 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||
| 912 | 159 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 913 | 159 | my ($self, $lnameargs, $block) = @_; | |||||||||||||||||||||||||||
| 914 | 159 | my ($name, $args, $alias) = @$lnameargs; | |||||||||||||||||||||||||||
| 915 | 159 | $name = shift @$name; | |||||||||||||||||||||||||||
| 916 | 159 | $args = &args($self, $args); | |||||||||||||||||||||||||||
| 917 | 159 | ▶ | $args = $args ? "$args, $alias" : ", undef, $alias" | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 918 | if $alias; | ||||||||||||||||||||||||||||
| 919 | 159 | ▶ | $name .= ", $args" if $args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 920 | 159 | ▶ | $block = pad($block, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||
| 922 | 159 | return <<EOF; | |||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||
| 924 | # FILTER | ||||||||||||||||||||||||||||
| 925 | $OUTPUT do { | ||||||||||||||||||||||||||||
| 926 | my \$output = ''; | ||||||||||||||||||||||||||||
| 927 | my \$_tt_filter = \$context->filter($name) | ||||||||||||||||||||||||||||
| 928 | || \$context->throw(\$context->error); | ||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||
| 930 | $block | ||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||
| 932 | &\$_tt_filter(\$output); | ||||||||||||||||||||||||||||
| 933 | }; | ||||||||||||||||||||||||||||
| 934 | EOF | ||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||
| 938 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 939 | # capture($name, $block) | ||||||||||||||||||||||||||||
| 940 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||
| 942 | 12 | ▶ | sub capture { | ||||||||||||||||||||||||||
|
Subroutine
capture: called CC=5 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 943 | 12 | my ($self, $name, $block) = @_; | |||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||
| 945 | 12 | ▶ | if (ref $name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 946 | 12 | ▶ | if (scalar @$name == 2 && ! $name->[1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @$name == 2 and not $name->[1]
MC/DC0%0/2
scalar @$name == 2 and not $name->[1]
scalar @$name == 2
not $name->[1]
Truth table33%1/3
A and not(B)
A= scalar @$name == 2B= not $name->[1]
| |||||||||||||||||||||||||||||
| 947 | 12 | $name = $name->[0]; | |||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||
| 949 | else { | ||||||||||||||||||||||||||||
| 950 | 0 | $name = '[' . join(', ', @$name) . ']'; | |||||||||||||||||||||||||||
| 951 | } | ||||||||||||||||||||||||||||
| 952 | } | ||||||||||||||||||||||||||||
| 953 | 12 | ▶ | $block = pad($block, 1) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||
| 955 | 12 | return <<EOF; | |||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||
| 957 | # CAPTURE | ||||||||||||||||||||||||||||
| 958 | \$stash->set($name, do { | ||||||||||||||||||||||||||||
| 959 | my \$output = ''; | ||||||||||||||||||||||||||||
| 960 | $block | ||||||||||||||||||||||||||||
| 961 | \$output; | ||||||||||||||||||||||||||||
| 962 | }); | ||||||||||||||||||||||||||||
| 963 | EOF | ||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||
| 965 | } | ||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||
| 968 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 969 | # macro($name, $block, \@args) | ||||||||||||||||||||||||||||
| 970 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||
| 972 | 10 | ▶ | sub macro { | ||||||||||||||||||||||||||
|
Subroutine
macro: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 973 | 10 | my ($self, $ident, $block, $args) = @_; | |||||||||||||||||||||||||||
| 974 | 10 | ▶ | $block = pad($block, 2) if $PRETTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||
| 976 | 10 | ▶ | if ($args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 977 | 3 | my $nargs = scalar @$args; | |||||||||||||||||||||||||||
| 978 | 3 | $args = join(', ', map { "'$_'" } @$args); | |||||||||||||||||||||||||||
| 979 | 3 | ▶ | $args = $nargs > 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 980 | ? "\@_tt_args{ $args } = splice(\@_, 0, $nargs)" | ||||||||||||||||||||||||||||
| 981 | : "\$_tt_args{ $args } = shift"; | ||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||
| 983 | 3 | return <<EOF; | |||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||
| 985 | # MACRO | ||||||||||||||||||||||||||||
| 986 | \$stash->set('$ident', sub { | ||||||||||||||||||||||||||||
| 987 | my \$output = ''; | ||||||||||||||||||||||||||||
| 988 | my (%_tt_args, \$_tt_params); | ||||||||||||||||||||||||||||
| 989 | $args; | ||||||||||||||||||||||||||||
| 990 | \$_tt_params = shift; | ||||||||||||||||||||||||||||
| 991 | \$_tt_params = { } unless ref(\$_tt_params) eq 'HASH'; | ||||||||||||||||||||||||||||
| 992 | \$_tt_params = { \%_tt_args, %\$_tt_params }; | ||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||
| 994 | my \$stash = \$context->localise(\$_tt_params); | ||||||||||||||||||||||||||||
| 995 | eval { | ||||||||||||||||||||||||||||
| 996 | $block | ||||||||||||||||||||||||||||
| 997 | }; | ||||||||||||||||||||||||||||
| 998 | \$stash = \$context->delocalise(); | ||||||||||||||||||||||||||||
| 999 | die \$@ if \$@; | ||||||||||||||||||||||||||||
| 1000 | return \$output; | ||||||||||||||||||||||||||||
| 1001 | }); | ||||||||||||||||||||||||||||
| 1002 | EOF | ||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||
| 1004 | } | ||||||||||||||||||||||||||||
| 1005 | else { | ||||||||||||||||||||||||||||
| 1006 | 7 | return <<EOF; | |||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||
| 1008 | # MACRO | ||||||||||||||||||||||||||||
| 1009 | \$stash->set('$ident', sub { | ||||||||||||||||||||||||||||
| 1010 | my \$_tt_params = \$_[0] if ref(\$_[0]) eq 'HASH'; | ||||||||||||||||||||||||||||
| 1011 | my \$output = ''; | ||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||
| 1013 | my \$stash = \$context->localise(\$_tt_params); | ||||||||||||||||||||||||||||
| 1014 | eval { | ||||||||||||||||||||||||||||
| 1015 | $block | ||||||||||||||||||||||||||||
| 1016 | }; | ||||||||||||||||||||||||||||
| 1017 | \$stash = \$context->delocalise(); | ||||||||||||||||||||||||||||
| 1018 | die \$@ if \$@; | ||||||||||||||||||||||||||||
| 1019 | return \$output; | ||||||||||||||||||||||||||||
| 1020 | }); | ||||||||||||||||||||||||||||
| 1021 | EOF | ||||||||||||||||||||||||||||
| 1022 | } | ||||||||||||||||||||||||||||
| 1023 | } | ||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||
| 1026 | 15 | ▶ | sub debug { | ||||||||||||||||||||||||||
|
Subroutine
debug: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1027 | 15 | my ($self, $nameargs) = @_; | |||||||||||||||||||||||||||
| 1028 | 15 | my ($file, $args) = @$nameargs; | |||||||||||||||||||||||||||
| 1029 | 15 | my $hash = shift @$args; | |||||||||||||||||||||||||||
| 1030 | 15 | $args = join(', ', @$file, @$args); | |||||||||||||||||||||||||||
| 1031 | 15 | ▶ | $args .= @$hash ? ', { ' . join(', ', @$hash) . ' }' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1032 | 15 | return "$OUTPUT \$context->debugging($args); ## DEBUG ##"; | |||||||||||||||||||||||||||
| 1033 | } | ||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||
| 1036 | 106 | 1; | |||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||
| 1038 | __END__ | ||||||||||||||||||||||||||||