Oh wise monks,
So, I've inherited some code, and I've been assigned the task of enhancing it in various ways, but I am constrained along various dimensions. In particular, I cannot change the class/package structure, nor how packages and objects are related to one another. And I'm stuck trying to understand what's happening here...
The code here is a minimal example of what I have. The method I'm trying to understand is Q::bar.
package P; sub new { my ($proto) = @_; my $self = {}; bless $self => $proto; } sub foo { print "P: foo\n"; } sub bar { print "P: bar\n"; } package Pprime; @Pprime::ISA = qw(P); sub new { my ($proto) = @_; my $self = {}; bless $self => ref($proto) || $proto; } package Q; sub new { my ($proto) = @_; my $self = {}; bless $self => $proto; } sub bar { my $self = shift; print "Q: bar\n"; $self->SUPER::bar(); } sub test { my $self = shift; $self->foo(); $self->bar(); } package Qprime; @Qprime::ISA = qw(Q Pprime); sub new { my ($proto) = @_; my $self = {}; bless $self => ref($proto) || $proto; } package main; my $obj = Qprime->new(); $obj->test();
Running this script yields the following output:
P: foo Q: bar Can't locate object method "bar" via package "Q" (perhaps you forgot t +o load "Q"?) at ./demo.pl line 40.
Now as it turns out, I can get around the problem because I'm able to rename Q::bar, at which point the calls to P::foo and P::bar act the same. But I just don't understand why the SUPER doesn't work.
I appreciate any wisdom you can shed on the issue.
--roundboy
In reply to Weird inheritance and SUPER by roundboy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |