[Catalyst] perl subroutine attributes

Sebastian Riedel sri at oook.de
Wed Mar 15 15:57:07 CET 2006


15.03.2006 15:37 Yuval Kogman:

> On Wed, Mar 15, 2006 at 09:17:03 -0500, Steven Hilton wrote:
>
>> I could continue with the Catalyst tutorials, but the attributes  
>> thing
>> still seems like a black box to me, and I'm really trying to get a
>> deeper understanding of how and why they are used (in more of a  
>> "perl"
>> way, not just the "catalyst" way.)
>
> Basically the attributes cause a method to be invoked on the class
> in which the attribute was found. For example
>
> 	package Foo;
> 	sub moose : Bling { }
>
> will cause a compile time call of a method (i forgot it's name) on
> class Foo with Bling and some extra details as arguments to be made.
>
> From then on the handling code can choose to do anything

These are the interesting parts of our attribute caching base class.

     __PACKAGE__->mk_classdata($_) for qw/_attr_cache _action_cache/;
     __PACKAGE__->_attr_cache( {} );
     __PACKAGE__->_action_cache( [] );

     sub MODIFY_CODE_ATTRIBUTES {
         my ( $class, $code, @attrs ) = @_;
         $class->_attr_cache( { %{ $class->_attr_cache }, $code =>  
[@attrs] } );
         $class->_action_cache(
             [ @{ $class->_action_cache }, [ $code, [@attrs] ] ] );
         return ();
     }

     sub FETCH_CODE_ATTRIBUTES { $_[0]->_attr_cache->{ $_[1] } || () }


--
sebastian




More information about the Catalyst mailing list