I think typeglobs are the way to go if you want to figure out at run time what method to override.
my $package_method = 'Foo::Bar::baz'; my $orig = \&($package_method}; no warnings; *{$package_method} = sub { pre(); $orig->(@_); post() };
You can also do this:
package Foo::Bar; sub baz { print "I am the original!\n" } package main; sub Foo::Bar::baz { print "I am the new baz!\n" } Foo::Bar::baz();
Or you can toss in your own definition between a couple package lines anywhere you want. You can also build up a string like the above at run time and wrap it in an eval whenever you're ready.
Note that these various methods can have subtle differences when it comes to caller, and maybe some other stuff.
In reply to Re: What is the correct way to override a Package Method
by kyle
in thread What is the correct way to override a Package Method
by unlinker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |