mshiltonj has asked for the wisdom of the Perl Monks concerning the following question:
I just recently discovered subroutine attributes in perl, because I'm starting to read about Catalyst. I kind of get them, but really I don't. :-/
I've read many documents on attributes, but something still isn't clicking for me. The Attribute::Deprecated module is a good basic example of how use to attributes based on the Attribute::Handlers module. I can use attributes that way and get it.
But, to get a deeper understanding (and because this is how Catalyst uses attributes), I've been trying to use the attributes pragma directly, but the documentation isn't answering a question I still have. The Catalyst code on this isn't a good example for me because it looks to be so highly optimized.
My question is illustrated by the code I have below, right on the "magic happens here" line.
How do I create the magic?
Thanks so much for any help on this.#!/usr/bin/perl -w use strict; use attributes; sub FETCH_CODE_ATTRIBUTES { return qw(Big Damn Test); } sub MODIFY_CODE_ATTRIBUTES { my ( $class, $code, @attrs ) = @_; if ( $class ne 'main' ) { if (my $code = $class->SUPER::can('MODIFY_CODE_ATTRIBUTES')) { @attrs = $code->( $class, $code, @attrs ); } } my @unknown; foreach my $attr (@attrs) { if ( 1 ) { # yeah, I'm supposed to handle this attribute # "There is no spoon." # Magic Happens Here .. ??? } else { push @unknown, $attr; } } return @unknown; } sub foo : Big Damn Test { warn "SPOOON!"; } foo();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do you use/create subroutine attributes?
by xdg (Monsignor) on Mar 17, 2006 at 20:08 UTC | |
|
Re: How do you use/create subroutine attributes?
by stvn (Monsignor) on Mar 17, 2006 at 20:00 UTC | |
by xdg (Monsignor) on Mar 17, 2006 at 20:22 UTC |