MooseX::Aliases(3pm)

πŸ“¦
version 0.11 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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:


πŸ’œ AUTHORS πŸ’œ

  • Jesse Luehrs <doy@tozt.net>
  • Chris Prather <chris@prather.org>
  • Justin Hunter <justin.d.hunter@gmail.com>

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