Which inherites from a base class:package DerivedClass; use strict; use base qw(BaseClass); use ImportClass qw(blah); sub new { return bless {}; } 1;
And uses another module to generate a method:package BaseClass; sub blah { return "blah"; } 1;
And then I want to call that generated method:package ImportClass; use strict; use NEXT; sub import { my $package = shift; my $methodname = shift; my $dest = caller; my $method = sub { return shift->SUPER::blah(); }; my $symbol = $dest . '::' . $methodname; { no strict 'refs'; *$symbol = $method; } } 1;
#!/usr/bin/perl use DerivedClass; my $object = DerivedClass->new(); print $object->blah() . "\n";
Obviously this is a simplified version of something actually useful I'm trying to accomplish.
If I run this, I'll get the error:
As SUPER is trying to look at the package in which it's defined. I thought the NEXT module would fix this, but if I change that SUPER to NEXT I get:Can't locate object method "blah" via package "ImportClass" at ImportC +lass.pm line 10.
Can't call NEXT::blah from ImportClass::__ANON__ at ImportClass.pm lin +e 10
I thought the point of NEXT was to do runtime resolution of SUPER dispatch, but it doesn't seem to like this because it is looking at the method where it was declared, not at where it was imported to. Is there any way to massage NEXT into doing what I want? Is there another way of achieving this?
Thanks for any help anyone can give.In reply to SUPER or NEXT from imported methods by jsadusk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |