[Catalyst] Re: Private Chained Actions?

Aristotle Pagaltzis pagaltzis at gmx.de
Fri Jun 20 16:56:54 BST 2008


* Marc Sebastian Pelzer <marc at knusperfisch.de> [2008-06-20 14:10]:
> I'd like to forward and/or detach to private actions which
> should be chained together, like:
>
> sub hello_setup : Privat Chained {
>   my ($self, $c) = @_
>
>   $c->stash->{setup} = 'done';
> }
>
> sub hello : Private Chained('hello_setup') {
>   my ($self, $c) = @_
>
>   $c->res->body('hello! setup is ' . $c->stash->{setup});
> }
>
> sub index : Path : Args(0) {
>   my ($self, $c) = @_
>
>   $c->detach('hello');
> }
>
> This does actually not work. Only hello() is being called.

You need a screwdriver, not a hammer.

    sub hello_setup : Private {
      my ($self, $c) = @_
      $c->stash->{setup} = 'done';
    }
    
    sub hello : Private {
      my ($self, $c) = @_
      $c->forward('hello_setup'); # <---------
      $c->res->body('hello! setup is ' . $c->stash->{setup});
    }
    
    sub index : Path : Args(0) {
      my ($self, $c) = @_
      $c->detach('hello');
    }

-- 
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}
&Just->another->Perl->hack;
#Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the Catalyst mailing list