I've been threatening for more than a year to write a plugin to do this.
I wrote to ask for CPAN/method name suggestions, Aristotle gave me good advice
which I'll have to dig up.

If you want to do it yourself you would just put a new method which dies
and detaches. Then in your examples below you'd call
$c->error_out() (I think this is my original stupid name which Aristotle
tried to save us all from) and it would throw your exception (or perhaps
something out of $c->errors) and $c->detach("end")... maybe. It's been
a year since I looked at it though I think it's a good idea.

-Ashley

On Mar 14, 2008, at 12:54 AM, Dami Laurent (PJ) wrote:

Hello list,

Sorry, I already asked the same question a couple of days ago, but
probably I was not clear enough.

My problem is that if there is an exception at the entry point of an
action chain, processing nevertheless continues until the endpoint of
the chain.

Consider for example the following action chain :

   sub one : Chained("/") :PathPart("one") :CaptureArgs(0) {
     my ($self, $c) = @_;
     $c->{stash}{msg} = "start_work";
     die "die in one";
   }

   sub two : Chained("one") :PathPart("two") :CaptureArgs(0) {
     my ($self, $c) = @_;
     $c->{stash}{msg} .= ", ". $self->expensive_work($c);
     die "die in two";
   }

   sub three : Chained("two") :PathPart("three") :Args(0) {
     my ($self, $c) = @_;
     $c->{stash}{msg} .= ", ". $self->expensive_work($c) . " again";
     die "die in three";
     $c->response->body($c->stash->{msg});
   }

   sub expensive_work {
     my ($self, $c) = @_;
     return "this took me a long time";
   }

and the following finalize_error function :

sub finalize_error {
  my ($c) = @_;
  my $body = "got errors : " . join ("\n", @{$c->error})
           . "\nand message was :\n" . $c->stash->{msg};
  $c->response->body($body);
}

This yields

  got errors : Caught exception in
Cata_exceptions::Controller::Root->one "die in one at
D:/Temp/Cata_exceptions/scripts/../lib/Cata_exceptions/Controller/ Root.p
m line 22."
Caught exception in Cata_exceptions::Controller::Root->two "die in two
at
D:/Temp/Cata_exceptions/scripts/../lib/Cata_exceptions/Controller/ Root.p
m line 28."
  Caught exception in Cata_exceptions::Controller::Root->three "die in
three at
D:/Temp/Cata_exceptions/scripts/../lib/Cata_exceptions/Controller/ Root.p
m line 35."
  and message was :
  start_work, this took me a long time, this took me a long time again


Now the question is : how to avoid calling expensive_work() ? Is there a
way to tune up the chaining mechanism so that it would automatically
detach() at the first exception ?

Thanks in advance, Laurent Dami

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/ catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to