report not finding a template correctly
TtRenderer was dying with a 'not found' error when a template was not found, instead of returning 0, which was interfering with things like the error screen. Use $provider->fetch to find templates and return 0 when a template is not found.
This commit is contained in:
1 parent
d45efa5405
commit
4225658dbc
1 file changed
+19
-3
@@ -12,6 +12,7 @@ use Mojo::ByteStream 'b';
|
|||||||
use Template ();
|
use Template ();
|
||||||
use Cwd qw/abs_path/;
|
use Cwd qw/abs_path/;
|
||||||
use Scalar::Util 'weaken';
|
use Scalar::Util 'weaken';
|
||||||
|
use POSIX ':errno_h';
|
||||||
|
|
||||||
__PACKAGE__->attr('tt');
|
__PACKAGE__->attr('tt');
|
||||||
|
|
||||||
@@ -87,11 +88,26 @@ sub _render {
|
|||||||
my $provider = $self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0];
|
my $provider = $self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0];
|
||||||
$provider->options($options);
|
$provider->options($options);
|
||||||
$provider->ctx($c);
|
$provider->ctx($c);
|
||||||
$provider->not_found(0);
|
|
||||||
|
|
||||||
my $ok = $self->tt->process(defined $inline ? \$inline : $t, @params);
|
my $ok = do {
|
||||||
|
if (defined $inline) {
|
||||||
|
$self->tt->process(\$inline, @params);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my @ret = $provider->fetch($t);
|
||||||
|
|
||||||
return 0 if $provider->not_found;
|
if (not defined $ret[1]) {
|
||||||
|
$self->tt->process($ret[0], @params);
|
||||||
|
}
|
||||||
|
elsif (not defined $ret[0]) { # not found
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else { # error
|
||||||
|
return 0 if $! == ENOENT && (not ref $ret[0]); # not found when not blessed exception
|
||||||
|
die $ret[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
# Error
|
# Error
|
||||||
die $self->tt->error unless $ok;
|
die $self->tt->error unless $ok;
|
||||||
|
|||||||
Reference in new issue
Block a user