http://qs321.pair.com?node_id=488877

Thilosophy has asked for the wisdom of the Perl Monks concerning the following question:

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