[Catalyst] Catalyst action attributes

Devin Austin devin.austin at gmail.com
Mon Jul 13 07:44:27 GMT 2009


Try this:

sub post_chain_root : Chained('/') CaptureArgs(0) {

    my ($self, $c) =3D @_;

    foreach my $action (@{$c->action->chain}) {
        my $role =3D $action->attributes->{RequiresRole}[0];
        next unless $role;
        ## test role here...
    }

}


That's a bit of code that you can put in the root of a Chained chain and do
something like

sub create_new_post : RequiresRole('can_post') {

# ...

}
HTH.


On Mon, Jul 13, 2009 at 12:50 AM, Toby Corkindale <
toby.corkindale at strategicdata.com.au> wrote:

> Devin Austin wrote:
>
>> Check this out:
>> http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manu=
al/ExtendingCatalyst.pod#Attributes<http://search.cpan.org/%7Ehkclark/Catal=
yst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Attributes>and
>> http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manu=
al/ExtendingCatalyst.pod#Action_classes<http://search.cpan.org/%7Ehkclark/C=
atalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Action_clas=
ses>
>>
>
> Thanks, although I had already read that before posting.
>
> As far as I can see, there is no way to pass parameters to the ActionClas=
s.
> Have I missed something?
>
>  On Mon, Jul 13, 2009 at 12:27 AM, Toby Corkindale <
>> toby.corkindale at strategicdata.com.au <mailto:
>> toby.corkindale at strategicdata.com.au>> wrote:
>>
>>    Toby Corkindale wrote:
>>
>>        Hi,
>>        I wondered if anyone could point me towards a working example of
>>        creating custom action attribute handlers for Catalyst?
>>
>>        eg. The contents of Catalyst::Controller::SecretAgent in the
>>        example below:
>>
>>
>>        package MyApp::Controller::M;
>>        use parent 'Catalyst::Controller::SecretAgent';
>>        # Provides Vehicle() and Gimmick() actions.
>>
>>        sub bond : Vehicle('Aston Martin') {
>>         my ($self, $c) =3D @_;
>>         # ...
>>        }
>>
>>        sub maxwell_smart : Gimmick('Shoe-phone') {
>>         My ($self, $c) =3D @_;
>>         #...
>>        }
>>
>>        1;
>>
>>
>>
>>    I should clarify what I'm after..
>>    I'd still like to be able to specify regular DispatchType attributes
>>    against the routines (eg. Local, Chained, etc), but I'd also like to
>>    have my own methods called against the other attributes I've specifie=
d.
>>
>>    The first method I tried was:
>>     package Catalyst::Controller::SecretAgent;
>>     use strict / use warnings
>>     use parent 'Catalyst::Controller';
>>     use attributes __PACKAGE__ =3D> \&set_vehicle, "Vehicle";
>>     sub set_vehicle { # do something }
>>     ...
>>
>>    but I think that messes up catalyst's own handling of attributes.
>>
>>
>>    _______________________________________________
>>    List: Catalyst at lists.scsys.co.uk <mailto:Catalyst at 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/
>>
>>
>>
>>
>> --
>> Devin Austin
>> http://www.codedright.net
>> http://www.dreamhost.com/r.cgi?326568/hosting.html - Host with DreamHost!
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> List: Catalyst at 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/
>>
>
>
> --
> Strategic Data Pty Ltd
> Ph: 03 9340 9000
>
>
> _______________________________________________
> List: Catalyst at 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/
>



-- =

Devin Austin
http://www.codedright.net
http://www.dreamhost.com/r.cgi?326568/hosting.html - Host with DreamHost!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090713/26031=
53d/attachment.htm


More information about the Catalyst mailing list