Method::Alias(3pm) User Contributed Perl Documentation Method::Alias(3pm)NAME
Method::Alias - Create method aliases (and do it safely)
SYNOPSIS
# My method
sub foo {
...
}
# Alias the method
use Method::Alias 'bar' => 'foo',
'baz' => 'foo';
DESCRIPTION
For a very long time, whenever I wanted to have a method alias (provide an alternate name for a method) I would simple do a GLOB alias.
That is,
# My method
sub foo {
...
}
# Alias the method
*bar = *foo;
While this works fine for functions, it does not work for methods.
If your class has a subclass that redefines "foo", any call to "bar" will result in the overloaded method being ignored and the wrong "foo"
method being called.
These are basically bugs waiting to happen, and having completed a number of very large APIs with lots of depth myself, I've been bitten
several times.
In this situation, the canonical and fasest way to handle an alias looks something like this.
# My method
sub foo {
...
}
# Alias the method
sub bar { shift->foo(@_) }
Note that this adds an extra entry to the caller array, but this isn't really all that important unless you are paranoid about these
things.
The alternative would be to try to find the method using UNIVERSAL::can, and then goto it. I might add this later if someone really wants
it, but until then the basic method will suffice.
That doing this right is even worthy of a module is debatable, but I would rather have something that looks like a method alias definition,
than have to document additional methods all the time.
Using Method::Alias
Method::Alias is designed to be used as a pragma, to which you provide a set of pairs of method names. Only very minimal checking is done,
if you wish to create infinite loops or what have you, you are more than welcome to shoot yourself in the foot.
# Add a single method alias
use Method::Alias 'foo' => 'bar';
# Add several method aliases
use Method::Alias 'a' => 'b',
'c' => 'd',
'e' => 'f';
And for now, that's all there is to it.
METHODS
import from => to, ...
Although primarily used as a pragma, you may call import directly if you wish.
Taking a set of pairs of normal strings, the import method creates a number of methods in the caller's package to call the real method.
Returns true, or dies on error.
SUPPORT
Bugs should always be submitted via the CPAN bug tracker
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Method-Alias>
For other issues, contact the maintainer
AUTHORS
Adam Kennedy <cpan@ali.as>
SEE ALSO
<http://ali.as/>
COPYRIGHT
Copyright 2004, 2006 Adam Kennedy. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
perl v5.8.8 2006-07-15 Method::Alias(3pm)
Emergency UNIX and Linux Support !! Help Me! Forum (Request Urgent Help)
README FIRST: How to Request Emergency or Urgent Help:
You may post emergency work-related questions in the emergency forum. To post in this forum you will need to use your Bits. All questions answered on a "best... (0 Replies)
Homework Help:
On Posting Questions:
Any and all high school and undergraduate homework assignments or textbook style exercises for which you are seeking assistance are to be posted only in our Homework & Coursework Questions area--not in blogs, visitor messages, PMs, or the main technical... (0 Replies)
How to Use Code Tags in The UNIX and Linux Forums
Developer: This video tutorial was created by scott for forum users. Everyone should use code tags when posting code and command line logic in the forums.
cPF45jjWe7Q
A full list of BB codes is available here. (8 Replies)
RULES OF THE UNIX AND LINUX FORUMS
For the latest version of the community rules (the official community rules page), please visit here.
No flames, shouting (all caps), sarcasm, bullying, profanity or arrogant posts.
No negative comments about others or impolite remarks. Be patient. No... (1 Reply)
Hey,
Just added a new UserCP option so you can change the code tags to look like the code tags in this example (turn this on and off):
Note: I set the default to "SyntaxHighlighting" for debugging purposes. We can change the default back to the original code tags later.
... (36 Replies)
Having spent a lot of time over the past year taking a legacy vBulletin site (this forum) and making the site responsive on mobile; I've happy with the results; but it will soon be time to move on.
Basically, at our core, we are a LAMP (Linux, Apache2, MySQL and PHP) site, and vBulletin was... (6 Replies)
On this special Happy News Year day, 1 January 2019, I am pleased to promote Ravinder Singh to UNIX.COM Moderator, for at least the following reasons:
Ravinder Loves UNIX.COM
Ravinder has 1,372 Thanks, which puts him in the Top Ten in that important single category.
Ravinder is one of... (8 Replies)
Please join me in congratulations to Wolf Machowitsch (bakunin) for his long overdue lifetime achievement award badge from UNIX.COM in computer wizardry:
"The Order of the Wizard's Hat - Lifetime Achievement Award"
This "Order of the Wizard's Hat" is presented to Wolf Machowitsch (bakunin)... (11 Replies)
Dear All,
We were hit with a denial of service (DOS) attack today beginning around June 12th 2019 @ 01:27:51 PM from an IP address registered to "RACKWEB-NET" in Bulgaria.
I was notified about this around June 12th 2019 @ 03:05 PM and did some log file analysis and discovered how the attack... (4 Replies)
Dear All,
I am very pleased to inform everyone that Nicki Paul (zxmaus) is joining the Moderation Team after a number of years away from the site.
Nicki used to be very active here (over 800 posts), and she got busy with travel, work, family and her dogs, and we have missed her. Now she is... (7 Replies)