/usr/share/perl5/Any/Moose.pm is in libany-moose-perl 0.17-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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | package Any::Moose;
{
$Any::Moose::VERSION = '0.17';
}
# ABSTRACT: use Moose or Mouse modules
use 5.006_002;
use strict;
use warnings;
# decide which backend to use
our $PREFERRED;
do {
local $@;
if ($ENV{ANY_MOOSE}) {
$PREFERRED = $ENV{'ANY_MOOSE'};
warn "ANY_MOOSE is not set to Moose or Mouse"
unless $PREFERRED eq 'Moose'
|| $PREFERRED eq 'Mouse';
# if we die here, then perl gives "unknown error" which doesn't tell
# you what the problem is at all. argh.
if ($PREFERRED eq 'Moose' && !eval { require Moose }) {
warn "\$ANY_MOOSE is set to Moose but we cannot load it";
}
elsif ($PREFERRED eq 'Mouse' && !eval { require Mouse }) {
warn "\$ANY_MOOSE is set to Mouse but we cannot load it";
}
}
elsif (_is_moose_loaded()) {
$PREFERRED = 'Moose';
}
elsif (eval { require Mouse }) {
$PREFERRED = 'Mouse';
}
elsif (eval { require Moose }) {
$PREFERRED = 'Moose';
}
else {
require Carp;
warn "Unable to locate Mouse or Moose in INC";
}
};
sub import {
my $self = shift;
my $pkg = caller;
# Any::Moose gives you strict and warnings
strict->import;
warnings->import;
# first options are for Mo*se
unshift @_, 'Moose' if !@_ || ref($_[0]);
while (my $module = shift) {
my $options = @_ && ref($_[0]) ? shift : [];
$options = $self->_canonicalize_options(
module => $module,
options => $options,
package => $pkg,
);
$self->_install_module($options);
}
# give them any_moose too
no strict 'refs';
*{$pkg.'::any_moose'} = \&any_moose;
}
sub unimport {
my $sel = shift;
my $pkg = caller;
my $module;
if(@_){
$module = any_moose(shift, $pkg);
}
else {
$module = _backer_of($pkg);
}
my $e = do{
local $@;
eval "package $pkg;\n"
. '$module->unimport();';
$@;
};
if ($e) {
require Carp;
Carp::croak("Cannot unimport Any::Moose: $e");
}
return;
}
sub _backer_of {
my $pkg = shift;
if(exists $INC{'Mouse.pm'}){
my $meta = Mouse::Util::get_metaclass_by_name($pkg);
if ($meta) {
return 'Mouse::Role' if $meta->isa('Mouse::Meta::Role');
return 'Mouse' if $meta->isa('Mouse::Meta::Class');
}
}
if (_is_moose_loaded()) {
my $meta = Class::MOP::get_metaclass_by_name($pkg);
if ($meta) {
return 'Moose::Role' if $meta->isa('Moose::Meta::Role');
return 'Moose' if $meta->isa('Moose::Meta::Class');
}
}
return undef;
}
sub _canonicalize_options {
my $self = shift;
my %args = @_;
my %options;
if (ref($args{options}) eq 'HASH') {
%options = %{ $args{options} };
}
else {
%options = (
imports => $args{options},
);
}
$options{package} = $args{package};
$options{module} = any_moose($args{module}, $args{package});
return \%options;
}
sub _install_module {
my $self = shift;
my $options = shift;
my $module = $options->{module};
(my $file = $module . '.pm') =~ s{::}{/}g;
require $file;
my $e = do {
local $@;
eval "package $options->{package};\n"
. '$module->import(@{ $options->{imports} });';
$@;
};
if ($e) {
require Carp;
Carp::croak("Cannot import Any::Moose: $e");
}
return;
}
sub any_moose {
my $fragment = _canonicalize_fragment(shift);
my $package = shift || caller;
# Mouse gets first dibs because it doesn't introspect existing classes
my $backer = _backer_of($package) || '';
if ($backer =~ /^Mouse/) {
$fragment =~ s/^Moose/Mouse/;
return $fragment;
}
return $fragment if $backer =~ /^Moose/;
$fragment =~ s/^Moose/Mouse/ if mouse_is_preferred();
return $fragment;
}
for my $name (qw/
load_class
is_class_loaded
class_of
get_metaclass_by_name
get_all_metaclass_instances
get_all_metaclass_names
load_first_existing_class
/) {
no strict 'refs';
*{__PACKAGE__."::$name"} = moose_is_preferred()
? *{"Class::MOP::$name"}
: *{"Mouse::Util::$name"};
}
sub moose_is_preferred { $PREFERRED eq 'Moose' }
sub mouse_is_preferred { $PREFERRED eq 'Mouse' }
sub _is_moose_loaded { exists $INC{'Moose.pm'} }
sub is_moose_loaded {
require Carp;
Carp::carp("Any::Moose::is_moose_loaded is deprecated. Please use Any::Moose::moose_is_preferred instead");
goto \&_is_moose_loaded;
}
sub _canonicalize_fragment {
my $fragment = shift;
return 'Moose' if !$fragment;
# any_moose("X::Types") -> any_moose("MooseX::Types")
$fragment =~ s/^X::/MooseX::/;
# any_moose("::Util") -> any_moose("Moose::Util")
$fragment =~ s/^::/Moose::/;
# any_moose("Mouse::Util") -> any_moose("Moose::Util")
$fragment =~ s/^Mouse(X?)\b/Moose$1/;
# any_moose("Util") -> any_moose("Moose::Util")
$fragment =~ s/^(?!Moose)/Moose::/;
return $fragment;
}
1;
=pod
=head1 NAME
Any::Moose - use Moose or Mouse modules
=head1 VERSION
version 0.17
=head1 SYNOPSIS
=head2 BASIC
package Class;
# uses Moose if it's loaded or demanded, Mouse otherwise
use Any::Moose;
# cleans the namespace up
no Any::Moose;
=head2 OTHER MODULES
package Other::Class;
use Any::Moose;
# uses Moose::Util::TypeConstraints if the class has loaded Moose,
# Mouse::Util::TypeConstraints otherwise.
use Any::Moose '::Util::TypeConstraints';
=head2 ROLES
package My::Sorter;
use Any::Moose 'Role';
requires 'cmp';
=head2 COMPLEX USAGE
package My::Meta::Class;
use Any::Moose;
# uses subtype from Moose::Util::TypeConstraints if the class loaded Moose,
# subtype from Mouse::Util::TypeConstraints otherwise.
# similarly for Mo*se::Util's does_role
use Any::Moose (
'::Util::TypeConstraints' => ['subtype'],
'::Util' => ['does_role'],
);
# uses MouseX::Types or MooseX::Types
use Any::Moose 'X::Types';
# gives you the right class name depending on which Mo*se was loaded
extends any_moose('::Meta::Class');
=head1 DESCRIPTION
Though we recommend that people generally use L<Moose>, we accept that Moose
cannot yet be used for everything everywhere. People generally like the Moose
sugar, so many people use L<Mouse>, a lightweight replacement for parts of
Moose.
Because Mouse strives for compatibility with Moose, it's easy to substitute one
for the other. This module facilitates that substitution. By default, Mouse
will be provided to libraries, unless Moose is already loaded -or-
explicitly requested by the end-user. The end-user can force the decision
of which backend to use by setting the environment variable C<ANY_MOOSE> to
be C<Moose> or C<Mouse>.
Note that the decision of which backend to use is made only once, so that if
Any-Moose picks Mouse, then a third-party library loads Moose, anything else
that uses Any-Moose will continue to pick Mouse.
So, if you have to use L<Mouse>, please be considerate to the Moose fanboys
(like myself!) and use L<Any-Moose> instead. C<:)>
=head1 SEE ALSO
L<Moose>
L<Mouse>
L<Squirrel> - a deprecated first-stab at Any-Moose-like logic. Its biggest
fault was in making the decision of which backend to use every time it was
used, rather than just once.
=head1 AUTHORS
=over 4
=item *
Shawn M Moore <sartak@bestpractical.com>
=item *
Florian Ragwitz <rafl@debian.org>
=item *
Stevan Little <stevan@iinteractive.com>
=item *
Tokuhiro Matsuno <tokuhirom@gmail.com>
=item *
Goro Fuji <gfuji@cpan.org>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Best Practical Solutions.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
__END__
|