Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
made exceptions a little more reusable
  • Loading branch information
kraih committed Jan 23, 2012
1 parent 2eb4c0d commit 7d21f95
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@
This file documents the revision history for Perl extension Mojolicious.

2.46 2012-01-23 00:00:00
2.46 2012-01-24 00:00:00
- Added EXPERIMENTAL request_timeout attribute to Mojo::UserAgent.
- Added EXPERIMENTAL text_after and text_before methods to Mojo::DOM.
- Improved all uses of syswrite to be more defensive. (bduggan, sri)
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/templates/exception.development.html.ep
@@ -1,4 +1,3 @@
% my $e = delete $self->stash->{'exception'};
<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -120,6 +119,7 @@
</tr>
% end
<div id="showcase" class="code box">
% my $e = $self->stash->{exception};
<pre><%= $e->message %></pre>
<div id="context">
<table>
Expand Down
20 changes: 19 additions & 1 deletion t/mojolicious/exception_lite_app.t
Expand Up @@ -9,7 +9,7 @@ BEGIN {
$ENV{MOJO_MODE} = 'development';
}

use Test::More tests => 74;
use Test::More tests => 80;

# "This calls for a party, baby.
# I'm ordering 100 kegs, 100 hookers and 100 Elvis impersonators that aren't
Expand Down Expand Up @@ -78,6 +78,17 @@ get '/trapped/too' => sub {
$self->render_text("$@" || 'failed');
};

# Reuse exception
my $exception;
hook after_dispatch => sub {
my $self = shift;
return unless $self->req->url->path->contains('/reuse/exception');
$exception = $self->stash('exception');
};

# GET /reuse/exception
get '/reuse/exception' => sub { die "Reusable exception.\n" };

my $t = Test::Mojo->new;

# GET /logger (debug)
Expand Down Expand Up @@ -166,6 +177,13 @@ $t->get_ok('/missing_template.json')->status_is(404)
->content_type_is('text/html;charset=UTF-8')
->content_like(qr/Page not found/);

# GET /reuse/exception
ok !$exception, 'no exception';
$t->get_ok('/reuse/exception')->status_is(500)
->content_like(qr/Reusable exception/);
isa_ok $exception, 'Mojo::Exception', 'right exception class';
like $exception, qr/Reusable exception/, 'right exception';

__DATA__
@@ layouts/green.html.ep
%= content
Expand Down

0 comments on commit 7d21f95

Please sign in to comment.