[Catalyst] perl subroutine attributes

Yuval Kogman nothingmuch at woobling.org
Wed Mar 15 15:37:24 CET 2006


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

> Are there any basic-but-working examples of attribute usage that I can
> refer to, other than catalyst? Or just other useful links?

Attribuute::Handler is a good start, probably.

The 'shared' attribute for variables (threads), and 'locked' for
subroutines are good examples.

Basically the idea is that you can attach meta data to a
declaration.

Within Catalyst the way it works is:

	1. The controller base class contains attribute handlers
	2. The controller code declares a subroutine with an attribute	
	3. the attribute handler is triggered by the compiler 
	4. the attribute handler looks at the code ref, and constructs a
	Catalyst::Action object with all the interesting info from the
	attribute (it's name, it's arguments)

then, later these objects are collected into the dispatcher.

P.S. Note that attributes on lexical variables get delivered
whenever the variable is allocated (every block entry), unnlike
attributes for any other declaration which is typically handled at
compile time.

-- 
 ()  Yuval Kogman <nothingmuch at woobling.org> 0xEBD27418  perl hacker &
 /\  kung foo master: /me wields bonsai kittens: neeyah!!!!!!!!!!!!!!!!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060315/9729aae3/attachment.pgp 


More information about the Catalyst mailing list