| 1 | package Template::Alloy::Compile; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | Template::Alloy::Compile - Compile role - allows for compiling the AST to perl code | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Template::Alloy; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Template::Alloy::Iterator; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | our $VERSION = $Template::Alloy::VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | our $INDENT = ' ' x 4; | |||||||||||||||||||||||||||||||||||||||||
| 16 | our $DIRECTIVES = { | ||||||||||||||||||||||||||||||||||||||||||
| 17 | BLOCK => \&compile_BLOCK, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | BREAK => \&compile_LAST, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | CALL => \&compile_CALL, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | CASE => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | CATCH => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | CLEAR => \&compile_CLEAR, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | '#' => sub {}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | COMMENT => sub {}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | CONFIG => \&compile_CONFIG, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | DEBUG => \&compile_DEBUG, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | DEFAULT => \&compile_DEFAULT, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | DUMP => \&compile_DUMP, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ELSE => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ELSIF => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 373 | ▶ | END => sub {}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | EVAL => \&compile_EVAL, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | FILTER => \&compile_FILTER, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | '|' => \&compile_FILTER, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | FINAL => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | FOR => \&compile_FOR, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | FOREACH => \&compile_FOR, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | GET => \&compile_GET, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | IF => \&compile_IF, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | INCLUDE => \&compile_INCLUDE, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | INSERT => \&compile_INSERT, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | JS => \&compile_JS, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | LAST => \&compile_LAST, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | LOOP => \&compile_LOOP, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | MACRO => \&compile_MACRO, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | META => \&compile_META, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | NEXT => \&compile_NEXT, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | PERL => \&compile_PERL, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | PROCESS => \&compile_PROCESS, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | RAWPERL => \&compile_RAWPERL, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | RETURN => \&compile_RETURN, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | SET => \&compile_SET, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | STOP => \&compile_STOP, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | SWITCH => \&compile_SWITCH, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 23 | ▶ | TAGS => sub {}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | THROW => \&compile_THROW, | |||||||||||||||||||||||||||||||||||||||||
| 57 | TRY => \&compile_TRY, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | UNLESS => \&compile_UNLESS, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | USE => \&compile_USE, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | VIEW => \&compile_VIEW, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | WHILE => \&compile_WHILE, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | WRAPPER => \&compile_WRAPPER, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub new { die "This class is a role for use by packages such as Template::Alloy" } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1693 | ▶ | sub load_perl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_perl: called CC=23 SCAR=32.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1693 | my ($self, $doc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | ### first look for a compiled perl document | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 1693 | my $perl; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 1693 | ▶ | if ($doc->{'_filename'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1692 | ▶ | $doc->{'modtime'} ||= (stat $doc->{'_filename'})[9]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$doc->{"modtime"} ||= (stat $doc->{"_filename"})[9]
MC/DC0%0/2
$doc->{"modtime"} ||= (stat $doc->{"_filename"})[9]
$doc->{"modtime"}
(stat $doc->{"_filename"})[9]
Truth table66%2/3
A ||= B
A= $doc->{"modtime"}B= (stat $doc->{"_filename"})[9]
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1692 | ▶ | if ($self->{'COMPILE_DIR'} || $self->{'COMPILE_EXT'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"COMPILE_DIR"} or $self->{"COMPILE_EXT"}
MC/DC100%2/2
$self->{"COMPILE_DIR"} or $self->{"COMPILE_EXT"}
$self->{"COMPILE_DIR"}
$self->{"COMPILE_EXT"}
Truth table100%3/3
A or B
A= $self->{"COMPILE_DIR"}B= $self->{"COMPILE_EXT"}
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 9 | my $file = $doc->{'_filename'}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 9 | ▶ | if ($self->{'COMPILE_DIR'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | ▶ | $file =~ y|:|/| if $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | $file = $self->{'COMPILE_DIR'} .'/'. $file; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } elsif ($doc->{'_is_str_ref'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | $file = ($self->include_paths->[0] || '.') .'/'. $file; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->include_paths->[0] || '.'
MC/DC0%0/1
$self->include_paths->[0] || '.'
$self->include_paths->[0]
Truth table50%1/2
A
A= $self->include_paths->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | ▶ | $file .= $self->{'COMPILE_EXT'} if defined($self->{'COMPILE_EXT'}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 9 | ▶ | $file .= $Template::Alloy::PERL_COMPILE_EXT if defined $Template::Alloy::PERL_COMPILE_EXT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 9 | ▶ | if (-e $file && ($doc->{'_is_str_ref'} || (stat $file)[9] == $doc->{'modtime'})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
-e $file and $doc->{"_is_str_ref"} || (stat $file)[9] == $doc->{"modtime"}
$doc->{"_is_str_ref"} or (stat $file)[9] == $doc->{"modtime"}
MC/DC33%1/3
-e $file and $doc->{"_is_str_ref"} || (stat $file)[9] == $doc->{"modtime"}
-e $file
$doc->{"_is_str_ref"}
(stat $file)[9] == $doc->{"modtime"}
Truth table50%2/4
A and B or C
A= -e $fileB= $doc->{"_is_str_ref"}C= (stat $file)[9] == $doc->{"modtime"}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | $perl = $self->slurp($file); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 8 | $doc->{'_compile_filename'} = $file; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 1693 | ▶ | $perl ||= $self->compile_template($doc); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$perl ||= $self->compile_template($doc)
MC/DC0%0/2
$perl ||= $self->compile_template($doc)
$perl
$self->compile_template($doc)
Truth table66%2/3
A ||= B
A= $perlB= $self->compile_template($doc)
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | ### save a cache on the fileside as asked | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 1645 | ▶ | if ($doc->{'_compile_filename'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | my $dir = $doc->{'_compile_filename'}; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | $dir =~ s|/[^/]+$||; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 8 | ▶ | if (! -d $dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | require File::Path; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | File::Path::mkpath($dir); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 8 | ▶ | open(my $fh, ">", $doc->{'_compile_filename'}) || $self->throw('compile', "Could not open file \"$doc->{'_compile_filename'}\" for writing: $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | ### todo - think about locking | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 8 | ▶ | if ($self->{'ENCODING'} && eval { require Encode } && defined &Encode::encode) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->{"ENCODING"} and eval {
do {
require Encode
}
} and defined &Encode::encode
$self->{"ENCODING"} and eval {
do {
require Encode
}
}
MC/DC33%1/3
$self->{"ENCODING"} and eval {
do {
require Encode
}
} and defined &Encode::encode
$self->{"ENCODING"}
eval {
do {
require Encode
}
}
defined &Encode::encode
Truth table50%2/4
A and B and C
A= $self->{"ENCODING"}B= eval {
do {
require Encode
}
}C= defined &Encode::encode
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | print {$fh} Encode::encode($self->{'ENCODING'}, $$perl); | |||||||||||||||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | print {$fh} $$perl; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 8 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 8 | utime $doc->{'modtime'}, $doc->{'modtime'}, $doc->{'_compile_filename'}; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 1645 | ▶ | $perl = eval $$perl; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 1645 | ▶ | $self->throw('compile', "Trouble loading compiled perl: $@") if ! $perl && $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $perl and $@
MC/DC0%0/2
not $perl and $@
not $perl
$@
Truth table33%1/3
not(A) and B
A= not $perlB= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 1645 | return $perl; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | ###----------------------------------------------------------------### | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 1692 | ▶ | sub compile_template { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_template: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1692 | my ($self, $doc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1692 | local $self->{'_component'} = $doc; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 1692 | ▶ | my $tree = $doc->{'_tree'} ||= $self->load_tree($doc); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$doc->{"_tree"} ||= $self->load_tree($doc)
MC/DC0%0/2
$doc->{"_tree"} ||= $self->load_tree($doc)
$doc->{"_tree"}
$self->load_tree($doc)
Truth table66%2/3
A ||= B
A= $doc->{"_tree"}B= $self->load_tree($doc)
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 1644 | local $self->{'_blocks'} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 1644 | local $self->{'_meta'} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 1644 | my $code = $self->compile_tree($tree, $INDENT); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 1644 | ▶ | $self->{'_blocks'} .= "\n" if $self->{'_blocks'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 1644 | ▶ | $self->{'_meta'} .= "\n" if $self->{'_meta'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 1644 | ▶ | my $file = $doc->{'_filename'} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$doc->{'_filename'} || ''
MC/DC100%1/1
$doc->{'_filename'} || ''
$doc->{'_filename'}
Truth table100%2/2
A
A= $doc->{'_filename'}
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 1644 | $file =~ s/\'/\\\'/g; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | my $str = "# Generated by ".__PACKAGE__." v$VERSION on ".localtime()." | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | my \$file = '$file'; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | my \$blocks = {$self->{'_blocks'}}; | ||||||||||||||||||||||||||||||||||||||||||
| 142 | my \$meta = {$self->{'_meta'}}; | ||||||||||||||||||||||||||||||||||||||||||
| 143 | my \$code = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | ${INDENT}my (\$self, \$out_ref, \$var) = \@_;" | ||||||||||||||||||||||||||||||||||||||||||
| 145 | .($self->{'_blocks'} ? "\n${INDENT}\@{ \$self->{'BLOCKS'} }{ keys %\$blocks } = values %\$blocks;" : "") | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 1644 | ▶ | .($self->{'_meta'} ? "\n${INDENT}\@{ \$self->{'_component'} }{ keys %\$meta } = values %\$meta;" : "") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | ."$code | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | ${INDENT}return 1; | ||||||||||||||||||||||||||||||||||||||||||
| 150 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | ${INDENT}blocks => \$blocks, | ||||||||||||||||||||||||||||||||||||||||||
| 154 | ${INDENT}meta => \$meta, | ||||||||||||||||||||||||||||||||||||||||||
| 155 | ${INDENT}code => \$code, | ||||||||||||||||||||||||||||||||||||||||||
| 156 | };\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 157 | # print $str; | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 1644 | return \$str; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | ###----------------------------------------------------------------### | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 3398 | ▶ | sub _node_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_node_info: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 3398 | my ($self, $node, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 3398 | ▶ | my $doc = $self->{'_component'} || return ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_component'} || (return '')
MC/DC0%0/1
$self->{'_component'} || (return '')
$self->{'_component'}
Truth table50%1/2
A
A= $self->{'_component'}
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 3398 | ▶ | $doc->{'_content'} ||= $self->slurp($doc->{'_filename'}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$doc->{"_content"} ||= $self->slurp($doc->{"_filename"})
MC/DC0%0/2
$doc->{"_content"} ||= $self->slurp($doc->{"_filename"})
$doc->{"_content"}
$self->slurp($doc->{"_filename"})
Truth table33%1/3
A ||= B
A= $doc->{"_content"}B= $self->slurp($doc->{"_filename"})
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 3398 | my ($line, $char) = $self->get_line_number_by_index($doc, $node->[1], 'include_chars'); | |||||||||||||||||||||||||||||||||||||||||
| 168 | 3398 | return "\n\n${indent}# \"$node->[0]\" Line $line char $char (chars $node->[1] to $node->[2])"; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 2181 | ▶ | sub compile_tree { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_tree: called CC=8 SCAR=21.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 2181 | my ($self, $tree, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 2181 | my $code = ''; | |||||||||||||||||||||||||||||||||||||||||
| 174 | # node contains (0: DIRECTIVE, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | # 1: start_index, | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # 2: end_index, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # 3: parsed tag details, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # 4: sub tree for block types | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # 5: continuation sub trees for sub continuation block types (elsif, else, etc) | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # 6: flag to capture next directive | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 2181 | my @doc; | |||||||||||||||||||||||||||||||||||||||||
| 182 | my $func; | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 2181 | for my $node (@$tree) { | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | # text nodes are just the bare text | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 4437 | ▶ | if (! ref $node) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 1132 | my $copy = $node; # must make a copy before modification | |||||||||||||||||||||||||||||||||||||||||
| 188 | 1132 | $copy =~ s/([\'\\])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 1132 | $code .= "\n\n${indent}\$\$out_ref .= '$copy';"; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 1132 | next; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 3305 | ▶ | if ($self->{'_debug_dirs'} && ! $self->{'_debug_off'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"_debug_dirs"} and not $self->{"_debug_off"}
MC/DC50%1/2
$self->{"_debug_dirs"} and not $self->{"_debug_off"}
$self->{"_debug_dirs"}
not $self->{"_debug_off"}
Truth table66%2/3
A and not(B)
A= $self->{"_debug_dirs"}B= not $self->{"_debug_off"}
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 8 | my $info = $self->node_info($node); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 8 | my ($file, $line, $text) = @{ $info }{qw(file line text)}; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 8 | s/\'/\\\'/g foreach $file, $line, $text; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 8 | $code .= "\n | |||||||||||||||||||||||||||||||||||||||||
| 198 | ${indent}if (\$self->{'_debug_dirs'} && ! \$self->{'_debug_off'}) { # DEBUG | ||||||||||||||||||||||||||||||||||||||||||
| 199 | ${indent}${INDENT}my \$info = {file => '$file', line => '$line', text => '$text'}; | ||||||||||||||||||||||||||||||||||||||||||
| 200 | ${indent}${INDENT}my \$format = \$self->{'_debug_format'} || \$self->{'DEBUG_FORMAT'} || \"\\n## \\\$file line \\\$line : [% \\\$text %] ##\\n\"; | ||||||||||||||||||||||||||||||||||||||||||
| 201 | ${indent}${INDENT}\$format =~ s{\\\$(file|line|text)}{\$info->{\$1}}g; | ||||||||||||||||||||||||||||||||||||||||||
| 202 | ${indent}${INDENT}\$\$out_ref .= \$format; | ||||||||||||||||||||||||||||||||||||||||||
| 203 | ${indent}}"; | ||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 3305 | $code .= _node_info($self, $node, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 3305 | ▶ | if ($func = $DIRECTIVES->{$node->[0]}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 3305 | $func->($self, $node, \$code, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 210 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 211 | ### if the method isn't defined - delegate to the play directive (if there is one) | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | require Template::Alloy::Play; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if ($func = $Template::Alloy::Play::DIRECTIVES->{$node->[0]}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | _compile_defer_to_play($self, $node, \$code, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | die "Couldn't find compile or play method for directive \"$node->[0]\""; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 2181 | return $code; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 2321 | ▶ | sub compile_expr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_expr: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 2321 | my ($self, $var, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 2321 | return "\$self->play_expr(".$self->ast_string($var).")"; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 269 | ▶ | sub _compile_defer_to_play { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile_defer_to_play: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 269 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 269 | my $directive = $node->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 269 | ▶ | die "Invalid node name \"$directive\"" if $directive !~ /^\w+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 269 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 234 | ${indent}require Template::Alloy::Play; | ||||||||||||||||||||||||||||||||||||||||||
| 235 | ${indent}\$var = ".$self->ast_string($node->[3])."; | ||||||||||||||||||||||||||||||||||||||||||
| 236 | ${indent}\$Template::Alloy::Play::DIRECTIVES->{'$directive'}->(\$self, \$var, ".$self->ast_string($node).", \$out_ref);"; | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 269 | return; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 35 | ▶ | sub _is_empty_named_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_empty_named_args: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 35 | my ($hash_ident) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 243 | # [[undef, '{}', 'key1', 'val1', 'key2, 'val2'], 0] | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 35 | return @{ $hash_ident->[0] } <= 2; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | ###----------------------------------------------------------------### | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 93 | ▶ | sub compile_BLOCK { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_BLOCK: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 93 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 93 | my $ref = \ $self->{'_blocks'}; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 93 | my $name = $node->[3]; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 93 | $name =~ s/\'/\\\'/g; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 93 | my $name2 = $self->{'_component'}->{'name'} .'/'. $node->[3]; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 93 | $name2 =~ s/\'/\\\'/g; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 93 | my $code = $self->compile_tree($node->[4], "$INDENT$INDENT$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 93 | $$ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 261 | ${INDENT}'$name' => { | ||||||||||||||||||||||||||||||||||||||||||
| 262 | ${INDENT}${INDENT}name => '$name2', | ||||||||||||||||||||||||||||||||||||||||||
| 263 | ${INDENT}${INDENT}_filename => \$file, | ||||||||||||||||||||||||||||||||||||||||||
| 264 | ${INDENT}${INDENT}_perl => {code => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 265 | ${INDENT}${INDENT}${INDENT}my (\$self, \$out_ref, \$var) = \@_;$code | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | ${INDENT}${INDENT}${INDENT}return 1; | ||||||||||||||||||||||||||||||||||||||||||
| 268 | ${INDENT}${INDENT}}}, | ||||||||||||||||||||||||||||||||||||||||||
| 269 | ${INDENT}},"; | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 93 | return; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 26 | ▶ | sub compile_CALL { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_CALL: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 26 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 26 | $$str_ref .= "\n${indent}scalar ".$self->compile_expr($node->[3], $indent).";"; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 26 | return; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 7 | ▶ | sub compile_CLEAR { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_CLEAR: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 7 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 7 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 283 | ${indent}\$\$out_ref = '';"; | ||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 41 | ▶ | sub compile_CONFIG { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_CONFIG: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 41 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 41 | _compile_defer_to_play($self, $node, $str_ref, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | ▶ | sub compile_DEBUG { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_DEBUG: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | my $text = $node->[3]->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | ▶ | if ($text eq 'on') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $$str_ref .= "\n${indent}delete \$self->{'_debug_off'};"; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } elsif ($text eq 'off') { | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $$str_ref .= "\n${indent}\$self->{'_debug_off'} = 1;"; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } elsif ($text eq 'format') { | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | my $format = $node->[3]->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | $format =~ s/\'/\\\'/g; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | $$str_ref .= "\n${indent}\$self->{'_debug_format'} = '$format';"; | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 3 | ▶ | sub compile_DEFAULT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_DEFAULT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 3 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 3 | local $self->{'_is_default'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 3 | $DIRECTIVES->{'SET'}->($self, $node, $str_ref, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 28 | ▶ | sub compile_DUMP { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_DUMP: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 28 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 28 | _compile_defer_to_play($self, $node, $str_ref, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 1621 | ▶ | sub compile_GET { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_GET: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 1621 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 1621 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 322 | $indent\$var = ".$self->compile_expr($node->[3], $indent)."; | ||||||||||||||||||||||||||||||||||||||||||
| 323 | $indent\$\$out_ref .= defined(\$var) ? \$var : \$self->undefined_get(".$self->ast_string($node->[3]).");"; | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 1621 | return; | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 9 | ▶ | sub compile_EVAL { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_EVAL: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 9 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 9 | my ($named, @strs) = @{ $node->[3] }; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | $$str_ref .= " | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 9 | ${indent}foreach (".join(",\n", map {$self->ast_string($_)} @strs).") { | |||||||||||||||||||||||||||||||||||||||||
| 333 | ${indent}${INDENT}my \$str = \$self->play_expr(\$_); | ||||||||||||||||||||||||||||||||||||||||||
| 334 | ${indent}${INDENT}next if ! defined \$str; | ||||||||||||||||||||||||||||||||||||||||||
| 335 | ${indent}${INDENT}\$\$out_ref .= \$self->play_expr([[undef, '-temp-', \$str], 0, '|', 'eval', [".$self->ast_string($named)."]]); | ||||||||||||||||||||||||||||||||||||||||||
| 336 | ${indent}}"; | ||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 24 | ▶ | sub compile_FILTER { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_FILTER: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 24 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 24 | my ($name, $filter) = @{ $node->[3] }; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 24 | ▶ | return if ! @$filter; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 24 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 345 | ${indent}\$var = do { | ||||||||||||||||||||||||||||||||||||||||||
| 346 | ${indent}${INDENT}my \$filter = ".$self->ast_string($filter).";"; | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | ### allow for alias | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 24 | ▶ | if (length $name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 6 | $name =~ s/\'/\\\'/g; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 6 | $$str_ref .= "\n${indent}${INDENT}\$self->{'FILTERS'}->{'$name'} = \$filter; # alias for future calls\n"; | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 24 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 355 | ${indent}${INDENT}my \$out = ''; | ||||||||||||||||||||||||||||||||||||||||||
| 356 | ${indent}${INDENT}my \$out_ref = \\\$out;" | ||||||||||||||||||||||||||||||||||||||||||
| 357 | .$self->compile_tree($node->[4], "$indent$INDENT")." | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | ${indent}\$out = \$self->play_expr([[undef, '-temp-', \$out], 0, '|', \@\$filter]); | ||||||||||||||||||||||||||||||||||||||||||
| 360 | ${indent}${INDENT}\$out; | ||||||||||||||||||||||||||||||||||||||||||
| 361 | ${indent}}; | ||||||||||||||||||||||||||||||||||||||||||
| 362 | ${indent}\$\$out_ref .= \$var if defined \$var;"; | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 85 | ▶ | sub compile_FOR { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_FOR: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 85 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 85 | my ($name, $items) = @{ $node->[3] }; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 85 | local $self->{'_in_loop'} = 'FOREACH'; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 85 | my $code = $self->compile_tree($node->[4], "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 85 | $$str_ref .= "\n${indent}do { | |||||||||||||||||||||||||||||||||||||||||
| 374 | ${indent}my \$loop = ".$self->compile_expr($items, $indent)."; | ||||||||||||||||||||||||||||||||||||||||||
| 375 | ${indent}\$loop = [] if ! defined \$loop; | ||||||||||||||||||||||||||||||||||||||||||
| 376 | ${indent}\$loop = \$self->iterator(\$loop) if ref(\$loop) !~ /Iterator\$/; | ||||||||||||||||||||||||||||||||||||||||||
| 377 | ${indent}local \$self->{'_vars'}->{'loop'} = \$loop;"; | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 85 | ▶ | if (! defined $name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 23 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 380 | ${indent}my \$swap = \$self->{'_vars'}; | ||||||||||||||||||||||||||||||||||||||||||
| 381 | ${indent}local \$self->{'_vars'} = my \$copy = {%\$swap};"; | ||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 85 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 385 | ${indent}my (\$var, \$error) = \$loop->get_first; | ||||||||||||||||||||||||||||||||||||||||||
| 386 | ${indent}FOREACH: while (! \$error) {"; | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 85 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 62 | $$str_ref .= "\n$indent$INDENT\$self->set_variable(".$self->ast_string($name).", \$var);"; | |||||||||||||||||||||||||||||||||||||||||
| 390 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 23 | $$str_ref .= "\n$indent$INDENT\@\$copy{keys %\$var} = values %\$var if ref(\$var) eq 'HASH';"; | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 85 | $$str_ref .= "$code | |||||||||||||||||||||||||||||||||||||||||
| 395 | ${indent}${INDENT}(\$var, \$error) = \$loop->get_next; | ||||||||||||||||||||||||||||||||||||||||||
| 396 | ${indent}} | ||||||||||||||||||||||||||||||||||||||||||
| 397 | ${indent}};"; | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 85 | return; | |||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | sub compile_FOREACH { shift->compile_FOR(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_FOREACH: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 86 | ▶ | sub compile_IF { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_IF: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 86 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 86 | $$str_ref .= "\n${indent}if (".$self->compile_expr($node->[3], $indent).") {"; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 86 | $$str_ref .= $self->compile_tree($node->[4], "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 86 | ▶ | while ($node = $node->[5]) { # ELSE, ELSIF's | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 40 | $$str_ref .= _node_info($self, $node, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 411 | 40 | ▶ | if ($node->[0] eq 'ELSE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 27 | $$str_ref .= "\n${indent}} else {"; | |||||||||||||||||||||||||||||||||||||||||
| 413 | 27 | $$str_ref .= $self->compile_tree($node->[4], "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 414 | 27 | last; | |||||||||||||||||||||||||||||||||||||||||
| 415 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 13 | $$str_ref .= "\n${indent}} elsif (".$self->compile_expr($node->[3], $indent).") {"; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 13 | $$str_ref .= $self->compile_tree($node->[4], "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 86 | $$str_ref .= "\n${indent}}"; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 37 | ▶ | sub compile_INCLUDE { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_INCLUDE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 37 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 37 | _compile_defer_to_play($self, $node, $str_ref, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 8 | ▶ | sub compile_INSERT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_INSERT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 8 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 8 | _compile_defer_to_play($self, $node, $str_ref, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | sub compile_JS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_JS: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | _compile_defer_to_play($self, $node, $str_ref, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 3 | ▶ | sub compile_LAST { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_LAST: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 3 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 3 | ▶ | my $type = $self->{'_in_loop'} || die "Found LAST while not in FOR, FOREACH or WHILE"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_in_loop'} || die('Found LAST while not in FOR, FOREACH or WHILE')
MC/DC0%0/1
$self->{'_in_loop'} || die('Found LAST while not in FOR, FOREACH or WHILE')
$self->{'_in_loop'}
Truth table50%1/2
A
A= $self->{'_in_loop'}
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 3 | $$str_ref .= "\n${indent}last $type;"; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 21 | ▶ | sub compile_LOOP { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_LOOP: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 21 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 447 | 21 | my $ref = $node->[3]; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 21 | ▶ | $ref = [$ref, 0] if ! ref $ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 21 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 451 | ${indent}\$var = ".$self->compile_expr($ref, $indent)."; | ||||||||||||||||||||||||||||||||||||||||||
| 452 | ${indent}if (\$var) { | ||||||||||||||||||||||||||||||||||||||||||
| 453 | ${indent}${INDENT}my \$global = ! \$self->{'SYNTAX'} || \$self->{'SYNTAX'} ne 'ht' || \$self->{'GLOBAL_VARS'}; | ||||||||||||||||||||||||||||||||||||||||||
| 454 | ${indent}${INDENT}my \$items = ref(\$var) eq 'ARRAY' ? \$var : ref(\$var) eq 'HASH' ? [\$var] : []; | ||||||||||||||||||||||||||||||||||||||||||
| 455 | ${indent}${INDENT}my \$i = 0; | ||||||||||||||||||||||||||||||||||||||||||
| 456 | ${indent}${INDENT}for my \$ref (\@\$items) { | ||||||||||||||||||||||||||||||||||||||||||
| 457 | ${indent}${INDENT}${INDENT}\$self->throw('loop', 'Scalar value used in LOOP') if \$ref && ref(\$ref) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 458 | ${indent}${INDENT}${INDENT}local \$self->{'_vars'} = (! \$global) ? (\$ref || {}) : (ref(\$ref) eq 'HASH') ? {%{ \$self->{'_vars'} }, %\$ref} : \$self->{'_vars'}; | ||||||||||||||||||||||||||||||||||||||||||
| 459 | ${indent}${INDENT}${INDENT}\@{ \$self->{'_vars'} }{qw(__counter__ __first__ __last__ __inner__ __odd__)} | ||||||||||||||||||||||||||||||||||||||||||
| 460 | ${indent}${INDENT}${INDENT}${INDENT}= (++\$i, (\$i == 1 ? 1 : 0), (\$i == \@\$items ? 1 : 0), (\$i == 1 || \$i == \@\$items ? 0 : 1), (\$i % 2) ? 1 : 0) | ||||||||||||||||||||||||||||||||||||||||||
| 461 | ${indent}${INDENT}${INDENT}${INDENT}${INDENT}if \$self->{'LOOP_CONTEXT_VARS'} && ! \$Template::Alloy::QR_PRIVATE;" | ||||||||||||||||||||||||||||||||||||||||||
| 462 | .$self->compile_tree($node->[4], "$indent$INDENT$INDENT")." | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | ${indent}${INDENT}} | ||||||||||||||||||||||||||||||||||||||||||
| 465 | ${indent}}"; | ||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 34 | ▶ | sub compile_MACRO { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_MACRO: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 34 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 34 | my ($name, $args) = @{ $node->[3] }; | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | ### get the sub tree | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 34 | my $sub_tree = $node->[4]; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 34 | ▶ | if (! $sub_tree || ! $sub_tree->[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$sub_tree && $sub_tree->[0]
MC/DC0%0/2
$sub_tree && $sub_tree->[0]
$sub_tree
$sub_tree->[0]
Truth table33%1/3
A && B
A= $sub_treeB= $sub_tree->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 476 | ${indent}\$self->set_variable(".$self->ast_string($name).", undef);"; | ||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 478 | ▶ | } elsif (ref($sub_tree->[0]) && $sub_tree->[0]->[0] eq 'BLOCK') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $sub_tree->[0] and $sub_tree->[0][0] eq "BLOCK"
MC/DC100%2/2
ref $sub_tree->[0] and $sub_tree->[0][0] eq "BLOCK"
ref $sub_tree->[0]
$sub_tree->[0][0] eq "BLOCK"
Truth table100%3/3
A and B
A= ref $sub_tree->[0]B= $sub_tree->[0][0] eq "BLOCK"
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 23 | $sub_tree = $sub_tree->[0]->[4]; | |||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | 34 | my $code = $self->compile_tree($sub_tree, "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 34 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 485 | ${indent}do { | ||||||||||||||||||||||||||||||||||||||||||
| 486 | ${indent}my \$self_copy = \$self; | ||||||||||||||||||||||||||||||||||||||||||
| 487 | ${indent}eval {require Scalar::Util; Scalar::Util::weaken(\$self_copy)}; | ||||||||||||||||||||||||||||||||||||||||||
| 488 | ${indent}\$var = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 489 | ${indent}${INDENT}my \$copy = \$self_copy->{'_vars'}; | ||||||||||||||||||||||||||||||||||||||||||
| 490 | ${indent}${INDENT}local \$self_copy->{'_vars'}= {%\$copy}; | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | ${indent}${INDENT}local \$self_copy->{'_macro_recurse'} = \$self_copy->{'_macro_recurse'} || 0; | ||||||||||||||||||||||||||||||||||||||||||
| 493 | ${indent}${INDENT}my \$max = \$self_copy->{'MAX_MACRO_RECURSE'} || \$Template::Alloy::MAX_MACRO_RECURSE; | ||||||||||||||||||||||||||||||||||||||||||
| 494 | ${indent}${INDENT}\$self_copy->throw('macro_recurse', \"MAX_MACRO_RECURSE \$max reached\") | ||||||||||||||||||||||||||||||||||||||||||
| 495 | ${indent}${INDENT}${INDENT}if ++\$self_copy->{'_macro_recurse'} > \$max; | ||||||||||||||||||||||||||||||||||||||||||
| 496 | "; | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 34 | foreach my $var (@$args) { | |||||||||||||||||||||||||||||||||||||||||
| 499 | 28 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 500 | ${indent}${INDENT}\$self_copy->set_variable("; | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 28 | $$str_ref .= $self->ast_string($var); | |||||||||||||||||||||||||||||||||||||||||
| 502 | 28 | $$str_ref .= ", shift(\@_));"; | |||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | 34 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 505 | ${indent}${INDENT}if (\@_ && \$_[-1] && UNIVERSAL::isa(\$_[-1],'HASH')) { | ||||||||||||||||||||||||||||||||||||||||||
| 506 | ${indent}${INDENT}${INDENT}my \$named = pop \@_; | ||||||||||||||||||||||||||||||||||||||||||
| 507 | ${indent}${INDENT}${INDENT}foreach my \$name (sort keys %\$named) { | ||||||||||||||||||||||||||||||||||||||||||
| 508 | ${indent}${INDENT}${INDENT}${INDENT}\$self_copy->set_variable([\$name, 0], \$named->{\$name}); | ||||||||||||||||||||||||||||||||||||||||||
| 509 | ${indent}${INDENT}${INDENT}} | ||||||||||||||||||||||||||||||||||||||||||
| 510 | ${indent}${INDENT}} | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | ${indent}${INDENT}my \$out = ''; | ||||||||||||||||||||||||||||||||||||||||||
| 513 | ${indent}${INDENT}my \$out_ref = \\\$out;$code | ||||||||||||||||||||||||||||||||||||||||||
| 514 | ${indent}${INDENT}return \$out; | ||||||||||||||||||||||||||||||||||||||||||
| 515 | ${indent}}; | ||||||||||||||||||||||||||||||||||||||||||
| 516 | ${indent}\$self->set_variable(".$self->ast_string($name).", \$var); | ||||||||||||||||||||||||||||||||||||||||||
| 517 | ${indent}};"; | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | 34 | return; | |||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 92 | ▶ | sub compile_META { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_META: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 92 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 524 | 92 | ▶ | if (my $kp = $node->[3]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | 46 | ▶ | $kp = {@$kp} if ref($kp) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | 46 | ▶ | while (my($key, $val) = each %$kp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | 46 | s/\'/\\\'/g foreach $key, $val; | |||||||||||||||||||||||||||||||||||||||||
| 528 | 46 | $self->{'_meta'} .= "\n${indent}'$key' => '$val',"; | |||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 92 | return; | |||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | 2 | ▶ | sub compile_NEXT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_NEXT: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | 2 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 2 | ▶ | my $type = $self->{'_in_loop'} || die "Found next while not in FOR, FOREACH or WHILE"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_in_loop'} || die('Found next while not in FOR, FOREACH or WHILE')
MC/DC0%0/1
$self->{'_in_loop'} || die('Found next while not in FOR, FOREACH or WHILE')
$self->{'_in_loop'}
Truth table50%1/2
A
A= $self->{'_in_loop'}
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 2 | ▶ | $$str_ref .= "\n${indent}(\$var, \$error) = \$loop->get_next;" if $type eq 'FOREACH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | 2 | $$str_ref .= "\n${indent}next $type;"; | |||||||||||||||||||||||||||||||||||||||||
| 539 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 6 | ▶ | sub compile_PERL{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_PERL: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 6 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | ### fill in any variables | ||||||||||||||||||||||||||||||||||||||||||
| 546 | 6 | ▶ | my $perl = $node->[4] || return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->[4] || (return)
MC/DC0%0/1
$node->[4] || (return)
$node->[4]
Truth table50%1/2
A
A= $node->[4]
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 6 | my $code = $self->compile_tree($perl, "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 6 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 550 | ${indent}\$self->throw('perl', 'EVAL_PERL not set') if ! \$self->{'EVAL_PERL'}; | ||||||||||||||||||||||||||||||||||||||||||
| 551 | ${indent}require Template::Alloy::Play; | ||||||||||||||||||||||||||||||||||||||||||
| 552 | ${indent}\$var = do { | ||||||||||||||||||||||||||||||||||||||||||
| 553 | ${indent}${INDENT}my \$out = ''; | ||||||||||||||||||||||||||||||||||||||||||
| 554 | ${indent}${INDENT}my \$out_ref = \\\$out;$code | ||||||||||||||||||||||||||||||||||||||||||
| 555 | ${indent}${INDENT}\$out; | ||||||||||||||||||||||||||||||||||||||||||
| 556 | ${indent}}; | ||||||||||||||||||||||||||||||||||||||||||
| 557 | ${indent}#\$var = \$1 if \$var =~ /^(.+)\$/s; # blatant untaint | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | ${indent}my \$err; | ||||||||||||||||||||||||||||||||||||||||||
| 560 | ${indent}eval { | ||||||||||||||||||||||||||||||||||||||||||
| 561 | ${indent}${INDENT}package Template::Alloy::Perl; | ||||||||||||||||||||||||||||||||||||||||||
| 562 | ${indent}${INDENT}my \$context = \$self->context; | ||||||||||||||||||||||||||||||||||||||||||
| 563 | ${indent}${INDENT}my \$stash = \$context->stash; | ||||||||||||||||||||||||||||||||||||||||||
| 564 | ${indent}${INDENT}local *PERLOUT; | ||||||||||||||||||||||||||||||||||||||||||
| 565 | ${indent}${INDENT}tie *PERLOUT, 'Template::Alloy::EvalPerlHandle', \$out_ref; | ||||||||||||||||||||||||||||||||||||||||||
| 566 | ${indent}${INDENT}my \$old_fh = select PERLOUT; | ||||||||||||||||||||||||||||||||||||||||||
| 567 | ${indent}${INDENT}eval \$var; | ||||||||||||||||||||||||||||||||||||||||||
| 568 | ${indent}${INDENT}\$err = \$\@; | ||||||||||||||||||||||||||||||||||||||||||
| 569 | ${indent}${INDENT}select \$old_fh; | ||||||||||||||||||||||||||||||||||||||||||
| 570 | ${indent}}; | ||||||||||||||||||||||||||||||||||||||||||
| 571 | ${indent}\$err ||= \$\@; | ||||||||||||||||||||||||||||||||||||||||||
| 572 | ${indent}if (\$err) { | ||||||||||||||||||||||||||||||||||||||||||
| 573 | ${indent}${INDENT}\$self->throw('undef', \$err) if ! UNIVERSAL::can(\$err, 'type'); | ||||||||||||||||||||||||||||||||||||||||||
| 574 | ${indent}${INDENT}die \$err; | ||||||||||||||||||||||||||||||||||||||||||
| 575 | ${indent}}"; | ||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 142 | ▶ | sub compile_PROCESS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_PROCESS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 582 | 142 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 583 | 142 | _compile_defer_to_play($self, $node, $str_ref, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | 1 | ▶ | sub compile_RAWPERL { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_RAWPERL: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 588 | 1 | _compile_defer_to_play($self, $node, $str_ref, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 5 | ▶ | sub compile_RETURN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_RETURN: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 5 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 5 | ▶ | if (defined($node->[3])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 596 | ${indent}\$var = {return_val => ".$self->compile_expr($node->[3])."}; | ||||||||||||||||||||||||||||||||||||||||||
| 597 | ${indent}\$self->throw('return', \$var);"; | ||||||||||||||||||||||||||||||||||||||||||
| 598 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 5 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 600 | ${indent}\$self->throw('return', undef);"; | ||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 396 | ▶ | sub compile_SET { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_SET: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | 396 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 606 | 396 | my $sets = $node->[3]; | |||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 396 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 396 | foreach (@$sets) { | |||||||||||||||||||||||||||||||||||||||||
| 610 | 400 | my ($op, $set, $val) = @$_; | |||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||
| 612 | 400 | ▶ | if ($self->{'_is_default'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 613 | 3 | $$str_ref .= "\n${indent}if (! ".$self->compile_expr($set, $indent).") {"; | |||||||||||||||||||||||||||||||||||||||||
| 614 | 3 | $indent .= $INDENT; | |||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 400 | $$str_ref .= "\n$indent\$var = "; | |||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | 400 | ▶ | if (! defined $val) { # not defined | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | 9 | $$str_ref .= 'undef'; | |||||||||||||||||||||||||||||||||||||||||
| 620 | ▶ | } elsif ($node->[4] && $val == $node->[4]) { # a captured directive | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$node->[4] and $val == $node->[4]
MC/DC50%1/2
$node->[4] and $val == $node->[4]
$node->[4]
$val == $node->[4]
Truth table66%2/3
A and B
A= $node->[4]B= $val == $node->[4]
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | 28 | my $sub_tree = $node->[4]; | |||||||||||||||||||||||||||||||||||||||||
| 622 | 28 | ▶ | $sub_tree = $sub_tree->[0]->[4] if $sub_tree->[0] && $sub_tree->[0]->[0] eq 'BLOCK'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$sub_tree->[0] and $sub_tree->[0][0] eq "BLOCK"
MC/DC50%1/2
$sub_tree->[0] and $sub_tree->[0][0] eq "BLOCK"
$sub_tree->[0]
$sub_tree->[0][0] eq "BLOCK"
Truth table66%2/3
A and B
A= $sub_tree->[0]B= $sub_tree->[0][0] eq "BLOCK"
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 28 | my $code = $self->compile_tree($sub_tree, "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 624 | 28 | $$str_ref .= "${indent}do { | |||||||||||||||||||||||||||||||||||||||||
| 625 | ${indent}${INDENT}my \$out = ''; | ||||||||||||||||||||||||||||||||||||||||||
| 626 | ${indent}${INDENT}my \$out_ref = \\\$out;$code | ||||||||||||||||||||||||||||||||||||||||||
| 627 | ${indent}${INDENT}\$out; | ||||||||||||||||||||||||||||||||||||||||||
| 628 | ${indent}}" | ||||||||||||||||||||||||||||||||||||||||||
| 629 | } else { # normal var | ||||||||||||||||||||||||||||||||||||||||||
| 630 | 363 | $$str_ref .= $self->compile_expr($val, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | 400 | ▶ | if ($Template::Alloy::OP_DISPATCH->{$op}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | $$str_ref .= ' }'; | |||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | 400 | $$str_ref .= "; | |||||||||||||||||||||||||||||||||||||||||
| 638 | $indent\$self->set_variable(".$self->ast_string($set).", \$var);"; | ||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | 400 | ▶ | if ($self->{'_is_default'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | 3 | substr($indent, -length($INDENT), length($INDENT), ''); | |||||||||||||||||||||||||||||||||||||||||
| 642 | 3 | $$str_ref .= "\n$indent}"; | |||||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||
| 645 | 400 | $$str_ref .= ";"; | |||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||
| 648 | 396 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||
| 651 | 10 | ▶ | sub compile_STOP { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_STOP: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 652 | 10 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 653 | 10 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 654 | ${indent}\$self->throw('stop', 'Control Exception');"; | ||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | 10 | ▶ | sub compile_SWITCH { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_SWITCH: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 10 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | 10 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 661 | ${indent}\$var = ".$self->compile_expr($node->[3], $indent).";"; | ||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 10 | my $default; | |||||||||||||||||||||||||||||||||||||||||
| 664 | 10 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 665 | 10 | ▶ | while ($node = $node->[5]) { # CASES | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 666 | 10 | ▶ | if (! defined $node->[3]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | 3 | $default = $node; | |||||||||||||||||||||||||||||||||||||||||
| 668 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | 7 | $$str_ref .= _node_info($self, $node, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 672 | 7 | ▶ | $$str_ref .= "\n$indent" .($i++ ? "} els" : ""). "if (do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | ${indent}${INDENT}no warnings; | ||||||||||||||||||||||||||||||||||||||||||
| 674 | ${indent}${INDENT}my \$var2 = ".$self->compile_expr($node->[3], "$indent$INDENT")."; | ||||||||||||||||||||||||||||||||||||||||||
| 675 | ${indent}${INDENT}scalar grep {\$_ eq \$var} (UNIVERSAL::isa(\$var2, 'ARRAY') ? \@\$var2 : \$var2); | ||||||||||||||||||||||||||||||||||||||||||
| 676 | ${indent}${INDENT}}) { | ||||||||||||||||||||||||||||||||||||||||||
| 677 | ${indent}${INDENT}my \$var;"; | ||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | 7 | $$str_ref .= $self->compile_tree($node->[4], "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | 10 | ▶ | if ($default) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 683 | 3 | $$str_ref .= _node_info($self, $default, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 684 | 3 | ▶ | $$str_ref .= "\n$indent" .($i++ ? "} else {" : "if (1) {"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 3 | $$str_ref .= $self->compile_tree($default->[4], "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | 10 | ▶ | $$str_ref .= "\n$indent}" if $i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | 10 | return; | |||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | 35 | ▶ | sub compile_THROW { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_THROW: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 694 | 35 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | 35 | my ($name, $args) = @{ $node->[3] }; | |||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | 35 | my ($named, @args) = @$args; | |||||||||||||||||||||||||||||||||||||||||
| 699 | 35 | ▶ | push @args, $named if ! _is_empty_named_args($named); # add named args back on at end - if there are some | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | $$str_ref .= " | ||||||||||||||||||||||||||||||||||||||||||
| 702 | 35 | ${indent}\$self->throw(".$self->compile_expr($name, $indent).", [".join(", ", map{$self->compile_expr($_, $indent)} @args)."]);"; | |||||||||||||||||||||||||||||||||||||||||
| 703 | 35 | return; | |||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 45 | ▶ | sub compile_TRY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_TRY: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 708 | 45 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | 45 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 711 | ${indent}do { | ||||||||||||||||||||||||||||||||||||||||||
| 712 | ${indent}my \$out = ''; | ||||||||||||||||||||||||||||||||||||||||||
| 713 | ${indent}eval { | ||||||||||||||||||||||||||||||||||||||||||
| 714 | ${indent}${INDENT}my \$out_ref = \\\$out;" | ||||||||||||||||||||||||||||||||||||||||||
| 715 | . $self->compile_tree($node->[4], "$indent$INDENT") ." | ||||||||||||||||||||||||||||||||||||||||||
| 716 | ${indent}}; | ||||||||||||||||||||||||||||||||||||||||||
| 717 | ${indent}my \$err = \$\@; | ||||||||||||||||||||||||||||||||||||||||||
| 718 | ${indent}\$\$out_ref .= \$out; | ||||||||||||||||||||||||||||||||||||||||||
| 719 | ${indent}if (\$err) {"; | ||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | 45 | my $final; | |||||||||||||||||||||||||||||||||||||||||
| 722 | 45 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 723 | 45 | my $catches_str = ''; | |||||||||||||||||||||||||||||||||||||||||
| 724 | 45 | my @names; | |||||||||||||||||||||||||||||||||||||||||
| 725 | 45 | ▶ | while ($node = $node->[5]) { # CATCHES | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 726 | 43 | ▶ | if ($node->[0] eq 'FINAL') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 727 | 3 | $final = $node; | |||||||||||||||||||||||||||||||||||||||||
| 728 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | 40 | $catches_str .= _node_info($self, $node, "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 731 | 40 | $catches_str .= "\n${indent}${INDENT}} elsif (\$index == ".(scalar @names).") {"; | |||||||||||||||||||||||||||||||||||||||||
| 732 | 40 | $catches_str .= $self->compile_tree($node->[4], "$indent$INDENT$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 733 | 40 | push @names, $node->[3]; | |||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||
| 735 | 45 | ▶ | if (@names) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | 39 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 737 | ${indent}${INDENT}\$err = \$self->exception('undef', \$err) if ! UNIVERSAL::can(\$err, 'type'); | ||||||||||||||||||||||||||||||||||||||||||
| 738 | ${indent}${INDENT}my \$type = \$err->type; | ||||||||||||||||||||||||||||||||||||||||||
| 739 | ${indent}${INDENT}die \$err if \$type =~ /stop|return/; | ||||||||||||||||||||||||||||||||||||||||||
| 740 | ${indent}${INDENT}local \$self->{'_vars'}->{'error'} = \$err; | ||||||||||||||||||||||||||||||||||||||||||
| 741 | ${indent}${INDENT}local \$self->{'_vars'}->{'e'} = \$err; | ||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | ${indent}${INDENT}my \$index; | ||||||||||||||||||||||||||||||||||||||||||
| 744 | ${indent}${INDENT}my \@names = ("; | ||||||||||||||||||||||||||||||||||||||||||
| 745 | 39 | $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 746 | 39 | foreach $i (0 .. $#names) { | |||||||||||||||||||||||||||||||||||||||||
| 747 | 40 | ▶ | if (defined $names[$i]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 748 | 7 | $$str_ref .= "\n${indent}${INDENT}${INDENT}scalar(".$self->compile_expr($names[$i], "$indent$INDENT$INDENT")."), # $i;"; | |||||||||||||||||||||||||||||||||||||||||
| 749 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 750 | 33 | $$str_ref .= "\n${indent}${INDENT}${INDENT}undef, # $i"; | |||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 39 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 754 | ${indent}${INDENT}); | ||||||||||||||||||||||||||||||||||||||||||
| 755 | ${indent}${INDENT}for my \$i (0 .. \$#names) { | ||||||||||||||||||||||||||||||||||||||||||
| 756 | ${indent}${INDENT}${INDENT}my \$name = (! defined(\$names[\$i]) || lc(\$names[\$i]) eq 'default') ? '' : \$names[\$i]; | ||||||||||||||||||||||||||||||||||||||||||
| 757 | ${indent}${INDENT}${INDENT}\$index = \$i if \$type =~ m{^ \\Q\$name\\E \\b}x && (! defined(\$index) || length(\$names[\$index]) < length(\$name)); | ||||||||||||||||||||||||||||||||||||||||||
| 758 | ${indent}${INDENT}} | ||||||||||||||||||||||||||||||||||||||||||
| 759 | ${indent}${INDENT}if (! defined \$index) { | ||||||||||||||||||||||||||||||||||||||||||
| 760 | ${indent}${INDENT}${INDENT}die \$err;" | ||||||||||||||||||||||||||||||||||||||||||
| 761 | .$catches_str." | ||||||||||||||||||||||||||||||||||||||||||
| 762 | ${indent}${INDENT}}"; | ||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||
| 764 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 765 | 6 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 766 | ${indent}\$self->throw('throw', 'Missing CATCH block');"; | ||||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||
| 768 | 45 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 769 | ${indent}}"; | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 45 | ▶ | if ($final) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | 3 | $$str_ref .= _node_info($self, $final, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 772 | 3 | $$str_ref .= $self->compile_tree($final->[4], "$indent"); | |||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||
| 774 | 45 | $$str_ref .=" | |||||||||||||||||||||||||||||||||||||||||
| 775 | ${indent}};"; | ||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||
| 777 | 45 | return; | |||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||
| 780 | 8 | ▶ | sub compile_UNLESS { $DIRECTIVES->{'IF'}->(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_UNLESS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | 12 | ▶ | sub compile_USE { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_USE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 783 | 12 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 784 | 12 | _compile_defer_to_play($self, $node, $str_ref, $indent); | |||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | ▶ | sub compile_VIEW { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_VIEW: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | my ($blocks, $args, $name) = @{ $node->[3] }; | |||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | my $_name = $self->ast_string($name); | |||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||
| 793 | # [[undef, '{}', 'key1', 'val1', 'key2', 'val2'], 0] | ||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | $args = $args->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 796 | ${indent}do { | ||||||||||||||||||||||||||||||||||||||||||
| 797 | ${indent}${INDENT}my \$name = $_name; | ||||||||||||||||||||||||||||||||||||||||||
| 798 | ${indent}${INDENT}my \$hash = {};"; | ||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | ▶ | foreach (my $i = 2; $i < @$args; $i+=2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 801 | ${indent}${INDENT}\$var = ".$self->compile_expr($args->[$i+1], $indent)."; | ||||||||||||||||||||||||||||||||||||||||||
| 802 | ${indent}${INDENT}"; | ||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | my $key = $args->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | if (ref $key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | ▶ | if (@$key == 2 && ! ref($key->[0]) && ! $key->[1]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@$key == 2 and not ref $key->[0] and not $key->[1]
@$key == 2 and not ref $key->[0]
MC/DC0%0/3
@$key == 2 and not ref $key->[0] and not $key->[1]
@$key == 2
not ref $key->[0]
not $key->[1]
Truth table0%0/4
A and not(B) and not(C)
A= @$key == 2B= not ref $key->[0]C= not $key->[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | $key = $key->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 807 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 809 | ${indent}${INDENT}\$self->set_variable(".$self->compile_expr($key, $indent).", \$var);"; | ||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||
| 812 | } | ||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | $key =~ s/([\'\\])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | $$str_ref .= "\$hash->{'$key'} = \$var;"; | |||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 818 | ${indent}${INDENT}my \$prefix = \$hash->{'prefix'} || (ref(\$name) && \@\$name == 2 && ! \$name->[1] && ! ref(\$name->[0])) ? \"\$name->[0]/\" : ''; | ||||||||||||||||||||||||||||||||||||||||||
| 819 | ${indent}${INDENT}my \$blocks = \$hash->{'blocks'} = {};"; | ||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | foreach my $key (keys %$blocks) { | |||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | my $code = $self->compile_tree($blocks->{$key}, "$indent$INDENT$INDENT$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | $key =~ s/([\'\\])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 824 | ${indent}${INDENT}\$blocks->{'$key'} = { | ||||||||||||||||||||||||||||||||||||||||||
| 825 | ${indent}${INDENT}${INDENT}name => \$prefix . '$key', | ||||||||||||||||||||||||||||||||||||||||||
| 826 | ${indent}${INDENT}${INDENT}_perl => {code => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 827 | ${indent}${INDENT}${INDENT}${INDENT}my (\$self, \$out_ref, \$var) = \@_;$code | ||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | ${indent}${INDENT}${INDENT}${INDENT}return 1; | ||||||||||||||||||||||||||||||||||||||||||
| 830 | ${indent}${INDENT}${INDENT}} }, | ||||||||||||||||||||||||||||||||||||||||||
| 831 | ${indent}${INDENT}};"; | ||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 835 | ${indent}${INDENT}\$self->throw('view', 'Could not load Template::View library') | ||||||||||||||||||||||||||||||||||||||||||
| 836 | ${indent}${INDENT}${INDENT} if ! eval { require Template::View }; | ||||||||||||||||||||||||||||||||||||||||||
| 837 | ${indent}${INDENT}my \$view = Template::View->new(\$self->context, \$hash) | ||||||||||||||||||||||||||||||||||||||||||
| 838 | ${indent}${INDENT}${INDENT}|| \$self->throw('view', \$Template::View::ERROR); | ||||||||||||||||||||||||||||||||||||||||||
| 839 | ${indent}${INDENT}my \$old_view = \$self->play_expr(['view', 0]); | ||||||||||||||||||||||||||||||||||||||||||
| 840 | ${indent}${INDENT}\$self->set_variable(\$name, \$view); | ||||||||||||||||||||||||||||||||||||||||||
| 841 | ${indent}${INDENT}\$self->set_variable(['view', 0], \$view);"; | ||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | ▶ | if ($node->[4]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 845 | ${indent}${INDENT}my \$out = ''; | ||||||||||||||||||||||||||||||||||||||||||
| 846 | ${indent}${INDENT}my \$out_ref = \\\$out;" | ||||||||||||||||||||||||||||||||||||||||||
| 847 | .$self->compile_tree($node->[4], "$indent$INDENT"); | ||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 851 | ${indent}${INDENT}\$self->set_variable(['view', 0], \$old_view); | ||||||||||||||||||||||||||||||||||||||||||
| 852 | ${indent}${INDENT}\$view->seal; | ||||||||||||||||||||||||||||||||||||||||||
| 853 | ${indent}};"; | ||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||
| 859 | 13 | ▶ | sub compile_WHILE { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_WHILE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 860 | 13 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | 13 | local $self->{'_in_loop'} = 'WHILE'; | |||||||||||||||||||||||||||||||||||||||||
| 863 | 13 | my $code = $self->compile_tree($node->[4], "$indent$INDENT"); | |||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||
| 865 | 13 | $$str_ref .= " | |||||||||||||||||||||||||||||||||||||||||
| 866 | ${indent}my \$count = \$Template::Alloy::WHILE_MAX; | ||||||||||||||||||||||||||||||||||||||||||
| 867 | ${indent}WHILE: while (--\$count > 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 868 | ${indent}my \$var = ".$self->compile_expr($node->[3], $indent)."; | ||||||||||||||||||||||||||||||||||||||||||
| 869 | ${indent}last if ! \$var;$code | ||||||||||||||||||||||||||||||||||||||||||
| 870 | ${indent}}"; | ||||||||||||||||||||||||||||||||||||||||||
| 871 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | 9 | ▶ | sub compile_WRAPPER { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile_WRAPPER: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 875 | 9 | my ($self, $node, $str_ref, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||
| 877 | 9 | my ($named, @files) = @{ $node->[3] }; | |||||||||||||||||||||||||||||||||||||||||
| 878 | 9 | $named = $self->ast_string($named); | |||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | $$str_ref .= " | ||||||||||||||||||||||||||||||||||||||||||
| 881 | ${indent}\$var = do { | ||||||||||||||||||||||||||||||||||||||||||
| 882 | ${indent}${INDENT}my \$out = ''; | ||||||||||||||||||||||||||||||||||||||||||
| 883 | ${indent}${INDENT}my \$out_ref = \\\$out;" | ||||||||||||||||||||||||||||||||||||||||||
| 884 | .$self->compile_tree($node->[4], "$indent$INDENT")." | ||||||||||||||||||||||||||||||||||||||||||
| 885 | ${indent}${INDENT}\$out; | ||||||||||||||||||||||||||||||||||||||||||
| 886 | ${indent}}; | ||||||||||||||||||||||||||||||||||||||||||
| 887 | ${indent}for my \$file (reverse(" | ||||||||||||||||||||||||||||||||||||||||||
| 888 | 9 | .join(",${indent}${INDENT}", map {"\$self->play_expr(".$self->ast_string($_).")"} @files).")) { | |||||||||||||||||||||||||||||||||||||||||
| 889 | ${indent}${INDENT}local \$self->{'_vars'}->{'content'} = \$var; | ||||||||||||||||||||||||||||||||||||||||||
| 890 | ${indent}${INDENT}\$var = ''; | ||||||||||||||||||||||||||||||||||||||||||
| 891 | ${indent}${INDENT}require Template::Alloy::Play; | ||||||||||||||||||||||||||||||||||||||||||
| 892 | ${indent}\$Template::Alloy::Play::DIRECTIVES->{'INCLUDE'}->(\$self, [$named, \$file], ['$node->[0]', $node->[1], $node->[2]], \\\$var); | ||||||||||||||||||||||||||||||||||||||||||
| 893 | ${indent}} | ||||||||||||||||||||||||||||||||||||||||||
| 894 | ${indent}\$\$out_ref .= \$var if defined \$var;"; | ||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||
| 896 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||
| 900 | ###----------------------------------------------------------------### | ||||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||
| 902 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||
| 904 | __END__ | ||||||||||||||||||||||||||||||||||||||||||