GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
MooseX::Aliases(3) User Contributed Perl Documentation MooseX::Aliases(3)

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

version 0.11

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

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) ],
    );

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

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

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

No known bugs.

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

Method::Alias

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>

  • 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.

2013-07-12 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.