Here are two other ways of dealing with it:

First, in your base module, create a MODIFY_CODE_ATTRIBUTES method that manually walks up the inheritance tree calling MODIFY_CODE_ATTRIBUTES on all of the super classes.

use strict; use warnings; package One; sub MODIFY_CODE_ATTRIBUTES { my ( $pkg, $ref, @attr ) = @_; print "Package One handler given (@attr) and handles 'Eins'\n"; return grep { $_ ne 'Eins' } @attr; } package Two; use base qw(One); sub MODIFY_CODE_ATTRIBUTES { my ( $pkg, $ref, @attr ) = @_; print "Package Two handler given (@attr) and handles 'Zwei'\n"; return grep { $_ ne 'Zwei' } @attr; } package Three; sub MODIFY_CODE_ATTRIBUTES { my ( $pkg, $ref, @attr ) = @_; print "Package Three handler given (@attr) and handles 'Drei'\n"; return grep { $_ ne 'Drei' } @attr; } package Four; sub empty {} package Five; use base qw[ Two Three Four ]; use Class::ISA; sub MODIFY_CODE_ATTRIBUTES { my ( $pkg, $ref, @attr ) = @_; foreach my $class (Class::ISA::super_path($pkg)) { @attr = $class->MODIFY_CODE_ATTRIBUTES( $ref, @attr ) if $class->can('MODIFY_CODE_ATTRIBUTES'); } print "These attributes are left over (@attr) \n" if @attr; return @attr; } sub foo : Eins Zwei Drei { } __END__

Second, use NEXT to make sure all classes have a chance to run their MODIFY_CODE_ATTRIBUTES method. This depends on all classes working together to make sure they all use and call NEXT.

use strict; use warnings; package One; use NEXT; sub MODIFY_CODE_ATTRIBUTES { my ( $pkg, $ref, @attr ) = @_; print "Package One handler given (@attr) and handles 'Eins'\n"; @attr = grep { $_ ne 'Eins' } @attr; return $pkg->NEXT::MODIFY_CODE_ATTRIBUTES($ref, @attr); } package Two; use base qw(One); use NEXT; sub MODIFY_CODE_ATTRIBUTES { my ( $pkg, $ref, @attr ) = @_; print "Package Two handler given (@attr) and handles 'Zwei'\n"; @attr = grep { $_ ne 'Zwei' } @attr; return $pkg->NEXT::MODIFY_CODE_ATTRIBUTES($ref, @attr); } package Three; use NEXT; sub MODIFY_CODE_ATTRIBUTES { my ( $pkg, $ref, @attr ) = @_; print "Package Three handler given (@attr) and handles 'Drei'\n"; @attr = grep { $_ ne 'Drei' } @attr; return $pkg->NEXT::MODIFY_CODE_ATTRIBUTES($ref, @attr); } package Four; sub empty {} package Five; use base qw[ Two Three Four ]; sub foo : Eins Zwei Drei { } __END__

Update: I should have noted that neither of these options are ideal... The first could potentially call the same MODIFY_CODE_ATTRIBUTES method in one class two times, if one of the modules already calls SUPER::MODIFY_CODE_ATTRIBUTES (not sure if that would break things, probably not). Also, a module will not have the ability to override the MODIFY_CODE_ATTRIBUTES method of it's parent class, since the parent class version will still be called... The second version requires you to trust that all the modules you inherit from that have a MODIFY_CODE_ATTRIBUTES method also use the NEXT method otherwise something might get missed.


In reply to Re: Package-specific Attribute Handling and Multiple Inheritence by cees
in thread 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.