Well, it all depends on what kind of magic you want to happen.

I am pretty sure that MODIFY_CODE_ATTRIBUTES will run in the BEGIN phase of the perl compiler. And the $code passed to you is usually a stub, and not the true subroutine that you will eventually have (however it's ref address will stay the same, so you can use that). What Catalyst does is to store the code-ref address along with the list of attributes it had for it, then when Catalyst is initialized (sometime during runtime presumably) it matches code-refs to attributes (using attribute::get() which calls FETCH_CODE_ATTRIBUTES) and does magic then. Attribute::Handlers does similar stuff, but it uses the INIT phase of the perl compiler to do it's dirty work.

In general subroutine attributes are an unwieldy beast with a really bad interface. They are especially tricky when it comes to CODE references. But then again, this is my experience, and your mileage may vary.

-stvn

In reply to Re: How do you use/create subroutine attributes? by stvn
in thread 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.