Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Perl's SUPER call use the arrow method?

Tags:

oop

perl

I noticed that when you call a superclass's methods, you need to do something like this :

my $self = $class->SUPER::new();

Why isn't that:

my $self = $class->SUPER->new();
like image 285
Geo Avatar asked Sep 06 '09 12:09

Geo


2 Answers

I suspect because $class->SUPER->new() would normally be the same as $class->SUPER()->new(). But there isn't a $class->SUPER() function, and its not clear what that would return.

On the other hand, $class->Foo::Bar has always been a valid way to call a method directly by full name, so making a special package-like thing — SUPER — fits in better. (I suspect that you could actually implement SUPER as a package, and maybe it historically was, I don't know)

PS: Take a look at the mro package, and $self->next::method. Also, take a look at Moose if you're going to do serious OO work in Perl.

like image 132
derobert Avatar answered Oct 04 '22 00:10

derobert


In short, SUPER isn't a method. It's a virtual package. It's documented in perlobj under the "Method Invocation" section.

Note, however, that SUPER bases itself on the current package, not the package of the instance you used it with.

like image 31
brian d foy Avatar answered Oct 03 '22 22:10

brian d foy