Dancer2
Dancer2 copied to clipboard
Template::Exception when forwarding
Sorry, I couldn't work out whether the bug is in Dancer2 or Template Toolkit. Any idea how to test Template Toolkit independently?
Context
Template-Toolkit-3.101
Dancer2-1.1.0
Perl v5.36.0
Code to replicate the issue
#!/usr/bin/perl
use Dancer2;
set template => 'template_toolkit';
get '/foo' => sub {
return forward '/bar';
};
get '/bar' => sub {
return 'Hello, World!';
};
dance;
To demonstrate the bug
curl http://localhost:3000/foo
and this is what appears in the logs:
>> Dancer2 v1.1.0 server 19422 listening on http://0.0.0.0:3000
[main:19422] debug @2024-02-14 20:04:23> bless( ['file','404.tt: not found',undef], 'Template::Exception' ) in /usr/local/share/perl/5.36.0/Dancer2/Core/Error.pm l. 73
To dodge the bug
Just comment out this line:
set template => 'template_toolkit';
I get this error when I try to curl http://localhost:3000/, but when I hit /foo, I get exactly what's expected.
That error is telling you that it's trying to use TT to render a 404 page, but there's no template available to satisfy that, and so TT throws an exception.
FYI, if you are running that test case directly from the command line, you won't have https available.
Let me know if this solves things for you!
FYI, if you are running that test case directly from the command line, you won't have https available.
Sorry Jason, that was a typo on my part :-) fixed.
Now, I realise that my expectations are based on old documentation:
https://metacpan.org/release/SUKRIA/Dancer2-0.10/view/lib/Dancer2/Manual.pod#forward
Where's the updated documentation on forward?
Updated docs are here: https://metacpan.org/dist/Dancer2/view/lib/Dancer2/Manual/Keywords.pod#forward
Implementation details have changed since then. That's very, very old now ;-)