in reply to Re^6: Can't locate object method- Issue
in thread Can't locate object method- Issue

Certainly, but at least to my superficial understanding of Roles, you are not supposed to change your mind after the fact. Once you've mixed together some Roles in a class, you are not supposed to change the class further, or even worse, make changes on a per-object basis.

If you need to dynamically change the class hierarchy/composition, or need to change the behaviour on a per-object basis, in my opinion, you should look at using objects that delegate to other objects instead.

Meta: I came back to this comment due to the (maybe continued) discussion of the topic in 1056122.

  • Comment on Re^7: Can't locate object method- Issue

Replies are listed 'Best First'.
Re^8: Can't locate object method- Issue
by jdporter (Paladin) on Oct 01, 2013 at 11:59 UTC
    ...not supposed to change your mind...

    But this is Perl. ;-) We can re-bless. We can mess with the class inheritance tree. We should be able to mess with roles, too.

    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

      While Perl allows for more than one way, there are some ways that are clearly not as good as others :-).

      Certainly re-blessing into a class that has imported the appropriate roles is better than manually trying to remove roles from a class. I think much of the functionality of roles is implemented by manually importing the appropriate subroutines in the package namespace, instead of using the @ISA mechanism in the hope of getting the correct implementation of a method. This makes "unimporting" a role quite hard to do.