1MooseX::Aliases(3)    User Contributed Perl Documentation   MooseX::Aliases(3)
2
3
4

NAME

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

VERSION

9       version 0.11
10

SYNOPSIS

12           package MyApp;
13           use Moose;
14           use MooseX::Aliases;
15
16           has this => (
17               isa   => 'Str',
18               is    => 'rw',
19               alias => 'that',
20           );
21
22           sub foo { my $self = shift; print $self->that }
23           alias bar => 'foo';
24
25           my $o = MyApp->new();
26           $o->this('Hello World');
27           $o->bar; # prints 'Hello World'
28
29       or
30
31           package MyApp::Role;
32           use Moose::Role;
33           use MooseX::Aliases;
34
35           has this => (
36               isa   => 'Str',
37               is    => 'rw',
38               alias => 'that',
39           );
40
41           sub foo { my $self = shift; print $self->that }
42           alias bar => 'foo';
43

DESCRIPTION

45       The MooseX::Aliases module will allow you to quickly alias methods in
46       Moose. It provides an alias parameter for "has()" to generate aliased
47       accessors as well as the standard ones. Attributes can also be
48       initialized in the constructor via their aliased names.
49
50       You can create more than one alias at once by passing a arrayref:
51
52           has ip_addr => (
53               alias => [ qw(ipAddr ip) ],
54           );
55

FUNCTIONS

57   alias ALIAS METHODNAME
58       Installs ALIAS as a method that is aliased to the method METHODNAME.
59

ALIASING VERSUS OTHER MOOSE FEATURES

61   Aliasing versus inheritance
62           {
63               package Parent;
64               use Moose;
65               use MooseX::Aliases;
66               sub method1 { "A" }
67               alias method2 => "method1";
68           }
69
70           {
71               package Child1;
72               use Moose;
73               extends "Parent";
74               sub method1 { "B" }
75           }
76
77           {
78               package Child2;
79               use Moose;
80               extends "Parent";
81               sub method2 { "C" }
82           }
83
84       In the example above, Child1 overrides the method using its original
85       name ("method1"). As a result, calling "method1" or "method2" returns
86       "B". Child2 overrides the method using its alias ("method2"). As a
87       result, calling "method2" returns "C", but calling "method1" falls
88       through to the parent class, so returns "A".
89
90   Aliasing versus method modifiers
91           {
92               package Class1;
93               use Moose;
94               use MooseX::Aliases;
95               sub method1 { "A" }
96               alias method2 => "method1";
97               around method1 => sub { "B" };
98           }
99
100           {
101               package Class2;
102               use Moose;
103               use MooseX::Aliases;
104               sub method1 { "A" }
105               alias method2 => "method1";
106               around method2 => sub { "B" };
107           }
108
109       In the example above, Class1's around modifier modifies the method
110       using its original name. As a result, both "method1" and "method2"
111       return "B". Class2's around modifier modifies the alias, so "method2"
112       returns "B", but "method1" continues to return "A".
113

BUGS

115       No known bugs.
116
117       Please report any bugs to GitHub Issues at
118       <https://github.com/doy/moosex-aliases/issues>.
119

SEE ALSO

121       Method::Alias
122

SUPPORT

124       You can find this documentation for this module with the perldoc
125       command.
126
127           perldoc MooseX::Aliases
128
129       You can also look for information at:
130
131       ·   MetaCPAN
132
133           <https://metacpan.org/release/MooseX-Aliases>
134
135       ·   Github
136
137           <https://github.com/doy/moosex-aliases>
138
139       ·   RT: CPAN's request tracker
140
141           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Aliases>
142
143       ·   CPAN Ratings
144
145           <http://cpanratings.perl.org/d/MooseX-Aliases>
146

AUTHORS

148       ·   Jesse Luehrs <doy@tozt.net>
149
150       ·   Chris Prather <chris@prather.org>
151
152       ·   Justin Hunter <justin.d.hunter@gmail.com>
153
155       This software is copyright (c) 2013 by Jesse Luehrs.
156
157       This is free software; you can redistribute it and/or modify it under
158       the same terms as the Perl 5 programming language system itself.
159
160
161
162perl v5.30.0                      2019-07-26                MooseX::Aliases(3)
Impressum