/usr/share/perl5/MooX/Aliases.pm is in libmoox-aliases-perl 0.001006-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | package MooX::Aliases;
use strictures 1;
our $VERSION = '0.001006';
$VERSION = eval $VERSION;
use Carp;
use Class::Method::Modifiers qw(install_modifier);
sub import {
my ($class) = @_;
my $target = caller;
my $around = do { no strict 'refs'; \&{"${target}::around"} }
or croak "$target is not a Moo class or role";
my $make_alias = sub {
my ($from, $to) = @_;
if (!$target->can($to)) {
croak "Cannot find method $to to alias";
}
eval qq{
sub ${target}::${from} {
goto &{\$_[0]->can("$to")};
};
1;
} or die "$@";
};
{
no strict 'refs';
*{"${target}::alias"} = $make_alias;
}
my $installed_buildargs;
my %init_args;
install_modifier $target, 'around', 'has', sub {
my $orig = shift;
my ($attr, %opts) = @_;
my $aliases = delete $opts{alias};
$aliases = [ $aliases ]
if $aliases && !ref $aliases;
return $orig->($attr, %opts)
unless $aliases && @$aliases;
my $attr_name
= !ref $attr ? $attr
: @{$attr} == 1 ? $attr->[0]
: croak "Cannot make alias to list of attributes";
$attr_name =~ s/^\+//;
my $name = defined $opts{init_arg} ? $opts{init_arg} : $attr_name;
my @names = @$aliases;
if (!exists $opts{init_arg} || defined $opts{init_arg}) {
unshift @names, $name;
}
$init_args{$name} = \@names;
my $out = $orig->($attr, %opts);
for my $alias (@$aliases) {
$make_alias->($alias => $attr_name);
}
if (!$installed_buildargs) {
$installed_buildargs = 1;
$around->('BUILDARGS', sub {
my $orig = shift;
my $self = shift;
my $args = $self->$orig(@_);
for my $attr (keys %init_args) {
my @init = grep { exists $args->{$_} } (@{$init_args{$attr}});
if (@init > 1) {
croak "Conflicting init_args: (" . join(', ', @init) . ")";
}
elsif (@init == 1) {
$args->{$attr} = delete $args->{$init[0]};
}
}
return $args;
});
}
return $out;
};
}
1;
__END__
=head1 NAME
MooX::Aliases - easy aliasing of methods and attributes in Moo
=head1 SYNOPSIS
package MyClass;
use Moo;
use MooX::Aliases;
has this => (
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 MyRole;
use Moo::Role;
use MooX::Aliases;
has this => (
is => 'rw',
alias => 'that',
);
sub foo { my $self = shift; print $self->that }
alias bar => 'foo';
=head1 DESCRIPTION
The MooX::Aliases module will allow you to quickly alias methods
in Moo. 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 listref:
has ip_addr => (
alias => [ qw(ipAddr ip) ],
);
=head1 FUNCTIONS
=over 4
=item alias $alias, $method
Creates $alias as a method that is aliased to $method.
=back
=head1 CAVEATS
This module uses the C<BUILDARGS> to map the attributes. If a class uses a
custom C<BUILDARGS>, this module may not behave properly.
=head1 SEE ALSO
=over 4
=item L<MooseX::Aliases>
=back
=head1 AUTHOR
haarg - Graham Knop (cpan:HAARG) <haarg@haarg.org>
=head2 CONTRIBUTORS
=over 8
=item * Chris Prather <chris@prather.org>
=item * Jesse Luehrs <doy@tozt.net>
=item * Justin Hunter <justin.d.hunter@gmail.com>
=item * Karen Etheridge <ether@cpan.org>
=item * Yuval Kogman <nothingmuch@woobling.org>
=item * Daniel Gempesaw <gempesaw@gmail.com>
=item * Denis Ibaev <dionys@gmail.com>
=back
=head1 COPYRIGHT
Copyright (c) 2013 the MooX::Alises L</AUTHOR> and L</CONTRIBUTORS>
as listed above.
=head1 LICENSE
This library is free software and may be distributed under the same terms
as perl itself.
=cut
|