logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

MooseX::Aliases - easy aliasing of methods and attributes in Moose

Aliasing Versus Other Moose Features

Aliasingversusinheritance
           {
               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" }
           }

       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
       returns "A".

   Aliasingversusmethodmodifiers
           {
               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".

Authors

       •   Jesse Luehrs <doy@tozt.net>

       •   Chris Prather <chris@prather.org>

       •   Justin Hunter <justin.d.hunter@gmail.com>

Bugs

       No known bugs.

       Please report any bugs to GitHub Issues at <https://github.com/doy/moosex-aliases/issues>.

Description

       The MooseX::Aliases module will allow you to quickly alias methods in Moose. It provides an alias
       parameter for "has()" to generate aliased accessors as well as the standard ones. Attributes can also be
       initialized in the constructor via their aliased names.

       You can create more than one alias at once by passing a arrayref:

           has ip_addr => (
               alias => [ qw(ipAddr ip) ],
           );

Functions

aliasALIASMETHODNAME
       Installs ALIAS as a method that is aliased to the method METHODNAME.

Name

       MooseX::Aliases - easy aliasing of methods and attributes in Moose

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>

Synopsis

           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

           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';

Version

       version 0.11

See Also