Purpose Typeglob
*ExistingClass::oldExistingFunction = *ExistingClass::existingFunction;
Quick and dirty. This alias passes all existingFunction characters to oldExistingFunction . This includes the sub you are interested in, but also any scalars, arrays, hashes, descriptors that may have the same name.
- Advantages: no thinking, it just works. "Quick"
- Minuses: "dirty"
Purpose Coderef
*ExistingClass::oldExistingFunction = \&ExistingClass::existingFunction;
This is only an alias. It still runs in the package, so the oldExistingFunction symbol oldExistingFunction displayed globally, which may or may not be what you want. Probably not.
- Advantages: these aliases do not "leak" to other types of variables.
- Disadvantages: more thinking, more typing. Thinks a lot if you are going to use the syntax * ... {CODE} (I personally do not use it every day)
Lexical coderef
my $oldFunction = \&ExistingClass::existingFunction;
Using my contains a link to an old function that is visible only to the currrent block / file. There is no way that external code can get it without your help anymore. Note the calling convention:
$self->$oldFunction(@args); $oldFunction->($self, @args);
- Advantages: no problems with visibility.
- Disadvantages: it is more difficult to get the right.
Moose
See jrockway answer . This should be the βRight Wayβ because there are no more nuts with globes and / or links, but I don't know if this is enough to explain this.
source share