Fix another bunch of VMXTemplate errors
parent
65859d4485
commit
9de5cbf035
|
@ -215,14 +215,16 @@ sub compile
|
|||
my ($code, $fn, $force_reload) = @_;
|
||||
Encode::_utf8_off($code); # for md5_hex
|
||||
my $key = $fn ? 'F'.$fn : 'C'.md5_hex($code);
|
||||
|
||||
$force_reload = 1 if !$self->{compiled_code}->{$key};
|
||||
$force_reload = 1 if $self->{options}->{disable_cache};
|
||||
|
||||
# Load code
|
||||
my $mtime;
|
||||
if ($fn)
|
||||
{
|
||||
$fn = $self->{options}->{root}.$fn if $fn !~ m!^/!so;
|
||||
if (!$force_reload && $self->{reload} && $self->{ltimes}->{$fn}+$self->{reload} < time)
|
||||
if (!$force_reload && $self->{options}->{reload} && $self->{ltimes}->{$fn}+$self->{options}->{reload} < time)
|
||||
{
|
||||
$mtime = [ stat $fn ] -> [ 9 ];
|
||||
$force_reload = 1 if $mtime > $self->{mtimes}->{$fn};
|
||||
|
@ -263,7 +265,7 @@ sub compile
|
|||
if ($self->{options}->{cache_dir})
|
||||
{
|
||||
$h = $self->{options}->{cache_dir}.md5_hex($code).'.pl';
|
||||
if (-e $h && !$force_reload)
|
||||
if (-e $h)
|
||||
{
|
||||
my $r = $self->{compiled_code}->{$key} = do $h;
|
||||
if ($@)
|
||||
|
@ -272,13 +274,19 @@ sub compile
|
|||
unlink $h;
|
||||
}
|
||||
elsif (ref $r eq 'CODE' ||
|
||||
!$r->{':version'} || $r->{version} < CODE_VERSION)
|
||||
!$r->{':version'} || $r->{':version'} < CODE_VERSION)
|
||||
{
|
||||
# we got cache from older version, force recompile
|
||||
}
|
||||
else
|
||||
{
|
||||
return $r;
|
||||
if ($fn)
|
||||
{
|
||||
# remember modification and load time
|
||||
$self->{mtimes}->{$fn} = $mtime;
|
||||
$self->{ltimes}->{$fn} = time;
|
||||
}
|
||||
return ($r, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,10 @@ sub _Lexer
|
|||
sub _error
|
||||
{
|
||||
my ($self) = @_;
|
||||
$self->{lexer}->warn('Unexpected ' . $self->YYCurtok . ($self->YYCurval ? ' ' . $self->YYCurval : ''));
|
||||
if ($self->YYCurtok ne 'error')
|
||||
{
|
||||
$self->{lexer}->warn('Unexpected ' . $self->YYCurtok . ($self->YYCurval ? ' ' . $self->YYCurval : ''));
|
||||
}
|
||||
$self->{lexer}->skip_error;
|
||||
}
|
||||
|
||||
|
@ -40,6 +43,7 @@ sub compile
|
|||
delete $self->{functions}->{':main'};
|
||||
}
|
||||
return ($self->{options}->{use_utf8} ? "use utf8;\n" : "").
|
||||
($self->{options}->{input_filename} ? "# $self->{options}->{input_filename}\n" : '').
|
||||
"{\n':version' => ".VMXTemplate->CODE_VERSION.",\n".
|
||||
join(",\n", map { "'$_->{name}' => $_->{body}" } values %{$self->{functions}})."};\n";
|
||||
}
|
||||
|
@ -348,7 +352,7 @@ sub function_strftime
|
|||
my $self = shift;
|
||||
my ($fmt, $date, $time) = @_;
|
||||
$date = "($date).' '.($time)" if $time;
|
||||
$date = "POSIX::strftime($date, localtime(timestamp($date)))";
|
||||
$date = "POSIX::strftime($fmt, localtime(timestamp($date)))";
|
||||
$date = "utf8on($date)" if $self->{use_utf8};
|
||||
return $date;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ sub new
|
|||
keywords => { map { $_ => 1 } split / /, $keywords_str },
|
||||
|
||||
# Last directive start position, directive and substitution start/end counters
|
||||
skip_chars => 0,
|
||||
last_start => 0,
|
||||
last_start_line => 0,
|
||||
in_code => 0,
|
||||
|
@ -60,7 +61,7 @@ sub set_code
|
|||
$self->{code} = $code;
|
||||
$self->{eaten} = '';
|
||||
$self->{lineno} = $self->{in_code} = $self->{in_subst} = 0;
|
||||
$self->{last_start} = $self->{last_start_line} = 0;
|
||||
$self->{skip_chars} = $self->{last_start} = $self->{last_start_line} = 0;
|
||||
}
|
||||
|
||||
sub eat
|
||||
|
@ -89,7 +90,8 @@ sub line
|
|||
sub skip_error
|
||||
{
|
||||
my ($self) = @_;
|
||||
$self->{code} = substr($self->{eaten}, $self->{last_start}+1, length($self->{eaten}), '') . $self->{code};
|
||||
$self->{code} = substr($self->{eaten}, $self->{last_start}, length($self->{eaten}), '') . $self->{code};
|
||||
$self->{skip_chars} = 1;
|
||||
$self->{lineno} = $self->{last_start_line};
|
||||
$self->{in_code} = $self->{in_subst} = 0;
|
||||
}
|
||||
|
@ -105,8 +107,9 @@ sub read_token
|
|||
if ($self->{in_code} <= 0 && $self->{in_subst} <= 0)
|
||||
{
|
||||
my $r;
|
||||
my $code_pos = index($self->{code}, $self->{options}->{begin_code});
|
||||
my $subst_pos = $self->{options}->{begin_subst} ne '' ? index($self->{code}, $self->{options}->{begin_subst}) : -1;
|
||||
my $code_pos = index($self->{code}, $self->{options}->{begin_code}, $self->{skip_chars});
|
||||
my $subst_pos = $self->{options}->{begin_subst} ne '' ? index($self->{code}, $self->{options}->{begin_subst}, $self->{skip_chars}) : -1;
|
||||
$self->{skip_chars} = 0;
|
||||
if ($code_pos == -1 && $subst_pos == -1)
|
||||
{
|
||||
# No more directives
|
||||
|
@ -189,8 +192,8 @@ sub read_token
|
|||
return ('name', $l);
|
||||
}
|
||||
elsif ($self->{code} =~ /^(
|
||||
(\")(?:[^\"\\\\]+|\\\\.)*\" |
|
||||
\'(?:[^\'\\\\]+|\\\\.)*\' |
|
||||
(\")(?:[^\"\\]+|\\.)*\" |
|
||||
\'(?:[^\'\\]+|\\.)*\' |
|
||||
0\d+ | \d+(\.\d+)? | 0x\d+)/xis)
|
||||
{
|
||||
# String or numeric non-negative literal
|
||||
|
|
|
@ -22,6 +22,7 @@ sub new
|
|||
cache_dir => undef, # compiled templates cache directory
|
||||
reload => 2, # 0 means to not check for new versions of cached templates
|
||||
# > 0 - check at most each <reload> seconds
|
||||
disable_cache => 0, # turn cache off completely?
|
||||
filters => [], # filters to run on output of every template
|
||||
use_utf8 => 1, # templates are in UTF-8 and all template variables should be in UTF-8
|
||||
raise_error => 0, # die() on fatal template errors
|
||||
|
@ -78,7 +79,7 @@ sub get_errors
|
|||
return '<div id="template-errors" style="display: block; border: 1px solid black; padding: 8px; background: #fcc">'.
|
||||
'VMXTemplate errors:<ul><li>'.
|
||||
join('</li><li>', map { html_pbr($_) } @{$self->{errors}}).
|
||||
'</li></ul>';
|
||||
'</li></ul></div>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
|
|
@ -2665,7 +2665,7 @@ sub
|
|||
sub
|
||||
#line 313 "template.yp"
|
||||
{
|
||||
"{'".addcslashes($_[2], "'")."'}";
|
||||
"->{'".addcslashes($_[2], "'")."'}";
|
||||
}
|
||||
],
|
||||
[#Rule 81
|
||||
|
@ -2673,7 +2673,7 @@ sub
|
|||
sub
|
||||
#line 316 "template.yp"
|
||||
{
|
||||
($_[2][1] eq 'i' ? '['.$_[2][0].']' : "{".$_[2][0]."}");
|
||||
($_[2][1] eq 'i' ? '->['.$_[2][0].']' : "->{".$_[2][0]."}");
|
||||
}
|
||||
],
|
||||
[#Rule 82
|
||||
|
|
|
@ -311,10 +311,10 @@ varref: name {
|
|||
}
|
||||
;
|
||||
varpart: '.' name {
|
||||
"{'".addcslashes($_[2], "'")."'}";
|
||||
"->{'".addcslashes($_[2], "'")."'}";
|
||||
}
|
||||
| '[' exp ']' {
|
||||
($_[2][1] eq 'i' ? '['.$_[2][0].']' : "{".$_[2][0]."}");
|
||||
($_[2][1] eq 'i' ? '->['.$_[2][0].']' : "->{".$_[2][0]."}");
|
||||
}
|
||||
| '.' name '(' ')' {
|
||||
'->'.$_[2].'()';
|
||||
|
|
Loading…
Reference in New Issue