Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix Issue 592 - template() crashes outside request.

Check whether there's a request being processed before trying to add
request-specific tokens, so that if `template()` is used outside of a request
(in a script for instance as per Nick Knutov's example), it doesn't crash.

Thanks to Nick Knutov for reporting this on the mailing list:
http://www.backup-manager.org/pipermail/dancer-users/2011-July/001604.html
  • Loading branch information...
commit 8fb2801aaa2b9138091e31720b4dd2549bf30490 1 parent 935376a
@bigpresh bigpresh authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 lib/Dancer/Template/Abstract.pm
View
11 lib/Dancer/Template/Abstract.pm
@@ -108,9 +108,14 @@ sub _prepare_tokens_options {
$tokens->{perl_version} = $];
$tokens->{dancer_version} = $Dancer::VERSION;
$tokens->{settings} = Dancer::Config->settings;
- $tokens->{request} = Dancer::SharedData->request;
- $tokens->{params} = Dancer::SharedData->request->params;
- $tokens->{vars} = Dancer::SharedData->vars;
+
+ # If we're processing a request, also add the request object, params and
+ # vars as tokens:
+ if (my $request = Dancer::SharedData->request) {
+ $tokens->{request} = $request;
+ $tokens->{params} = $request->params;
+ $tokens->{vars} = Dancer::SharedData->vars;
+ }
Dancer::App->current->setting('session')
and $tokens->{session} = Dancer::Session->get;

2 comments on commit 8fb2801

@xsawyerx
Owner

Seems fine by me!

@knutov

Thanks, this patch works fine with me test code.

Please sign in to comment.
Something went wrong with that request. Please try again.