Skip to content

Commit

Permalink
added the controller global handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
John Napiorkowski committed Jun 9, 2010
1 parent d2270ff commit 58ca855
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
15 changes: 3 additions & 12 deletions lib/Catalyst/ActionRole/BuildDBICResult.pm
Expand Up @@ -235,7 +235,7 @@ around 'dispatch' => sub {
my $final_action_result = $self->$orig($ctx, @_);

if($err) {
my ($type, $target) = ('forward', $controller->action_for($base_name .'_ERROR'));
my ($type, $target) = ('forward', ($controller->action_for($base_name .'_ERROR') || $controller->action_for('ERROR')));
if($self->has_handlers && $self->handlers->{error}) {
($type, $target) = %{$self->handlers->{error}};
}
Expand All @@ -247,15 +247,15 @@ around 'dispatch' => sub {
}

if($row) {
my ($type, $target) = ('forward', $controller->action_for($base_name .'_FOUND'));
my ($type, $target) = ('forward', ($controller->action_for($base_name .'_FOUND') || $controller->action_for('FOUND') ));
if($self->has_handlers && $self->handlers->{found}) {
($type, $target) = %{$self->handlers->{found}};
}
if($target) {
$final_action_result = $ctx->$type( $target, [$row, @{$ctx->req->args}] );
}
} else {
my ($type, $target) = ('forward', $controller->action_for($base_name .'_NOTFOUND'));
my ($type, $target) = ('forward', ($controller->action_for($base_name .'_NOTFOUND') || $controller->action_for('NOTFOUND') ));
if($self->has_handlers && $self->handlers->{notfound}) {
($type, $target) = %{$self->handlers->{notfound}};
}
Expand Down Expand Up @@ -843,15 +843,6 @@ example.
Please see L</FIND CONDITIONS DETAILS> for more.
=head2 detach_exceptions
detach_exceptions => 1, # default is 0
By default we $ctx->forward to expection handlers (NOTFOUND, ERROR), which we
believe gives you the most flexibility. You can always detach within a handling
action. However if you wish, you can force NOTFOUND or ERROR to detach instead
of forwarding by setting this option to any true value.
=head2 auto_stash
If this is true (default is false), upon a FOUND result, place the found
Expand Down
6 changes: 6 additions & 0 deletions t/app.t
Expand Up @@ -114,6 +114,12 @@ ok my $user_code_store2 = request(GET '/inherit/user_code_store2/102')->content,
is $user_code_store2, 'user_code_store2,jay@shutterstock.com',
'got expected values for user_code_store2 not found';

ok my $global_not_found = request(GET '/inherit/user_code_store2/xxxx')->content,
'checking global_not_found';

is $global_not_found, 'user_code_store2,global_not_found',
'got expected values for global_not_found not found';

SKIP: {
skip 'need better IOC (or something)', 1;
ok my $role_value_store = request(GET '/inherit/role_value_store/admin')->content,
Expand Down
4 changes: 4 additions & 0 deletions t/lib/TestApp/Controller/Inherit.pm
Expand Up @@ -228,5 +228,9 @@ sub end :Private {
}
}

sub NOTFOUND :Action {
my ($self, $ctx) = @_;
push @{$ctx->stash->{res}}, 'global_not_found';
}

1;

0 comments on commit 58ca855

Please sign in to comment.