use Carp qw(confess cluck);
use Config ();
-our $VERSION = "1.012";
+our $VERSION = "1.013";
my %formats =
(
[ "<:", ":>" ],
[ "[:", ":]" ],
];
+ $topts{error_not_defined} =
+ $cfg->entry("basic", "error_not_defined", 1);
}
return Squirrel::Template->new(%topts);
use constant DEBUG_GET_PARMS => 0;
-our $VERSION = "1.030";
+our $VERSION = "1.031";
my %compile_cache;
}
}
- die "ENOIMPL\nVariable $name not defined";
+ $self->{error_not_defined}
+ and die "Variable '$name' not set\n";
+
+ die "ENOIMPL\nVariable '$name' not set";
}
sub set_var {
use Squirrel::Template::Constants qw(:node);
use Scalar::Util ();
-our $VERSION = "1.025";
+our $VERSION = "1.026";
use constant ACTS => 0;
use constant TMPLT => 1;
my @errors;
my $value = "";
- unless (eval { $value = $self->[EVAL]->process($node->[NODE_EXPR_EXPR]); 1 }) {
+ unless (eval {
+ local $SIG{__DIE__};
+ $value = $self->[EVAL]->process($node->[NODE_EXPR_EXPR]);
+ 1
+ }) {
my $msg = $@;
if ($msg =~ /\bENOIMPL\b/) {
my @errors;
my $value = "";
- if (eval { $value = $self->[EVAL]->process($node->[NODE_SET_EXPR]); 1 }) {
+ if (eval {
+ local $SIG{__DIE__};
+ $value = $self->[EVAL]->process($node->[NODE_SET_EXPR]);
+ 1
+ }) {
my @var = @{$node->[NODE_SET_VAR]};
if (@var > 1) {
my $top_name = shift @var;
my $defaults;
my $name;
if (eval {
+ local $SIG{__DIE__};
$name = $self->[EVAL]->process($node->[NODE_CALL_NAME]);
for my $arg (@{$node->[NODE_CALL_LIST]}) {
my $key = $self->[EVAL]->process($arg->[0]);
my $list;
unless (eval {
+ local $SIG{__DIE__};
$list = $self->[EVAL]->process($node->[NODE_FOR_EXPR]); 1;
}) {
my $msg = $@;
my @errors;
my $name;
if (eval {
+ local $SIG{__DIE__};
$name = $self->[EVAL]->process($filename);
for my $arg (@$args) {
my $key = $self->[EVAL]->process($arg->[0]);
my @conds = @{$node->[NODE_EXTIF_CONDS]};
while (my $cond = shift @conds) {
my $result;
- if (eval { $result = $self->[EVAL]->process($cond->[2]); 1 }) {
+ if (eval {
+ local $SIG{__DIE__};
+ $result = $self->[EVAL]->process($cond->[2]);
+ 1
+ }) {
if ($result) {
return $self->process($cond->[1]);
}
my $call;
my @args;
unless (eval {
+ local $SIG{__DIE__};
$call = $self->[EVAL]->process($node->[NODE_ITERATEOVER_CALL]);
@args = map $self->[EVAL]->process($_), @{$node->[NODE_ITERATEOVER_ARGS]};
1;
my $cond = $node->[NODE_WHILE_COND];
my $result;
- unless (eval { $result = $self->[EVAL]->process($cond); 1 }) {
+ unless (eval {
+ local $SIG{__DIE__};
+ $result = $self->[EVAL]->process($cond);
+ 1
+ }) {
my $msg = $@;
if (!ref $msg && $msg =~ /\bENOIMPL\b/) {
return
while ($result) {
push @output, $self->process($node->[NODE_WHILE_CONTENT]);
- unless (eval { $result = $self->[EVAL]->process($cond); 1 }) {
+ unless (eval {
+ local $SIG{__DIE__};
+ $result = $self->[EVAL]->process($cond);
+ 1
+ }) {
my $msg = $@;
if (!ref $msg && $msg ==~ /\bENOIMPL\b/) {
return
If set to 0, dynamic article iterators will no access control filter
their results. Default: 1.
+=item error_not_defined
+
+If non-zero, during dynamic page generation, inserts a message
+explaining which variable is not set, instead of just leaving the tag
+unreplaced. Default: 1.
+
=item http_only_session
If this is non-zero, the default, the session cookie sent to the
#!perl -w
# Basic tests for Squirrel::Template
use strict;
-use Test::More tests => 198;
+use Test::More tests => 201;
use HTML::Entities;
sub template_test($$$$;$$);
my $gotmodule = require_ok('Squirrel::Template');
+my %extra_opts;
+
SKIP: {
skip "couldn't load module", 15 unless $gotmodule;
a,b
OUT
+
+ {
+ local $extra_opts{error_not_defined} = 1;
+ template_test(<<'IN', <<'OUT', "error !defined: expr", \%acts, "", \%vars);
+<:= unknown_var :>
+IN
+* Variable 'unknown_var' not set
+ *
+OUT
+ template_test(<<'IN', <<'OUT', "error !defined: .if", \%acts, "", \%vars);
+<:.if unknown_var -:>
+a
+<:-.else -:>
+b
+<:-.end if:>
+IN
+* Variable 'unknown_var' not set
+ *
+OUT
+ template_test(<<'IN', <<'OUT', "error !defined: .set", \%acts, "", \%vars);
+<:.set foo = unknown_var :>
+IN
+* Variable 'unknown_var' not set
+ *
+OUT
+ }
}
sub template_test ($$$$;$$) {
html => sub {
encode_entities($_[0], '&<>');
}
- }
+ },
+ %extra_opts,
);
my $result = $templater->replace_template($in, $acts, undef, "test", $vars);
#!perl -w
use strict;
use BSE::Test ();
-use Test::More tests => 98;
+use Test::More tests => 101;
use File::Spec;
use FindBin;
my $cgidir = File::Spec->catdir(BSE::Test::base_dir, 'cgi-bin');
Dynamic: [1]
EXPECTED
+dyn_template_test "unknown vars", $parent, <<TEMPLATE, <<EXPECTED;
+<:= unknown_var :>
+TEMPLATE
+* Variable 'unknown_var' not set
+ *
+EXPECTED
+
$prod4->remove($cfg);
for my $prod (@prods) {
$prod->remove($cfg);