Fellow Monks,

I have a module ( CGI::Application::Plugin::AutoRunmode ) that installs subroutine attribute handlers into the caller's namespace:

package MyApp; use base 'CGI::Application'; use CGI::Application::Plugin::AutoRunmode; sub my_run_mode : StartRunmode { # (the StartRunmode attribute is provided by the plugin) }
This works fine, unless some other module also tries to do the same thing (we would be overwriting each-others handlers). So I am now trying to find another way to implement these subroutine attributes, that is less risky to collide with other modules. My current idea is outlined below, but it does not work, raising my first question: Why does it not work? The second question would be for alternative approaches to the problem.

I thought I could avoid putting the attribute handlers into the caller's namespace by instead adding a package that contains these handlers to @ISA. Perldoc says:

When an attribute list is present in a declaration, a check is made to
       see whether an attribute 'modify' handler is present in the appropriate
       package (or its @ISA inheritance tree).
However, this sample code does not work: Package Three has two parent packages, One and Two. The attribute handler in package Two is never accessed. Am I missing something?
use strict; use warnings; { package One; sub MODIFY_CODE_ATTRIBUTES{ my ($pkg, $ref, @attr) = @_; print "Package A handler: @attr \n"; return @attr; } } { package Two; sub MODIFY_CODE_ATTRIBUTES{ my ($pkg, $ref, @attr) = @_; print "Package B handler: @attr\n"; return (); } } package Three; use base qw[ One Two]; sub foo : Eins Zwei Drei { } =========== $ perl /tmp/attr.pl Package A handler: Eins Zwei Drei Invalid CODE attributes: Eins : Zwei : Drei at /tmp/attr.pl line 30 BEGIN failed--compilation aborted at /tmp/attr.pl line 30.
Thanks for your time,

Thilo


In reply to Package-specific Attribute Handling and Multiple Inheritence by Thilosophy

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.