Oh wise perl masters, I am humbly seeking guidance.

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?

#!/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();
Thanks so much for any help on this.
-- mshiltonj

In reply to How do you use/create subroutine attributes? by mshiltonj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.