Skip to content

Commit

Permalink
better use arguments in before_render hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 19, 2015
1 parent a7fb3a4 commit 111c38b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -509,8 +509,7 @@ passed to the renderer.
return unless $template eq 'exception';

# Switch to JSON rendering if content negotiation allows it
$args->{json} = {exception => $c->stash('exception')}
if $c->accepts('json');
$args->{json} = {exception => $args->{exception}} if $c->accepts('json');
};

get '/' => sub { die "This sho...ALL GLORY TO THE HYPNOTOAD!\n" };
Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/exception_lite_app.t
Expand Up @@ -24,14 +24,14 @@ helper dead_helper => sub { die "dead helper!\n" };
hook before_render => sub {
my ($c, $args) = @_;
return unless ($args->{template} // '') eq 'not_found';
my $exception = $c->stash('snapshot')->{exception};
my $exception = $args->{snapshot}{exception};
$args->{text} = "Missing template, $exception." if $args->{format} eq 'txt';
};

# Custom exception rendering for "txt"
hook before_render => sub {
my ($c, $args) = @_;
@$args{qw(text format)} = ($c->stash('exception'), 'txt')
@$args{qw(text format)} = ($args->{exception}, 'txt')
if ($args->{template} // '') eq 'exception' && $c->accepts('txt');
};

Expand Down

0 comments on commit 111c38b

Please sign in to comment.