| [reply] |
It's useful when you have multiple-inheritance, to say which of your parent classes to start searching.
Ah, of course, that make a lot of sense.
It's also useful when SUPER:: would be wrong... like a flyweight class.
I'm still scratching my head about this one. This is partly because I have not yet fully grokked Class::Prototyped (but I'm getting there :-) ), but partly because for the longest time I thougth that by "wrong" you meant bad OO design (and for the life of me I couldn't, and still can't, think of any scenario in which it would be OK design-wise to use $me->Dad::hello() but at the same time not OK to use $me->SUPER::hello()). Then it finally hit me that (maybe!) by "wrong" you meant "semantically wrong", as when the code in package main contains the expression $me->SUPER::hello() intending to access the hello method of $me's parent class. With "package-less classes" as those created with Class::Prototyped, there would not be any scope in which the SUPER pseudo-class had the desired meaning.
So at least that explains (maybe) why SUPER is particularly problematic with classes/prototypes created with Class::Protoyped. But what I still can't understand is how the fact that Perl allows the $object->ParentClass::method() form can be of any help if such a class wanted to invoke a method in a parent class. For example (adapted from the Class::Prototyped docs):
use strict;
use Class::Prototyped ':EZACCESS';
my $Dad = Class::Prototyped->new(
hello => sub { print "Hiya from $Dad!\n" }
);
my $Me = Class::Prototyped::new(
'parent*' => $Dad
hello
=> sub { # ???
print "I'm just a WILD AND CRAZY GUY!\n";
}
);
How can anything having the form $object->ParentClass::method() be used the definition of $Me's hello?
| [reply] [d/l] [select] |
'hello!' => sub {
my $self = shift;
my $mirror = $self->reflect;
$mirror->super(@args_to_dad_hello);
my code here;
}
The "hello!" here is the same as [qw(hello METHOD superable)]
| [reply] [d/l] [select] |
Given such strong opinions on multiple inheritance or data hiding or a myriad of other items that perl doesn't follow ... well, I think that tells you why. Because perl isn't dogmatic about anything.
If you really want to do it, you can. Which is way better than certain other languages who think they know better than the programmer.
| [reply] |
Exactly. I think when someone says something is 'wrong' (at least in a Perl context, maybe not so for other languages) they mean 'wrong in 99.999% of cases'. If you happen to be in the 0.001% of the world where it's not wrong (or at least not completely wrong), then I hope you're using Perl :)
| [reply] |