http://www.perlmonks.org?node_id=757296

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

Hi,

I have a Moose-question:

Previously I have used Class::Std and one of the features I like about it is that there are not attribute-collisions betweeen a class and it's base-classes.

Now what happens in Moose when there are collisions? Let's try:

package Hubba; use Moose; has hubba => ( is => "rw", isa => "Int", builder => "hubba_builder1" ) +; sub hubba_builder1 { return 1; } sub abba { my($this)=@_; return $this->hubba + 1; }

This is a class that has an int-attribute "hubba" together with a builder and another method "abba" that uses that attribute. Now we add a collision:

package Bubba; use Moose; extends "Hubba"; has hubba => ( is => "rw", isa => "Str", builder => "hubba_builder2" +); sub hubba_builder2 { my($this)=@_; return "bubba"; }

So now we have a derived class that also uses a "hubba"-attribute but with a different builder and a different type.

The problem (at least I consider it a problem) now appears when we do this:

Hubba->new->abba;

Which in this example produces a warning as abba expects an int but gets a string.

Please forgive the clumsy example but the problem I see is this:

I (up to now) have held the conviction that you should be able to derive from a class without knowing it's implementation (or attribute-list) and by deriving you should not break base-class functionality but this does not be possible in Moose. As I have tried to show above a class that derives from a base-class but accidentaly uses an attribute with the same name as one of the parent-classes not only shadows the parent-class attribute but completely replaces it, thereby possibly damaging base-class methods.

So below the line it looks to me that whenever I use Moose and want to derive from a class I have to manually ensure that there are no attribute-collision - or am I doing something wrong?

Many thanks!