| 1 | package Template::Plex::Internal; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Template::Plex; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use List::Util qw<min max>; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | #use Symbol qw<delete_package>; | ||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp qw<carp croak>; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use feature qw<say state refaliasing lexical_subs>; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | no warnings "experimental"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | #use File::Basename qw<dirname basename>; | ||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use File::Spec::Functions qw<catfile>; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use File::Basename qw<dirname>; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | #our %EXPORT_TAGS = ( 'all' => [ qw( plex plx block pl plex_clear jmap) ] ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | our @EXPORT_OK = qw<block pl jmap>;# @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | my $Include=qr|\@\{\s*\[\s*include\s*\(\s*(.*?)\s*\)\s*\] \s* \}|x; | |||||||||||||||||||||||||||
| 27 | 1 | my $Init=qr|\@\{\s*\[\s*init\s*\{(?:.*?)\}\s*\] \s* \}|smx; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub new; #forward declare new; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub lexical{ | ||||||||||||||||||||||||||||
| 33 | 4 | ▶ | my $href=shift; | ||||||||||||||||||||||||||
|
Subroutine
lexical: called CC=5 SCAR=17.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 4 | ▶ | croak "NEED A HASH REF " unless ref $href eq "HASH" or !defined $href; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $href eq "HASH" or not defined $href
MC/DC0%0/2
ref $href eq "HASH" or not defined $href
ref $href eq "HASH"
not defined $href
Truth table33%1/3
A or not(B)
A= ref $href eq "HASH"B= not defined $href
| |||||||||||||||||||||||||||||
| 35 | 4 | ▶ | $href//={}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$href //= {}
MC/DC0%0/1
$href //= {}
$href
Truth table50%1/2
A
A= $href
| |||||||||||||||||||||||||||||
| 36 | 4 | \my %fields=$href; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 4 | my $string=""; | |||||||||||||||||||||||||||
| 39 | 4 | for my $k (keys %fields){ | |||||||||||||||||||||||||||
| 40 | 0 | $string.= "\\my \$$k=\\\$fields{$k};\n"; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 4 | $string; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub bootstrap{ | ||||||||||||||||||||||||||||
| 46 | 4 | ▶ | my $plex=shift; | ||||||||||||||||||||||||||
|
Subroutine
bootstrap: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||
| 47 | 4 | \my $_data_=\shift; | |||||||||||||||||||||||||||
| 48 | 4 | my $href=shift; | |||||||||||||||||||||||||||
| 49 | 4 | my %opts=@_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | $href//={}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$href //= {}
MC/DC0%0/1
$href //= {}
$href
Truth table50%1/2
A
A= $href
| |||||||||||||||||||||||||||||
| 52 | 4 | \my %fields=$href; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | my $out="package $opts{package} { | |||||||||||||||||||||||||||
| 55 | use Template::Plex::Internal qw<pl block jmap>; | ||||||||||||||||||||||||||||
| 56 | no warnings qw<syntax>; | ||||||||||||||||||||||||||||
| 57 | "; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 4 | $out.='my $self=$plex; | |||||||||||||||||||||||||||
| 60 | '; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 4 | $out.= ' \my %fields=$href; | |||||||||||||||||||||||||||
| 63 | '; | ||||||||||||||||||||||||||||
| 64 | 4 | ▶ | $out.=' my %options=%opts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | ' if keys %opts; | ||||||||||||||||||||||||||||
| 66 | 4 | for($opts{use}->@*){ | |||||||||||||||||||||||||||
| 67 | 0 | $out.="use $_;\n"; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 4 | ▶ | $out.=lexical($href) unless $opts{no_alias}; #add aliased variables from hash | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 4 | $out.=' | |||||||||||||||||||||||||||
| 72 | my %cache; #Stores code refs using caller as keys | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub clear { | ||||||||||||||||||||||||||||
| 75 | %cache=(); | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub skip{ | ||||||||||||||||||||||||||||
| 79 | goto _PLEX_SKIP; | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | $plex->[Template::Plex::skip_]=\&skip; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | my sub init :prototype(&){ | ||||||||||||||||||||||||||||
| 86 | $self->_init(@_); | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | sub slot { | ||||||||||||||||||||||||||||
| 90 | $self->slot(@_); | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | sub fill_slot { | ||||||||||||||||||||||||||||
| 93 | $self->fill_slot(@_); | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | sub inherit { | ||||||||||||||||||||||||||||
| 96 | $self->inherit(@_); | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub load { | ||||||||||||||||||||||||||||
| 100 | $self->load(@_); | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub cache { | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | my ($id, $path, $var, @opts)=@_; | ||||||||||||||||||||||||||||
| 106 | #we want to cache based on the caller | ||||||||||||||||||||||||||||
| 107 | $id=$path.join "", caller; | ||||||||||||||||||||||||||||
| 108 | #unshift @_, $id; | ||||||||||||||||||||||||||||
| 109 | $self->cache($id,$path, $var,@opts); | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | sub immediate { | ||||||||||||||||||||||||||||
| 113 | my ($id, $path, $var, @opts)=@_; | ||||||||||||||||||||||||||||
| 114 | #we want to cache based on the caller | ||||||||||||||||||||||||||||
| 115 | $id=$path.join "", caller; | ||||||||||||||||||||||||||||
| 116 | my $template=$self->cache($id, $path,$var, @opts); | ||||||||||||||||||||||||||||
| 117 | if($template){ | ||||||||||||||||||||||||||||
| 118 | return $template->render; | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | ""; | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub { | ||||||||||||||||||||||||||||
| 125 | no warnings \'uninitialized\'; | ||||||||||||||||||||||||||||
| 126 | no strict; | ||||||||||||||||||||||||||||
| 127 | #my $plex=shift; | ||||||||||||||||||||||||||||
| 128 | my $self=shift; | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | \\my %fields=shift//\\%fields; | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | ##__START | ||||||||||||||||||||||||||||
| 134 | return $self->prefix. | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | {'. | ||||||||||||||||||||||||||||
| 137 | $_data_ | ||||||||||||||||||||||||||||
| 138 | . '} | ||||||||||||||||||||||||||||
| 139 | .$self->postfix; | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | _PLEX_SKIP: | ||||||||||||||||||||||||||||
| 142 | ""; | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | };'; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | }; | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # First argument the template string/text. This is any valid perl code | ||||||||||||||||||||||||||||
| 150 | # Second argument is a hash ref to default or base level fields | ||||||||||||||||||||||||||||
| 151 | # returns a code reference which when called renders the template with the values | ||||||||||||||||||||||||||||
| 152 | sub _prepare_template{ | ||||||||||||||||||||||||||||
| 153 | 1 | ▶ | no warnings qw<syntax>; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 154 | 4 | ▶ | my ($plex, undef, $href, %opts)=@_; | ||||||||||||||||||||||||||
|
Subroutine
_prepare_template: called CC=9 SCAR=31.1
| |||||||||||||||||||||||||||||
| 155 | 4 | ▶ | $href//={}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$href //= {}
MC/DC0%0/1
$href //= {}
$href
Truth table50%1/2
A
A= $href
| |||||||||||||||||||||||||||||
| 156 | 4 | \my %fields=$href; | |||||||||||||||||||||||||||
| 157 | 4 | \my %meta=\%opts; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | #$plex now variable is now of base class | ||||||||||||||||||||||||||||
| 160 | 4 | ▶ | $plex=($opts{base}//"Template::Plex")->new($plex); | ||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"base"} // "Template::Plex"
MC/DC0%0/1
$opts{"base"} // "Template::Plex"
$opts{"base"}
Truth table50%1/2
A
A= $opts{"base"}
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 4 | $plex->[Template::Plex::meta_]=\%opts; | |||||||||||||||||||||||||||
| 163 | 4 | $plex->[Template::Plex::args_]=$href; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 4 | my $prog=&Template::Plex::Internal::bootstrap; | |||||||||||||||||||||||||||
| 166 | 1 | ▶ | my $ref=eval $prog; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
BEGIN: called CC=1 SCAR=1.0
Subroutine
cache: called CC=1 SCAR=1.0
Subroutine
cache: not called CC=1 SCAR=1.0
Subroutine
cache: not called CC=1 SCAR=1.0
Subroutine
cache: not called CC=1 SCAR=1.0
Subroutine
clear: not called CC=1 SCAR=1.0
Subroutine
clear: not called CC=1 SCAR=1.0
Subroutine
clear: not called CC=1 SCAR=1.0
Subroutine
clear: not called CC=1 SCAR=1.0
Subroutine
fill_slot: not called CC=1 SCAR=1.0
Subroutine
fill_slot: called CC=1 SCAR=1.0
Subroutine
fill_slot: not called CC=1 SCAR=1.0
Subroutine
fill_slot: not called CC=1 SCAR=1.0
Subroutine
immediate: not called CC=2 SCAR=8.9
Subroutine
immediate: not called CC=2 SCAR=8.9
Subroutine
immediate: not called CC=2 SCAR=8.9
Subroutine
immediate: not called CC=2 SCAR=8.9
Subroutine
inherit: not called CC=1 SCAR=1.0
Subroutine
inherit: called CC=1 SCAR=1.0
Subroutine
inherit: called CC=1 SCAR=1.0
Subroutine
inherit: not called CC=1 SCAR=1.0
Subroutine
load: not called CC=1 SCAR=1.0
Subroutine
load: not called CC=1 SCAR=1.0
Subroutine
load: not called CC=1 SCAR=1.0
Subroutine
load: not called CC=1 SCAR=1.0
Subroutine
skip: called CC=1 SCAR=1.0
Subroutine
skip: called CC=1 SCAR=1.0
Subroutine
skip: called CC=1 SCAR=1.0
Subroutine
skip: called CC=1 SCAR=1.0
Subroutine
slot: called CC=1 SCAR=1.0
Subroutine
slot: not called CC=1 SCAR=1.0
Subroutine
slot: called CC=1 SCAR=1.0
Subroutine
slot: not called CC=1 SCAR=1.0
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 167 | 4 | ▶ | if($@ and !$ref){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ and not $ref
MC/DC0%0/2
$@ and not $ref
$@
not $ref
Truth table33%1/3
A and not(B)
A= $@B= not $ref
| |||||||||||||||||||||||||||||
| 168 | 0 | my $error=$@; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | my $line=1; | |||||||||||||||||||||||||||
| 171 | 0 | my $start; | |||||||||||||||||||||||||||
| 172 | #my @lines=map { $start= $line if /##__START/;$line++ . $_."\n"; } split "\n", $prog; | ||||||||||||||||||||||||||||
| 173 | 0 | ▶ | my @lines=map { $start = $line if /##__START/; $line++;$_."\n" } split "\n", $prog; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | $start+=2; | |||||||||||||||||||||||||||
| 175 | 0 | my @error_lines; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | $error=~s/line (\d+)/do{push @error_lines, $1;"line ".($1-$start)}/eg; | |||||||||||||||||||||||||||
| 178 | 0 | $error=~s/\(eval (\d+)\)/"(".$opts{file}.")"/eg; | |||||||||||||||||||||||||||
| 179 | 0 | my $min=min @error_lines; | |||||||||||||||||||||||||||
| 180 | 0 | my $max=max @error_lines; | |||||||||||||||||||||||||||
| 181 | 0 | ▶ | $min-=5; $min=$start if $min<$start; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | $max+=5; $max=$#lines-7 if $max>($#lines-7); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | my $counter=$min-$start+1; | |||||||||||||||||||||||||||
| 184 | 0 | my $out=$error; | |||||||||||||||||||||||||||
| 185 | 0 | for ($min..$max){ | |||||||||||||||||||||||||||
| 186 | 0 | $out.=$counter++." ".$lines[$_]; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | 0 | croak $out; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | 4 | $plex->[Template::Plex::sub_]=$ref; | |||||||||||||||||||||||||||
| 191 | 4 | $plex; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | #a little helper to allow 'including' templates into each other | ||||||||||||||||||||||||||||
| 195 | sub _munge { | ||||||||||||||||||||||||||||
| 196 | 0 | ▶ | my ($input, %options)=@_; | ||||||||||||||||||||||||||
|
Subroutine
_munge: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | #test for literals | ||||||||||||||||||||||||||||
| 199 | 0 | my $path; | |||||||||||||||||||||||||||
| 200 | 0 | ▶ | if($input =~ /^"(.*)"$/){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 201 | #literal | ||||||||||||||||||||||||||||
| 202 | 0 | $path=$1; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | elsif($input =~ /^'(.*)'$/){ | ||||||||||||||||||||||||||||
| 205 | #literal | ||||||||||||||||||||||||||||
| 206 | 0 | $path=$1; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | else { | ||||||||||||||||||||||||||||
| 209 | #not supported? | ||||||||||||||||||||||||||||
| 210 | # | ||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | 0 | Template::Plex::Internal->new(\&_prepare_template,$path,"",%options); | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | sub _subst_inject { | ||||||||||||||||||||||||||||
| 216 | 4 | ▶ | \my $buffer=\(shift); | ||||||||||||||||||||||||||
|
Subroutine
_subst_inject: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||
| 217 | 4 | ▶ | while($buffer=~s|$Include|_munge($1, @_)|e){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | #TODO: Possible point for diagnostics? | ||||||||||||||||||||||||||||
| 219 | }; | ||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | sub _block_fix { | ||||||||||||||||||||||||||||
| 223 | #remove any new line immediately after a ]} pair | ||||||||||||||||||||||||||||
| 224 | 4 | ▶ | \my $buffer=\(shift); | ||||||||||||||||||||||||||
|
Subroutine
_block_fix: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 225 | #$buffer=~s/^\]\}$/]}/gms; | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 4 | $buffer=~s/^(\@\{\[.*?\]\})\n/$1/gms; | |||||||||||||||||||||||||||
| 228 | ############################################## | ||||||||||||||||||||||||||||
| 229 | # while($buffer=~s/^\]\}\n/]}/gs){ # | ||||||||||||||||||||||||||||
| 230 | # } # | ||||||||||||||||||||||||||||
| 231 | # while($buffer=~s/^(@\{\[.*?\]\})\n/$1/gs){ # | ||||||||||||||||||||||||||||
| 232 | # } # | ||||||||||||||||||||||||||||
| 233 | ############################################## | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | sub _init_fix{ | ||||||||||||||||||||||||||||
| 238 | 4 | ▶ | \my $buffer=\$_[0]; | ||||||||||||||||||||||||||
|
Subroutine
_init_fix: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 239 | #Look for an init block | ||||||||||||||||||||||||||||
| 240 | #unless($buffer=~/\@\[\{\s*init\s*\{ | ||||||||||||||||||||||||||||
| 241 | 4 | ▶ | unless($buffer=~$Init){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | #carp __PACKAGE__." no init block detected. Adding dummy"; | ||||||||||||||||||||||||||||
| 243 | 1 | $buffer="\@{[init{}]}".$buffer; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 1 | my $prepare=\&_prepare_template; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 1 | my %cache; | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | sub clear { | ||||||||||||||||||||||||||||
| 253 | 0 | ▶ | %cache=(); | ||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | sub block :prototype(&) { | ||||||||||||||||||||||||||||
| 258 | 0 | ▶ | $_[0]->(); | ||||||||||||||||||||||||||
|
Subroutine
block: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 259 | 0 | return ""; | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | 1 | *pl=\*block; | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | sub new{ | ||||||||||||||||||||||||||||
| 266 | 4 | ▶ | my $plex=bless [], shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=29.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 267 | 4 | my ($prepare, $path, $args, %options)=@_; | |||||||||||||||||||||||||||
| 268 | 4 | my $root=$options{root}; | |||||||||||||||||||||||||||
| 269 | #croak "plex: even number of arguments required" if (@_-1)%2; | ||||||||||||||||||||||||||||
| 270 | 4 | ▶ | croak "Template::Plex::Internal first argument must be defined" unless defined $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | #croak "plex: at least 2 arguments needed" if ((@_-1) < 2); | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 4 | my $data=do { | |||||||||||||||||||||||||||
| 274 | 4 | local $/=undef; | |||||||||||||||||||||||||||
| 275 | 4 | ▶ | if(ref($path) eq "GLOB"){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 276 | #file handle | ||||||||||||||||||||||||||||
| 277 | 0 | $options{file}="$path"; | |||||||||||||||||||||||||||
| 278 | 0 | <$path>; | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | elsif(ref($path) eq "ARRAY"){ | ||||||||||||||||||||||||||||
| 281 | #process as inline template | ||||||||||||||||||||||||||||
| 282 | 0 | $options{file}="$path"; | |||||||||||||||||||||||||||
| 283 | 0 | join "", @$path; | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | else{ | ||||||||||||||||||||||||||||
| 286 | #Assume a path | ||||||||||||||||||||||||||||
| 287 | #Prepend the root if present | ||||||||||||||||||||||||||||
| 288 | 4 | $options{file}=$path; | |||||||||||||||||||||||||||
| 289 | 4 | ▶ | $path=catfile $root, $path if $root; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 4 | my $fh; | |||||||||||||||||||||||||||
| 291 | 4 | ▶ | if(open $fh, "<", $path){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | <$fh> | ||||||||||||||||||||||||||||
| 293 | 4 | } | |||||||||||||||||||||||||||
| 294 | else { | ||||||||||||||||||||||||||||
| 295 | 0 | croak "Could not open file: $path $!"; | |||||||||||||||||||||||||||
| 296 | 0 | ""; | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | }; | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 4 | ▶ | $args//={}; #set to empty hash if not defined | ||||||||||||||||||||||||||
|
Condition50%1/2
$args //= {}
MC/DC0%0/1
$args //= {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 4 | ▶ | chomp $data unless $options{no_eof_chomp}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | #Perform inject substitution | ||||||||||||||||||||||||||||
| 305 | 4 | ▶ | _subst_inject($data, root=>$root) unless $options{no_include}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | #Perform suppurfluous EOL removal | ||||||||||||||||||||||||||||
| 307 | 4 | ▶ | _block_fix($data) unless $options{no_block_fix}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 4 | ▶ | _init_fix($data) unless $options{no_init_fix}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 4 | ▶ | if($args){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | #Only call this from top level call | ||||||||||||||||||||||||||||
| 311 | #Returns the render sub | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 4 | state $package=0; | |||||||||||||||||||||||||||
| 314 | 4 | $package++; | |||||||||||||||||||||||||||
| 315 | 4 | $options{package}="Template::Plex::temp".$package; #force a unique package if non specified | |||||||||||||||||||||||||||
| 316 | 4 | $prepare->($plex, $data, $args, %options); #Prepare in the correct scope | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | else { | ||||||||||||||||||||||||||||
| 319 | 0 | $data; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | #Join map | ||||||||||||||||||||||||||||
| 325 | sub jmap :prototype(&$@){ | ||||||||||||||||||||||||||||
| 326 | 0 | ▶ | my ($sub,$delimiter)=(shift,shift); #block is first | ||||||||||||||||||||||||||
|
Subroutine
jmap: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | $delimiter//=""; #delimiter is whats left | ||||||||||||||||||||||||||
|
Condition0%0/2
$delimiter //= ""
MC/DC0%0/1
$delimiter //= ""
$delimiter
Truth table0%0/2
A
A= $delimiter
| |||||||||||||||||||||||||||||
| 328 | 0 | join $delimiter, map &$sub, @_; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 1 | 1; | |||||||||||||||||||||||||||