| 1 | package Text::Xslate::PP; | ||||||||||||||||||||||||||||
| 2 | # Text::Xslate in pure Perl | ||||||||||||||||||||||||||||
| 3 | 190 | ▶ | use 5.008_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 190 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 190 | ▶ | use version; our $VERSION = version->declare('v3.5.9'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 190 | ▶ | BEGIN{ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 9 | 190 | ▶ | $ENV{XSLATE} = ($ENV{XSLATE} || '') . '[pp]'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{'XSLATE'} || ''
MC/DC100%1/1
$ENV{'XSLATE'} || ''
$ENV{'XSLATE'}
Truth table100%2/2
A
A= $ENV{'XSLATE'}
| |||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 190 | ▶ | use Text::Xslate::Util qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | $DEBUG | ||||||||||||||||||||||||||||
| 14 | p | ||||||||||||||||||||||||||||
| 15 | 190 | ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 190 | ▶ | use constant _PP_ERROR_VERBOSE => scalar($DEBUG =~ /\b pp=verbose \b/xms); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 190 | ▶ | use constant _DUMP_LOAD => scalar($DEBUG =~ /\b dump=load \b/xms); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 190 | ▶ | use Text::Xslate::PP::Const qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 190 | ▶ | use Text::Xslate::PP::State; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 190 | ▶ | use Text::Xslate::PP::Type::Raw; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 190 | ▶ | use Text::Xslate::PP::Opcode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 190 | ▶ | use Text::Xslate::PP::Method; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 190 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 190 | ▶ | use overload (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 190 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # it must be loaded dynamically | ||||||||||||||||||||||||||||
| 32 | 190 | require Text::Xslate; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 190 | my $state_class = 'Text::Xslate::PP::Opcode'; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 190 | $VERSION =~ s/_//; # for developers versions | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 190 | if(_PP_ERROR_VERBOSE) { | |||||||||||||||||||||||||||
| 39 | Carp->import('verbose'); | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # fix up @ISA | ||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||
| 44 | 190 | package | |||||||||||||||||||||||||||
| 45 | Text::Xslate; | ||||||||||||||||||||||||||||
| 46 | 190 | ▶ | if(!our %OPS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | # the compiler use %Text::Xslate::OPS in order to optimize the code | ||||||||||||||||||||||||||||
| 48 | 190 | *OPS = \%Text::Xslate::PP::OPS; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 190 | our @ISA = qw(Text::Xslate::PP); | |||||||||||||||||||||||||||
| 51 | package | ||||||||||||||||||||||||||||
| 52 | Text::Xslate::PP; | ||||||||||||||||||||||||||||
| 53 | 190 | our @ISA = qw(Text::Xslate::Engine); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 190 | our $_depth = 0; | |||||||||||||||||||||||||||
| 57 | 190 | our $_current_st; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 190 | our($_orig_die_handler, $_orig_warn_handler); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 190 | our %html_escape = ( | |||||||||||||||||||||||||||
| 62 | '&' => '&', | ||||||||||||||||||||||||||||
| 63 | '<' => '<', | ||||||||||||||||||||||||||||
| 64 | '>' => '>', | ||||||||||||||||||||||||||||
| 65 | '"' => '"', | ||||||||||||||||||||||||||||
| 66 | "'" => ''', # IE8 doesn't support ' in title | ||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | 190 | our $html_metachars = sprintf '[%s]', join '', map { quotemeta } keys %html_escape; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 298 | ▶ | sub _register_builtin_methods { | ||||||||||||||||||||||||||
|
Subroutine
_register_builtin_methods: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | 298 | my($self, $funcs) = @_; | |||||||||||||||||||||||||||
| 72 | 298 | Text::Xslate::PP::Method::tx_register_builtin_methods($funcs); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # | ||||||||||||||||||||||||||||
| 76 | # public APIs | ||||||||||||||||||||||||||||
| 77 | # | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1367 | ▶ | sub render_string { | ||||||||||||||||||||||||||
|
Subroutine
render_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 1367 | my($self, $string, $vars) = @_; | |||||||||||||||||||||||||||
| 81 | 1367 | $self->load_string($string); | |||||||||||||||||||||||||||
| 82 | 1303 | return $self->render('<string>', $vars); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 2338 | ▶ | sub render { | ||||||||||||||||||||||||||
|
Subroutine
render: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 2338 | my ( $self, $name, $vars ) = @_; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 2338 | ▶ | Carp::croak("Usage: Text::Xslate::render(self, name, vars)") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 2 or @_ == 3
MC/DC100%2/2
@_ == 2 or @_ == 3
@_ == 2
@_ == 3
Truth table100%3/3
A or B
A= @_ == 2B= @_ == 3
| |||||||||||||||||||||||||||||
| 89 | if !( @_ == 2 or @_ == 3 ); | ||||||||||||||||||||||||||||
| 90 | 2337 | ▶ | unless ( ref $self ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 1 | Carp::croak( "Invalid xslate instance" ); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 2336 | ▶ | if(!defined $vars) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 378 | $vars = {}; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 2336 | ▶ | if ( !defined $name ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | Carp::croak("Xslate: Template name is not given"); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 2336 | ▶ | unless ( ref $vars eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 1 | Carp::croak( sprintf("Xslate: Template variables must be a HASH reference, not %s", $vars ) ); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 2335 | my $st = $self->tx_load_template( $name, 0 ); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2329 | local $_orig_die_handler = $SIG{__DIE__}; | |||||||||||||||||||||||||||
| 109 | 2329 | local $_orig_warn_handler = $SIG{__WARN__}; | |||||||||||||||||||||||||||
| 110 | 2329 | local $SIG{__DIE__} = \&_die; | |||||||||||||||||||||||||||
| 111 | 2329 | local $SIG{__WARN__} = \&_warn; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 2329 | return tx_execute( $st, $vars ); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 4 | ▶ | sub validate { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 117 | 4 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 4 | ▶ | Carp::croak("Usage: Text::Xslate::render(self, name)") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | if !( @_ == 2 ); | ||||||||||||||||||||||||||||
| 121 | 4 | ▶ | unless ( ref $self ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | Carp::croak( "Invalid xslate instance" ); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 4 | ▶ | if ( !defined $name ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | Carp::croak("Xslate: Template name is not given"); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 4 | local $self->{cache} = 0; # do not touch the cache | |||||||||||||||||||||||||||
| 130 | 4 | $self->tx_load_template( $name, 0 ); | |||||||||||||||||||||||||||
| 131 | 2 | return; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 2 | ▶ | sub current_engine { | ||||||||||||||||||||||||||
|
Subroutine
current_engine: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 135 | 2 | ▶ | return defined($_current_st) ? $_current_st->engine : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 3 | ▶ | sub current_vars { | ||||||||||||||||||||||||||
|
Subroutine
current_vars: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 139 | 3 | ▶ | return defined($_current_st) ? $_current_st->vars : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 2 | ▶ | sub current_file { | ||||||||||||||||||||||||||
|
Subroutine
current_file: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 143 | return defined($_current_st) | ||||||||||||||||||||||||||||
| 144 | ? $_current_st->code->[ $_current_st->{ pc } ]->{file} | ||||||||||||||||||||||||||||
| 145 | 2 | ▶ | : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 4 | ▶ | sub current_line { | ||||||||||||||||||||||||||
|
Subroutine
current_line: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 149 | return defined($_current_st) | ||||||||||||||||||||||||||||
| 150 | ? $_current_st->code->[ $_current_st->{ pc } ]->{line} | ||||||||||||||||||||||||||||
| 151 | 4 | ▶ | : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 8 | ▶ | sub print { | ||||||||||||||||||||||||||
|
Subroutine
print: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 155 | 8 | shift; | |||||||||||||||||||||||||||
| 156 | 8 | ▶ | if(defined $_current_st) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 8 | foreach my $s(@_) { | |||||||||||||||||||||||||||
| 158 | 11 | $_current_st->print($s); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | else { | ||||||||||||||||||||||||||||
| 162 | 0 | Carp::croak('You cannot call print() method outside render()'); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | 8 | return ''; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | # >> copied and modified from Text::Xslate | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 3572 | ▶ | sub _assemble { | ||||||||||||||||||||||||||
|
Subroutine
_assemble: called CC=20 SCAR=30.6
| |||||||||||||||||||||||||||||
| 170 | 3572 | my ( $self, $asm, $name, $fullpath, $cachepath, $mtime ) = @_; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 3572 | ▶ | unless ( defined $name ) { # $name ... filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 0 | $name = '<string>'; | |||||||||||||||||||||||||||
| 174 | 0 | $fullpath = $cachepath = undef; | |||||||||||||||||||||||||||
| 175 | 0 | $mtime = time(); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 3572 | my $st = $state_class->new(); | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 3572 | $st->symbol({ %{$self->{ function }} }); | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 3572 | my $tmpl = []; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 3572 | $self->{ template }->{ $name } = $tmpl; | |||||||||||||||||||||||||||
| 185 | 3572 | $self->{ tmpl_st }->{ $name } = $st; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 3572 | $tmpl->[ Text::Xslate::PP::TXo_MTIME ] = $mtime; | |||||||||||||||||||||||||||
| 188 | 3572 | $tmpl->[ Text::Xslate::PP::TXo_CACHEPATH ] = $cachepath; | |||||||||||||||||||||||||||
| 189 | 3572 | $tmpl->[ Text::Xslate::PP::TXo_FULLPATH ] = $fullpath; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 3572 | $st->tmpl( $tmpl ); | |||||||||||||||||||||||||||
| 192 | 3572 | $st->engine( $self ); # weak_ref! | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 3572 | $st->{sa} = undef; | |||||||||||||||||||||||||||
| 195 | 3572 | $st->{sb} = undef; | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # stack frame | ||||||||||||||||||||||||||||
| 198 | 3572 | $st->frame( [] ); | |||||||||||||||||||||||||||
| 199 | 3572 | $st->current_frame( -1 ); | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 3572 | my $len = scalar( @$asm ); | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 3572 | $st->push_frame('main', $len); | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 3572 | $st->code_len( $len ); | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 3572 | my $code = $st->code([]); | |||||||||||||||||||||||||||
| 208 | 3572 | my $macro; | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 3572 | my $oi_line = -1; | |||||||||||||||||||||||||||
| 211 | 3572 | my $oi_file = $name; | |||||||||||||||||||||||||||
| 212 | 3572 | ▶ | for ( my $i = 0; $i < $len; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 41508 | my $c = $asm->[ $i ]; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 41508 | ▶ | if ( ref $c ne 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | Carp::croak( sprintf( "Oops: Broken code found on [%d]", $i ) ); | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 41508 | my ( $opname, $arg, $line, $file ) = @{$c}; | |||||||||||||||||||||||||||
| 220 | 41508 | my $opnum = $OPS{ $opname }; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 41508 | ▶ | unless ( defined $opnum ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 0 | Carp::croak( sprintf( "Oops: Unknown opcode '%s' on [%d]", $opname, $i ) ); | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 41508 | ▶ | if(defined $line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 17913 | $oi_line = $line; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | 41508 | ▶ | if(defined $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 6312 | $oi_file = $file; | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 41508 | $code->[$i] = { | |||||||||||||||||||||||||||
| 234 | # opcode | ||||||||||||||||||||||||||||
| 235 | opname => $opname, | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | # opinfo | ||||||||||||||||||||||||||||
| 238 | line => $oi_line, | ||||||||||||||||||||||||||||
| 239 | file => $oi_file, | ||||||||||||||||||||||||||||
| 240 | }; | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 41508 | $code->[ $i ]->{ exec_code } = $OPCODE[ $opnum ]; | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 41508 | my $oparg = $OPARGS[ $opnum ]; | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 41508 | ▶ | if ( $oparg & TXARGf_SV ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | # This line croak at 'concat'! | ||||||||||||||||||||||||||||
| 249 | # Carp::croak( sprintf( "Oops: Opcode %s must have an argument on [%d]", $opname, $i ) ) | ||||||||||||||||||||||||||||
| 250 | # unless ( defined $arg ); | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 19541 | ▶ | if( $oparg & TXARGf_KEY ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 253 | 4222 | $code->[ $i ]->{ arg } = $arg; | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | elsif ( $oparg & TXARGf_INT ) { | ||||||||||||||||||||||||||||
| 256 | 3684 | $code->[ $i ]->{ arg } = int($arg); | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 3684 | ▶ | if( $oparg & TXARGf_PC ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 1190 | my $abs_addr = $i + $arg; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 1190 | ▶ | if( $abs_addr >= $len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 0 | Carp::croak( | |||||||||||||||||||||||||||
| 263 | sprintf( "Oops: goto address %d is out of range (must be 0 <= addr <= %d)", $arg, $len ) | ||||||||||||||||||||||||||||
| 264 | ); | ||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 1190 | $code->[ $i ]->{ arg } = $abs_addr; | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | else { | ||||||||||||||||||||||||||||
| 272 | 11635 | $code->[ $i ]->{ arg } = $arg; | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | else { | ||||||||||||||||||||||||||||
| 277 | 21967 | ▶ | if( defined $arg ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | 0 | Carp::croak( sprintf( "Oops: Opcode %s has an extra argument on [%d]", $opname, $i ) ); | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | 21967 | $code->[ $i ]->{ arg } = undef; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | # special cases | ||||||||||||||||||||||||||||
| 284 | 41508 | ▶ | if( $opnum == $OPS{ macro_begin } ) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 285 | 330 | my $name = $code->[ $i ]->{ arg }; | |||||||||||||||||||||||||||
| 286 | 330 | ▶ | if(!exists $st->symbol->{$name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 330 | require Text::Xslate::PP::Type::Macro; | |||||||||||||||||||||||||||
| 288 | 330 | $macro = Text::Xslate::PP::Type::Macro->new( | |||||||||||||||||||||||||||
| 289 | name => $name, | ||||||||||||||||||||||||||||
| 290 | addr => $i, | ||||||||||||||||||||||||||||
| 291 | state => $st, | ||||||||||||||||||||||||||||
| 292 | ); | ||||||||||||||||||||||||||||
| 293 | 330 | $st->symbol->{ $name } = $macro; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | else { | ||||||||||||||||||||||||||||
| 296 | 0 | $macro = undef; | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | elsif( $opnum == $OPS{ macro_nargs } ) { | ||||||||||||||||||||||||||||
| 300 | 91 | ▶ | if($macro) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | 91 | $macro->nargs($code->[$i]->{arg}); | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | elsif( $opnum == $OPS{ macro_outer } ) { | ||||||||||||||||||||||||||||
| 305 | 13 | ▶ | if($macro) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | 13 | $macro->outer($code->[$i]->{arg}); | |||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | elsif( $opnum == $OPS{ depend } ) { | ||||||||||||||||||||||||||||
| 310 | 103 | push @{ $tmpl }, $code->[ $i ]->{ arg }; | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 3572 | push @{$code}, { | |||||||||||||||||||||||||||
| 316 | 3572 | exec_code => $OPCODE[ $OPS{end} ], | |||||||||||||||||||||||||||
| 317 | file => $oi_file, | ||||||||||||||||||||||||||||
| 318 | line => $oi_line, | ||||||||||||||||||||||||||||
| 319 | opname => 'end', | ||||||||||||||||||||||||||||
| 320 | }; # for threshold | ||||||||||||||||||||||||||||
| 321 | 3572 | return; | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||
| 325 | package | ||||||||||||||||||||||||||||
| 326 | Text::Xslate::Util; | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 190 | sub escaped_string; *escaped_string = \&mark_raw; | |||||||||||||||||||||||||||
| 329 | 1321 | ▶ | sub mark_raw { | ||||||||||||||||||||||||||
|
Subroutine
mark_raw: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 330 | 1321 | my($str) = @_; | |||||||||||||||||||||||||||
| 331 | 1321 | ▶ | if(defined $str) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | 1319 | ▶ | return ref($str) eq Text::Xslate::PP::TXt_RAW() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | ? $str | ||||||||||||||||||||||||||||
| 334 | : bless \$str, Text::Xslate::PP::TXt_RAW(); | ||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | 2 | return $str; # undef | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | 17 | ▶ | sub unmark_raw { | ||||||||||||||||||||||||||
|
Subroutine
unmark_raw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 339 | 17 | my($str) = @_; | |||||||||||||||||||||||||||
| 340 | return ref($str) eq Text::Xslate::PP::TXt_RAW() | ||||||||||||||||||||||||||||
| 341 | 17 | ▶ | ? ${$str} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | : $str; | ||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 36 | ▶ | sub html_escape { | ||||||||||||||||||||||||||
|
Subroutine
html_escape: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 346 | 36 | my($s) = @_; | |||||||||||||||||||||||||||
| 347 | 36 | ▶ | return $s if | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $s eq "Text::Xslate::Type::Raw" or not defined $s
MC/DC100%2/2
ref $s eq "Text::Xslate::Type::Raw" or not defined $s
ref $s eq "Text::Xslate::Type::Raw"
not defined $s
Truth table100%3/3
A or not(B)
A= ref $s eq "Text::Xslate::Type::Raw"B= not defined $s
| |||||||||||||||||||||||||||||
| 348 | ref($s) eq Text::Xslate::PP::TXt_RAW() | ||||||||||||||||||||||||||||
| 349 | or !defined($s); | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 31 | $s =~ s/($html_metachars)/$html_escape{$1}/xmsgeo; | |||||||||||||||||||||||||||
| 352 | 31 | return bless \$s, Text::Xslate::PP::TXt_RAW(); | |||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 190 | my $uri_unsafe_rfc3986 = qr/[^A-Za-z0-9\-\._~]/; | |||||||||||||||||||||||||||
| 356 | 2150 | ▶ | sub uri_escape { | ||||||||||||||||||||||||||
|
Subroutine
uri_escape: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 357 | 2150 | my($s) = @_; | |||||||||||||||||||||||||||
| 358 | 2150 | ▶ | return $s if not defined $s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | # XXX: This must be the same as uri_escape() in XS. | ||||||||||||||||||||||||||||
| 360 | # See also tx_uri_escape() in xs/Text-Xslate.xs. | ||||||||||||||||||||||||||||
| 361 | 2148 | ▶ | utf8::encode($s) if utf8::is_utf8($s); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | 2148 | $s =~ s/($uri_unsafe_rfc3986)/sprintf '%%' . '%02X', ord $1/xmsgeo; | |||||||||||||||||||||||||||
| 363 | 2148 | return $s; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 5 | ▶ | sub is_array_ref { ref($_[0]) eq 'ARRAY' } | ||||||||||||||||||||||||||
|
Subroutine
is_array_ref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 367 | 5 | ▶ | sub is_hash_ref { ref($_[0]) eq 'HASH' } | ||||||||||||||||||||||||||
|
Subroutine
is_hash_ref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 368 | 2 | ▶ | sub is_code_ref { ref($_[0]) eq 'CODE' } | ||||||||||||||||||||||||||
|
Subroutine
is_code_ref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 6 | ▶ | sub merge_hash { +{ %{ $_[0] }, %{ $_[1] } } } | ||||||||||||||||||||||||||
|
Subroutine
merge_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | # | ||||||||||||||||||||||||||||
| 374 | # INTERNAL | ||||||||||||||||||||||||||||
| 375 | # | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 190 | ▶ | sub tx_check_itr_ar { | ||||||||||||||||||||||||||
|
Subroutine
tx_check_itr_ar: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 378 | 202 | my ( $st, $ar, $frame, $line ) = @_; | |||||||||||||||||||||||||||
| 379 | 202 | ▶ | return $ar if ref($ar) eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 13 | ▶ | if ( defined $ar ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | 6 | ▶ | if(my $x = Text::Xslate::PP::sv_is_ref($ar, 'ARRAY', '@{}')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | 2 | return $x; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 4 | $st->error( [$frame, $line], | |||||||||||||||||||||||||||
| 387 | "Iterator variables must be an ARRAY reference, not %s", | ||||||||||||||||||||||||||||
| 388 | Text::Xslate::Util::neat( $ar ) ); | ||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | 11 | return []; | |||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 6 | ▶ | sub sv_is_ref { | ||||||||||||||||||||||||||
|
Subroutine
sv_is_ref: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 394 | 6 | my($sv, $t, $ov) = @_; | |||||||||||||||||||||||||||
| 395 | 6 | ▶ | return $sv if ref($sv) eq $t; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 6 | ▶ | if(Scalar::Util::blessed($sv) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($sv) and my $m = overload::Method($sv, $ov)
MC/DC100%2/2
builtin::blessed($sv) and my $m = overload::Method($sv, $ov)
builtin::blessed($sv)
my $m = overload::Method($sv, $ov)
Truth table100%3/3
A and B
A= builtin::blessed($sv)B= my $m = overload::Method($sv, $ov)
| |||||||||||||||||||||||||||||
| 398 | && (my $m = overload::Method($sv, $ov))) { | ||||||||||||||||||||||||||||
| 399 | 3 | $sv = $sv->$m(undef, undef); | |||||||||||||||||||||||||||
| 400 | 3 | ▶ | return $sv if ref($sv) eq $t; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | 4 | return undef; | |||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 585 | ▶ | sub tx_sv_eq { | ||||||||||||||||||||||||||
|
Subroutine
tx_sv_eq: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 406 | 585 | my($x, $y) = @_; | |||||||||||||||||||||||||||
| 407 | 585 | ▶ | if ( defined $x ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | 581 | ▶ | return defined $y && $x eq $y; | ||||||||||||||||||||||||||
|
Condition100%3/3
defined $y && $x eq $y
MC/DC100%2/2
defined $y && $x eq $y
defined $y
$x eq $y
Truth table100%3/3
A && B
A= defined $yB= $x eq $y
| |||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | else { | ||||||||||||||||||||||||||||
| 411 | 4 | return !defined $y; | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 32 | ▶ | sub tx_match { # simple smart matching | ||||||||||||||||||||||||||
|
Subroutine
tx_match: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 416 | 32 | my($x, $y) = @_; | |||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 32 | ▶ | if(ref($y) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 419 | 4 | foreach my $item(@{$y}) { | |||||||||||||||||||||||||||
| 420 | 9 | ▶ | if(defined($item)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | 7 | ▶ | if(defined($x) && $x eq $item) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $x and $x eq $item
MC/DC100%2/2
defined $x and $x eq $item
defined $x
$x eq $item
Truth table100%3/3
A and B
A= defined $xB= $x eq $item
| |||||||||||||||||||||||||||||
| 422 | 2 | return 1; | |||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | else { | ||||||||||||||||||||||||||||
| 426 | 2 | ▶ | if(not defined($x)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | 1 | return 1; | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | 1 | return ''; | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | elsif(ref($y) eq 'HASH') { | ||||||||||||||||||||||||||||
| 434 | 3 | ▶ | return defined($x) && exists $y->{$x}; | ||||||||||||||||||||||||||
|
Condition66%2/3
defined $x && exists $y->{$x}
MC/DC50%1/2
defined $x && exists $y->{$x}
defined $x
exists $y->{$x}
Truth table66%2/3
A && B
A= defined $xB= exists $y->{$x}
| |||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | elsif(defined($y)) { | ||||||||||||||||||||||||||||
| 437 | 22 | ▶ | return defined($x) && $x eq $y; | ||||||||||||||||||||||||||
|
Condition100%3/3
defined $x && $x eq $y
MC/DC100%2/2
defined $x && $x eq $y
defined $x
$x eq $y
Truth table100%3/3
A && B
A= defined $xB= $x eq $y
| |||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||
| 439 | else { | ||||||||||||||||||||||||||||
| 440 | 3 | return !defined($x); | |||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 94 | ▶ | sub tx_concat { | ||||||||||||||||||||||||||
|
Subroutine
tx_concat: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 445 | 94 | my($lhs, $rhs) = @_; | |||||||||||||||||||||||||||
| 446 | 94 | ▶ | if (!defined $lhs){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 447 | 5 | return $rhs; | |||||||||||||||||||||||||||
| 448 | }elsif(!defined $rhs){ | ||||||||||||||||||||||||||||
| 449 | 4 | return $lhs; | |||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | 85 | ▶ | if(ref($lhs) eq TXt_RAW) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | 10 | ▶ | if(ref($rhs) eq TXt_RAW) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 453 | 5 | return Text::Xslate::Util::mark_raw(${ $lhs } . ${ $rhs }); | |||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | else { | ||||||||||||||||||||||||||||
| 456 | 5 | return Text::Xslate::Util::mark_raw(${ $lhs } . Text::Xslate::Util::html_escape($rhs)); | |||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | else { | ||||||||||||||||||||||||||||
| 460 | 75 | ▶ | if(ref($rhs) eq TXt_RAW) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 461 | 7 | return Text::Xslate::Util::mark_raw(Text::Xslate::Util::html_escape($lhs) . ${ $rhs }); | |||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | else { | ||||||||||||||||||||||||||||
| 464 | 68 | return $lhs . $rhs; | |||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 8 | ▶ | sub tx_repeat { | ||||||||||||||||||||||||||
|
Subroutine
tx_repeat: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 470 | 8 | my($lhs, $rhs) = @_; | |||||||||||||||||||||||||||
| 471 | 8 | ▶ | if(!defined($lhs)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 472 | 2 | $_current_st->warn(undef, "Use of nil for repeat operator"); | |||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | elsif(!Scalar::Util::looks_like_number($rhs)) { | ||||||||||||||||||||||||||||
| 475 | 0 | $_current_st->error(undef, "Repeat count must be a number, not %s", | |||||||||||||||||||||||||||
| 476 | Text::Xslate::Util::neat($rhs)); | ||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | else { | ||||||||||||||||||||||||||||
| 479 | 6 | ▶ | if( ref( $lhs ) eq TXt_RAW ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 480 | 2 | return Text::Xslate::Util::mark_raw( Text::Xslate::Util::unmark_raw($lhs) x $rhs ); | |||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | else { | ||||||||||||||||||||||||||||
| 483 | 4 | return $lhs x $rhs; | |||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | 2 | return ''; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 3585 | ▶ | sub tx_load_template { | ||||||||||||||||||||||||||
|
Subroutine
tx_load_template: called CC=10 SCAR=23.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 491 | 3585 | my ( $self, $name, $from_include ) = @_; | |||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 3585 | ▶ | unless ( ref $self ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 494 | 0 | Carp::croak( "Invalid xslate instance" ); | |||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | 3585 | my $ttable = $self->{ template }; | |||||||||||||||||||||||||||
| 498 | 3585 | my $retried = 0; | |||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 3585 | ▶ | if(ref $ttable ne 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 501 | 1 | Carp::croak( | |||||||||||||||||||||||||||
| 502 | sprintf( "Xslate: Cannot load template '%s': %s", $name, "template table is not a HASH reference" ) | ||||||||||||||||||||||||||||
| 503 | ); | ||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | RETRY: | ||||||||||||||||||||||||||||
| 507 | 5593 | ▶ | if( $retried > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 508 | 0 | Carp::croak( | |||||||||||||||||||||||||||
| 509 | sprintf( "Xslate: Cannot load template '%s': %s", $name, "retried reloading, but failed" ) | ||||||||||||||||||||||||||||
| 510 | ); | ||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 5593 | ▶ | if ( not exists $ttable->{ $name } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 514 | 194 | $self->load_file( $name, undef, $from_include ); | |||||||||||||||||||||||||||
| 515 | 185 | $retried++; | |||||||||||||||||||||||||||
| 516 | 185 | goto RETRY; | |||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | 5399 | my $tmpl = $ttable->{ $name }; | |||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | 5399 | ▶ | if(ref($tmpl) ne 'ARRAY' or not exists $self->{tmpl_st}{$name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $tmpl ne "ARRAY" or not exists $self->{"tmpl_st"}{$name}
MC/DC100%2/2
ref $tmpl ne "ARRAY" or not exists $self->{"tmpl_st"}{$name}
ref $tmpl ne "ARRAY"
not exists $self->{"tmpl_st"}{$name}
Truth table100%3/3
A or not(B)
A= ref $tmpl ne "ARRAY"B= not exists $self->{"tmpl_st"}{$name}
| |||||||||||||||||||||||||||||
| 522 | 2 | Carp::croak( | |||||||||||||||||||||||||||
| 523 | sprintf( "Xslate: Cannot load template '%s': template entry is invalid", $name ), | ||||||||||||||||||||||||||||
| 524 | ); | ||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | 5397 | my $cache_mtime = $tmpl->[ TXo_MTIME ]; | |||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | 5397 | ▶ | if(not defined $cache_mtime) { # cache => 2 (release mode) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 530 | 1514 | return $self->{ tmpl_st }->{ $name }; | |||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | 3883 | ▶ | if( $retried > 0 or tx_all_deps_are_fresh( $tmpl, $cache_mtime ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$retried > 0 or tx_all_deps_are_fresh($tmpl, $cache_mtime)
MC/DC100%2/2
$retried > 0 or tx_all_deps_are_fresh($tmpl, $cache_mtime)
$retried > 0
tx_all_deps_are_fresh($tmpl, $cache_mtime)
Truth table100%3/3
A or B
A= $retried > 0B= tx_all_deps_are_fresh($tmpl, $cache_mtime)
| |||||||||||||||||||||||||||||
| 534 | 2059 | return $self->{ tmpl_st }->{ $name }; | |||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||
| 536 | else{ | ||||||||||||||||||||||||||||
| 537 | 1824 | $self->load_file( $name, $cache_mtime, $from_include ); | |||||||||||||||||||||||||||
| 538 | 1824 | $retried++; | |||||||||||||||||||||||||||
| 539 | 1824 | goto RETRY; | |||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | 0 | Carp::croak("Oops: Not reached"); | |||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 1883 | ▶ | sub tx_all_deps_are_fresh { | ||||||||||||||||||||||||||
|
Subroutine
tx_all_deps_are_fresh: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 547 | 1883 | my ( $tmpl, $cache_mtime ) = @_; | |||||||||||||||||||||||||||
| 548 | 1883 | my $len = scalar @{$tmpl}; | |||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | 1883 | ▶ | for ( my $i = TXo_FULLPATH; $i < $len; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 551 | 1895 | my $deppath = $tmpl->[ $i ]; | |||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | 1895 | ▶ | next if ref $deppath; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | 1856 | my $mtime = ( stat( $deppath ) )[9]; | |||||||||||||||||||||||||||
| 556 | 1856 | ▶ | if ( defined($mtime) and $mtime > $cache_mtime ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $mtime and $mtime > $cache_mtime
MC/DC50%1/2
defined $mtime and $mtime > $cache_mtime
defined $mtime
$mtime > $cache_mtime
Truth table66%2/3
A and B
A= defined $mtimeB= $mtime > $cache_mtime
| |||||||||||||||||||||||||||||
| 557 | 1824 | my $main_cache = $tmpl->[ TXo_CACHEPATH ]; | |||||||||||||||||||||||||||
| 558 | 1824 | ▶ | if ( $i != TXo_FULLPATH and $main_cache ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i != 2 and $main_cache
MC/DC50%1/2
$i != 2 and $main_cache
$i != 2
$main_cache
Truth table66%2/3
A and B
A= $i != 2B= $main_cache
| |||||||||||||||||||||||||||||
| 559 | 2 | ▶ | unlink $main_cache or warn $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||
| 561 | 1824 | if(_DUMP_LOAD) { | |||||||||||||||||||||||||||
| 562 | printf STDERR " tx_all_depth_are_fresh: %s is too old (%d > %d)\n", | ||||||||||||||||||||||||||||
| 563 | $deppath, $mtime, $cache_mtime; | ||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||
| 565 | 1824 | return 0; | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | 59 | return 1; | |||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | 3571 | ▶ | sub tx_execute { | ||||||||||||||||||||||||||
|
Subroutine
tx_execute: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 574 | 3571 | my ( $st, $vars ) = @_; | |||||||||||||||||||||||||||
| 575 | 190 | ▶ | no warnings 'recursion'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | 3571 | ▶ | if ( $_depth > 100 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 578 | 4 | Carp::croak("Execution is too deep (> 100)"); | |||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||
| 580 | 3567 | if(_PP_ERROR_VERBOSE and ref $st->{code}->[0]->{ exec_code } ne 'CODE') { | |||||||||||||||||||||||||||
| 581 | Carp::croak("Oops: Not a CODE reference: " | ||||||||||||||||||||||||||||
| 582 | . Text::Xslate::Util::neat($st->{code}->[0]->{ exec_code })); | ||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | 3567 | local $st->{pc} = 0; | |||||||||||||||||||||||||||
| 586 | 3567 | local $st->{vars} = $vars; | |||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | 3567 | local $_depth = $_depth + 1; | |||||||||||||||||||||||||||
| 589 | 3567 | local $_current_st = $st; | |||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | 3567 | local $st->{local_stack}; | |||||||||||||||||||||||||||
| 592 | 3567 | local $st->{SP} = []; | |||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | 3567 | local $st->{sa}; | |||||||||||||||||||||||||||
| 595 | 3567 | local $st->{sb}; | |||||||||||||||||||||||||||
| 596 | 3567 | local $st->{output} = ''; | |||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | 3567 | local $st->{current_frame} = $st->{current_frame}; | |||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | 3567 | eval { | |||||||||||||||||||||||||||
| 601 | 3567 | $st->{code}->[0]->{ exec_code }->( $st ); | |||||||||||||||||||||||||||
| 602 | }; | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | 3567 | @{$st->{frame}->[-1]} = Text::Xslate::PP::TXframe_START_LVAR - 1; | |||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | 3567 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 607 | 425 | my $e = $@; | |||||||||||||||||||||||||||
| 608 | 425 | die $e; | |||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||
| 610 | 3142 | return $st->{output}; | |||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | 525 | ▶ | sub _error_handler { | ||||||||||||||||||||||||||
|
Subroutine
_error_handler: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 615 | 525 | my ( $str, $die ) = @_; | |||||||||||||||||||||||||||
| 616 | 525 | my $st = $_current_st; | |||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | 525 | local $SIG{__WARN__} = $_orig_warn_handler; | |||||||||||||||||||||||||||
| 619 | 525 | local $SIG{__DIE__} = $_orig_die_handler; | |||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | 525 | ▶ | if(!_PP_ERROR_VERBOSE && $str =~ s/at .+Text.Xslate.PP.+ line \d+\.\n$//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 622 | 8 | $str = Carp::shortmess($str); | |||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | 525 | ▶ | Carp::croak( $str ) unless defined $st; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | 525 | my $engine = $st->engine; | |||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | 525 | my $cframe = $st->frame->[ $st->current_frame ]; | |||||||||||||||||||||||||||
| 630 | 525 | my $name = $cframe->[ Text::Xslate::PP::TXframe_NAME ]; | |||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | 525 | my $opcode = $st->code->[ $st->{ pc } ]; | |||||||||||||||||||||||||||
| 633 | 525 | my $file = $opcode->{file}; | |||||||||||||||||||||||||||
| 634 | 525 | ▶ | if($file eq '<string>' && exists $engine->{string_buffer}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$file eq "<string>" and exists $engine->{"string_buffer"}
MC/DC100%2/2
$file eq "<string>" and exists $engine->{"string_buffer"}
$file eq "<string>"
exists $engine->{"string_buffer"}
Truth table100%3/3
A and B
A= $file eq "<string>"B= exists $engine->{"string_buffer"}
| |||||||||||||||||||||||||||||
| 635 | 99 | $file = \$engine->{string_buffer}; | |||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | my $mess = Text::Xslate::Util::make_error($engine, $str, $file, $opcode->{line}, | ||||||||||||||||||||||||||||
| 639 | 525 | sprintf( "&%s[%d]", $name, $st->{pc} )); | |||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||
| 641 | 525 | ▶ | if ( !$die ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 642 | # $h can ignore warnings | ||||||||||||||||||||||||||||
| 643 | 62 | ▶ | if ( my $h = $engine->{ warn_handler } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 644 | 55 | $h->( $mess ); | |||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||
| 646 | else { | ||||||||||||||||||||||||||||
| 647 | 7 | warn $mess; | |||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||
| 650 | else { | ||||||||||||||||||||||||||||
| 651 | # $h cannot ignore errors | ||||||||||||||||||||||||||||
| 652 | 463 | ▶ | if(my $h = $engine->{ die_handler } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 653 | 2 | $h->( $mess ); | |||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | 463 | die $mess; # MUST DIE! | |||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||
| 657 | 56 | return; | |||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | 62 | ▶ | sub _warn { | ||||||||||||||||||||||||||
|
Subroutine
_warn: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 661 | 62 | _error_handler( $_[0], 0 ); | |||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||
| 664 | 463 | ▶ | sub _die { | ||||||||||||||||||||||||||
|
Subroutine
_die: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 665 | 463 | _error_handler( $_[0], 1 ); | |||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | { | ||||||||||||||||||||||||||||
| 669 | package | ||||||||||||||||||||||||||||
| 670 | Text::Xslate::PP::Guard; | ||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | 47 | ▶ | sub DESTROY { $_[0]->() } | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | 190 | 1; | |||||||||||||||||||||||||||
| 676 | __END__ | ||||||||||||||||||||||||||||