Ummm... what's wrong with having Foo inherit from Bar through @ISA? This would mean that the users of Foo would have to understand how to use OO, but that's not that difficult, and it's even a little more intuitive, in many cases.
------ We are the carpenters and bricklayers of the Information Age. Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement. | [reply] |
So...Foo could override the method in Bar and then call Foo::SUPER->method ? That would work but what if I want to do the same with modules in the future I know nothing about, sort of like a plugin? Maybe there is a better way or my thinking is all wrong. I dont' want to always be updating pacakge Foo. I want Foo to dynamically load Bar, Baz..others (from a config file), basically override the methods for the intercept and then call the method. Also, if I use plain old ISA I could have conflictig method names: Bar->method1, Bax->method1.
Maybe I'm way of base here...seems like I should be able to do it though.
| [reply] |
Yes, Foo could override the method, then call $self->SUPER::method. (Slight difference, same idea.)
Now, if you're talking about doing some sort of plugin idea ... that's getting really complicated, involving on-the-fly modifications to @ISA, etc. Essentially, what it sounds that you really want to do is create a dispatch table that would have, instead of a coderef, a list of coderefs (or function names) that would be called in that order.
There has to be a better way to do what you want to do.
Period.
Maybe if you started describing what it is you want to design for, we can help.
------ We are the carpenters and bricklayers of the Information Age. Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
| [reply] |
Keeping in mind that this sounds truly evil, though it does sound a bit like Damian's Hook::LexWrap (though I don't think that redefines any subs, just defines new methods with pre and post processing, but you may want to look at that instead/anyway), and you're better off using dragonchild's suggestions of utilizing ISA and SUPER in an orthodox manner if at all possible:
use strict;
use warnings;
package Bar;
sub f1 {
print "there @_\n";
}
package Foo;
for (keys %Bar::) {
if (exists &{$Bar::{$_}}) {
no warnings 'redefine';
my $func = \&{$Bar::{$_}};
$Bar::{$_} = sub {
print "hello ";
goto &$func;
};
}
}
package main;
Bar::f1("Bob");
| [reply] [d/l] |
| [reply] |