-
-
12 Jul 2013 19:04:25 UTC
- Distribution: MooseX-Aliases
- Module version: 0.11
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (2)
- Testers (8786 / 31 / 0)
- Kwalitee
Bus factor: 0- % Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (17.32KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 7 contributors-
Jesse Luehrs
-
Chris Prather
-
Justin Hunter
-
Dave Rolsky
-
Karen Etheridge
-
Toby Inkster
-
Yuval Kogman
- NAME
- VERSION
- SYNOPSIS
- DESCRIPTION
- FUNCTIONS
- ALIASING VERSUS OTHER MOOSE FEATURES
- BUGS
- SEE ALSO
- SUPPORT
- AUTHORS
- COPYRIGHT AND LICENSE
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, callingmethod1
ormethod2
returns "B". Child2 overrides the method using its alias (method2
). As a result, callingmethod2
returns "C", but callingmethod1
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
andmethod2
return "B". Class2's around modifier modifies the alias, somethod2
returns "B", butmethod1
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
SUPPORT
You can find this documentation for this module with the perldoc command.
perldoc MooseX::Aliases
You can also look for information at:
MetaCPAN
Github
RT: CPAN's request tracker
CPAN Ratings
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.
Module Install Instructions
To install MooseX::Aliases, copy and paste the appropriate command in to your terminal.
cpanm MooseX::Aliases
perl -MCPAN -e shell install MooseX::Aliases
For more information on module installation, please visit the detailed CPAN module installation guide.