Catalyst-ActionRole-DetachOnDie
view release on metacpan or search on metacpan
lib/Catalyst/ActionRole/DetachOnDie.pm view on Meta::CPAN
package Catalyst::ActionRole::DetachOnDie;
{
$Catalyst::ActionRole::DetachOnDie::VERSION = '0.001006';
}
use Moose::Role;
use Try::Tiny;
use Scalar::Util qw(blessed);
# ABSTRACT: If something dies in a chain, stop the chain. DEPRECATED IN FAVOR OF CATALYST 5.90040
around execute => sub {
my ($orig, $self, $controller, $c, @args) = @_;
try {
$self->$orig($controller, $c, @args)
} catch {
if(blessed($_) && ($_->isa('Catalyst::Exception::Detach') || $_->isa('Catalyst::Exception::Go'))){
die $_; # re-throw explicit detach
}
$c->log->error("Caught exception: $_ detaching");
$c->error([ @{ $c->error }, $_ ]);
$c->detach;
undef
}
};
no Moose::Role;
1;
__END__
=pod
=head1 NAME
Catalyst::ActionRole::DetachOnDie - If something dies in a chain, stop the chain. DEPRECATED IN FAVOR OF CATALYST 5.90040
=head1 VERSION
version 0.001006
=head1 SYNOPSIS
package MyApp::Controller::Foo;
use Moose;
BEGIN { extends 'Catalyst::Controller::ActionRole' }
__PACKAGE__->config(
action => {
'*' => { Does => 'DetachOnDie' },
},
);
...;
=head1 DESCRIPTION
Chained dispatch is arguably one of the coolest features Catalyst has to offer,
unfortunately it is marred by the bizarre decision to have exceptions thrown
B<not> detach a chain. To be clear, if one has a chain as follows:
sub first : Chained('/') PathPart('') CaptureArgs(0) { ... }
sub middle : Chained('first') PathPart('middle') CaptureArgs(0) { ... }
sub last : Chained('middle') PathPart('') Args(0) { ... }
( run in 0.625 second using v1.01-cache-2.11-cpan-5b529ec07f3 )