Skip to content
Browse files

Merge branch 'topic/errorhook' into devel

  • Loading branch information...
2 parents 0c4e1b5 + 1414b17 commit b8486eb0c96b4fa06363d11dfce04f38029282ee @ambs ambs committed
Showing with 43 additions and 1 deletion.
  1. +4 −0 CHANGES
  2. +11 −0 lib/Dancer.pm
  3. +3 −1 lib/Dancer/Error.pm
  4. +25 −0 t/22_hooks/09_before_error_init.t
View
4 CHANGES
@@ -1,3 +1,7 @@
+
+ [ ENHANCEMENTS ]
+ * Error Hook (PR 563 - JT Smith)
+
1.3060 15.06.2011
** Codename: Pirouetting Pedro // Pedro Melo **
View
11 lib/Dancer.pm
@@ -795,6 +795,17 @@ This hook receives as argument the path of the file to render.
...
};
+
+=item before_error_init
+
+This hook receives as argument a L<Dancer::Error> object.
+
+ hook before_error_init => sub {
+ my $error = shift;
+ ...
+ };
+
+
=item before_error_render
This hook receives as argument a L<Dancer::Error> object.
View
4 lib/Dancer/Error.pm
@@ -16,11 +16,13 @@ use Dancer::FileUtils qw(open_file);
use Dancer::Engine;
Dancer::Factory::Hook->instance->install_hooks(
- qw/before_error_render after_error_render/);
+ qw/before_error_render after_error_render before_error_init/);
sub init {
my ($self) = @_;
+ Dancer::Factory::Hook->instance->execute_hooks('before_error_init', $self);
+
$self->attributes_defaults(
title => 'Error ' . $self->code,
type => 'runtime error',
View
25 t/22_hooks/09_before_error_init.t
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use lib '../../lib';
+use Test::More import => ['!pass'];
+use Dancer ':syntax';
+use Dancer::Test;
+
+plan tests => 3;
+
+get '/' => sub {
+ die 'ouch!';
+};
+
+route_exists [ GET => '/' ];
+response_status_is( [ GET => '/' ], 500 );
+
+hook before_error_init => sub {
+ my $error = shift;
+ $error->{code} = 555;
+ $error->{title} = 'foo';
+ $error->{message} = 'bar';
+};
+
+response_status_is( [ GET => '/' ], 555 );
+

0 comments on commit b8486eb

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