![]() |
|
Perl Monk, Perl Meditation | |
PerlMonks |
attribute collisions ín Mooseby morgon (Priest) |
on Apr 13, 2009 at 22:15 UTC ( #757296=perlquestion: print w/replies, xml ) | Need Help?? |
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:
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:
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:
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!
Back to
Seekers of Perl Wisdom
|
|