MooseX::Aliases(3pm)
π MooseX::Aliases β¨
okay bestie, welcome to the MooseX::Aliases era β it's a page from the User Contributed Perl Documentation collection, and honestly? it's giving "let me give my methods cute little nicknames" energy. π
πΈ NAME πΈ
MooseX::Aliases β easy aliasing of methods and attributes in Moose π¦
β VERSION β
version 0.11 π
π SYNOPSIS π
okay so first, the classic setup:
package MyApp;
use Moose;
use MooseX::Aliases;
has this => (
isa => 'Str',
is => 'rw',
alias => 'that',
);
sub foo { my $self = shift; print $self->that }
alias bar => 'foo';
my $o = MyApp->new();
$o->this('Hello World');
$o->bar; # prints 'Hello World'
or, if you're doing the role thing:
package MyApp::Role;
use Moose::Role;
use MooseX::Aliases;
has this => (
isa => 'Str',
is => 'rw',
alias => 'that',
);
sub foo { my $self = shift; print $self->that }
alias bar => 'foo';
π DESCRIPTION π
MooseX::Aliases lets you quickly alias methods in Moose. it hands you an alias parameter for has() so you get aliased accessors and the standard ones β no cap, you get both. π₯
and the glow-up doesn't stop there: attributes can also be initialized in the constructor via their aliased names. yes really, it's iconic like that. π
you can create more than one alias at once by passing an arrayref, like:
has ip_addr => (
alias => [ qw(ipAddr ip) ],
);
three names, one attribute, zero drama.</purpose> π
π FUNCTIONS π
alias ALIAS METHODNAME
installs ALIAS as a method that is aliased to the method METHODNAME. that's it, that's the whole job, and it ate. β¨
π¦ ALIASING VERSUS OTHER MOOSE FEATURES π¦
Aliasing versus inheritance
okay so peep this:
{
package Parent;
use Moose;
use MooseX::Aliases;
sub method1 { "A" }
alias method2 => "method1";
}
{
package Child1;
use Moose;
extends "Parent";
sub method1 { "B" }
}
{
package Child2;
use Moose;
extends "Parent";
sub method2 { "C" }
}
so in the example above, Child1 overrides the method using its original name (method1). as a result, calling method1 or method2 returns "B". π―
Child2 overrides the method using its alias (method2). as a result, calling method2 returns "C", but calling method1 falls through to the parent class, so it returns "A". plot twist!! π
Aliasing versus method modifiers
more examples, stay with me bestie:
{
package Class1;
use Moose;
use MooseX::Aliases;
sub method1 { "A" }
alias method2 => "method1";
around method1 => sub { "B" };
}
{
package Class2;
use Moose;
use MooseX::Aliases;
sub method1 { "A" }
alias method2 => "method1";
around method2 => sub { "B" };
}
in the example above, Class1's around modifier modifies the method using its original name. as a result, both method1 and method2 return "B". π«Ά
Class2's around modifier modifies the alias, so method2 returns "B", but method1 continues to return "A". same vibe, different name, different outcome, iykyk. π
π BUGS π
no known bugs. clean sheet, we love to see it. β¨
please report any bugs to GitHub Issues at <https://github.com/doy/moosex-aliases/issues>. π
π SEE ALSO π
- Method::Alias
πΈ SUPPORT πΈ
you can find this documentation for this module with the perldoc command:
perldoc MooseX::Aliases
you can also look for information at:
- MetaCPAN β <https://metacpan.org/release/MooseX-Aliases>
- Github β <https://github.com/doy/moosex-aliases>
- RT: CPAN's request tracker β <http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Aliases>
- CPAN Ratings β <http://cpanratings.perl.org/d/MooseX-Aliases>
π AUTHORS π
- Jesse Luehrs <doy@tozt.net>
- Chris Prather <chris@prather.org>
- Justin Hunter <justin.d.hunter@gmail.com>
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2013 by Jesse Luehrs.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie β go alias something and make it iconic. ππ
this lil rewrite was served up from MooseX::Aliases version 0.11, as documented for perl v5.34.0 on 2022-06-15. π¦β¨
π¦ where this page comes from
- debian bookworm: libmoosex-aliases-perl 0.11-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-aliases-perl 0.11-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-aliases-perl 0.11-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-aliases-perl 0.11-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-aliases-perl 0.11-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms