++ed by:
PHAYLON TMUELLER

2 PAUSE user(s)
4 non-PAUSE user(s).

Jesse Luehrs

NAME

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

VERSION

version 0.11

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

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

alias ALIAS METHODNAME

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

ALIASING VERSUS OTHER MOOSE FEATURES

Aliasing versus inheritance

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

Aliasing versus method modifiers

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

BUGS

No known bugs.

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>

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.




Hosting generously
sponsored by Bytemark