| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Any::Moose; # git description: v0.24-4-gb034fd7 |
|
2
|
|
|
|
|
|
|
# ABSTRACT: (DEPRECATED) use Moo instead! |
|
3
|
|
|
|
|
|
|
# KEYWORDS: deprecated Moose Mouse abstraction layer object-oriented |
|
4
|
|
|
|
|
|
|
$Any::Moose::VERSION = '0.25'; |
|
5
|
11
|
|
|
11
|
|
288248
|
use 5.006_002; |
|
|
11
|
|
|
|
|
36
|
|
|
|
11
|
|
|
|
|
385
|
|
|
6
|
11
|
|
|
11
|
|
47
|
use strict; |
|
|
11
|
|
|
|
|
11
|
|
|
|
11
|
|
|
|
|
354
|
|
|
7
|
11
|
|
|
11
|
|
40
|
use warnings; |
|
|
11
|
|
|
|
|
17
|
|
|
|
11
|
|
|
|
|
3129
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# decide which backend to use |
|
10
|
|
|
|
|
|
|
our $PREFERRED; |
|
11
|
|
|
|
|
|
|
do { |
|
12
|
|
|
|
|
|
|
local $@; |
|
13
|
|
|
|
|
|
|
if ($ENV{ANY_MOOSE}) { |
|
14
|
|
|
|
|
|
|
$PREFERRED = $ENV{'ANY_MOOSE'}; |
|
15
|
|
|
|
|
|
|
warn "ANY_MOOSE is not set to Moose or Mouse" |
|
16
|
|
|
|
|
|
|
unless $PREFERRED eq 'Moose' |
|
17
|
|
|
|
|
|
|
|| $PREFERRED eq 'Mouse'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# if we die here, then perl gives "unknown error" which doesn't tell |
|
20
|
|
|
|
|
|
|
# you what the problem is at all. argh. |
|
21
|
|
|
|
|
|
|
if ($PREFERRED eq 'Moose' && !eval { require Moose }) { |
|
22
|
|
|
|
|
|
|
warn "\$ANY_MOOSE is set to Moose but we cannot load it"; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
elsif ($PREFERRED eq 'Mouse' && !eval { require Mouse }) { |
|
25
|
|
|
|
|
|
|
warn "\$ANY_MOOSE is set to Mouse but we cannot load it"; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
elsif ( $INC{'Moo.pm'} && eval { require Moose } ) { |
|
29
|
|
|
|
|
|
|
$PREFERRED = 'Moose'; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
elsif (_is_moose_loaded()) { |
|
32
|
|
|
|
|
|
|
$PREFERRED = 'Moose'; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
elsif (eval { require Mouse; Mouse->VERSION('0.3701'); 1 }) { |
|
35
|
|
|
|
|
|
|
$PREFERRED = 'Mouse'; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
elsif (eval { require Moose }) { |
|
38
|
|
|
|
|
|
|
$PREFERRED = 'Moose'; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
else { |
|
41
|
|
|
|
|
|
|
require Carp; |
|
42
|
|
|
|
|
|
|
warn "Unable to locate Mouse or Moose in INC"; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
}; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub import { |
|
47
|
16
|
|
|
16
|
|
2441
|
my $self = shift; |
|
48
|
16
|
|
|
|
|
73
|
my $pkg = caller; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Any::Moose gives you strict and warnings |
|
51
|
16
|
|
|
|
|
208
|
strict->import; |
|
52
|
16
|
|
|
|
|
176
|
warnings->import; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# first options are for Mo*se |
|
55
|
16
|
100
|
66
|
|
|
101
|
unshift @_, 'Moose' if !@_ || ref($_[0]); |
|
56
|
|
|
|
|
|
|
|
|
57
|
16
|
|
|
|
|
54
|
while (my $module = shift) { |
|
58
|
16
|
100
|
66
|
|
|
74
|
my $options = @_ && ref($_[0]) ? shift : []; |
|
59
|
|
|
|
|
|
|
|
|
60
|
16
|
|
|
|
|
52
|
$options = $self->_canonicalize_options( |
|
61
|
|
|
|
|
|
|
module => $module, |
|
62
|
|
|
|
|
|
|
options => $options, |
|
63
|
|
|
|
|
|
|
package => $pkg, |
|
64
|
|
|
|
|
|
|
); |
|
65
|
|
|
|
|
|
|
|
|
66
|
16
|
|
|
|
|
39
|
$self->_install_module($options); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# give them any_moose too |
|
70
|
11
|
|
|
11
|
|
49
|
no strict 'refs'; |
|
|
11
|
|
|
|
|
14
|
|
|
|
11
|
|
|
|
|
6625
|
|
|
71
|
16
|
|
|
|
|
24
|
*{$pkg.'::any_moose'} = \&any_moose; |
|
|
16
|
|
|
|
|
8734
|
|
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub unimport { |
|
75
|
4
|
|
|
4
|
|
492
|
my $sel = shift; |
|
76
|
4
|
|
|
|
|
6
|
my $pkg = caller; |
|
77
|
4
|
|
|
|
|
6
|
my $module; |
|
78
|
|
|
|
|
|
|
|
|
79
|
4
|
100
|
|
|
|
12
|
if(@_){ |
|
80
|
1
|
|
|
|
|
2
|
$module = any_moose(shift, $pkg); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
else { |
|
83
|
3
|
|
|
|
|
8
|
$module = _backer_of($pkg); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
4
|
|
|
|
|
13
|
my $e = do{ |
|
86
|
4
|
|
|
|
|
4
|
local $@; |
|
87
|
4
|
|
|
|
|
210
|
eval "package $pkg;\n" |
|
88
|
|
|
|
|
|
|
. '$module->unimport();'; |
|
89
|
4
|
|
|
|
|
262
|
$@; |
|
90
|
|
|
|
|
|
|
}; |
|
91
|
|
|
|
|
|
|
|
|
92
|
4
|
50
|
|
|
|
12
|
if ($e) { |
|
93
|
0
|
|
|
|
|
0
|
require Carp; |
|
94
|
0
|
|
|
|
|
0
|
Carp::croak("Cannot unimport Any::Moose: $e"); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
4
|
|
|
|
|
2682
|
return; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _backer_of { |
|
101
|
24
|
|
|
24
|
|
29
|
my $pkg = shift; |
|
102
|
|
|
|
|
|
|
|
|
103
|
24
|
50
|
33
|
|
|
231
|
if(exists $INC{'Mouse.pm'} |
|
104
|
|
|
|
|
|
|
and Mouse::Util->can('get_metaclass_by_name') |
|
105
|
|
|
|
|
|
|
){ |
|
106
|
24
|
|
|
|
|
93
|
my $meta = Mouse::Util::get_metaclass_by_name($pkg); |
|
107
|
24
|
100
|
|
|
|
100
|
if ($meta) { |
|
108
|
9
|
50
|
|
|
|
62
|
return 'Mouse::Role' if $meta->isa('Mouse::Meta::Role'); |
|
109
|
9
|
50
|
|
|
|
39
|
return 'Mouse' if $meta->isa('Mouse::Meta::Class'); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
15
|
50
|
|
|
|
35
|
if (_is_moose_loaded()) { |
|
114
|
0
|
|
|
|
|
0
|
my $meta = Class::MOP::get_metaclass_by_name($pkg); |
|
115
|
0
|
0
|
|
|
|
0
|
if ($meta) { |
|
116
|
0
|
0
|
|
|
|
0
|
return 'Moose::Role' if $meta->isa('Moose::Meta::Role'); |
|
117
|
0
|
0
|
|
|
|
0
|
return 'Moose' if $meta->isa('Moose::Meta::Class'); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
15
|
|
|
|
|
105
|
return undef; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _canonicalize_options { |
|
125
|
16
|
|
|
16
|
|
21
|
my $self = shift; |
|
126
|
16
|
|
|
|
|
53
|
my %args = @_; |
|
127
|
|
|
|
|
|
|
|
|
128
|
16
|
|
|
|
|
22
|
my %options; |
|
129
|
16
|
50
|
|
|
|
62
|
if (ref($args{options}) eq 'HASH') { |
|
130
|
0
|
|
|
|
|
0
|
%options = %{ $args{options} }; |
|
|
0
|
|
|
|
|
0
|
|
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
else { |
|
133
|
16
|
|
|
|
|
40
|
%options = ( |
|
134
|
|
|
|
|
|
|
imports => $args{options}, |
|
135
|
|
|
|
|
|
|
); |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
16
|
|
|
|
|
28
|
$options{package} = $args{package}; |
|
139
|
16
|
|
|
|
|
35
|
$options{module} = any_moose($args{module}, $args{package}); |
|
140
|
|
|
|
|
|
|
|
|
141
|
16
|
|
|
|
|
47
|
return \%options; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub _install_module { |
|
145
|
16
|
|
|
16
|
|
18
|
my $self = shift; |
|
146
|
16
|
|
|
|
|
17
|
my $options = shift; |
|
147
|
|
|
|
|
|
|
|
|
148
|
16
|
|
|
|
|
24
|
my $module = $options->{module}; |
|
149
|
16
|
|
|
|
|
39
|
(my $file = $module . '.pm') =~ s{::}{/}g; |
|
150
|
|
|
|
|
|
|
|
|
151
|
16
|
|
|
|
|
463
|
require $file; |
|
152
|
|
|
|
|
|
|
|
|
153
|
16
|
|
|
|
|
755
|
my $e = do { |
|
154
|
16
|
|
|
|
|
18
|
local $@; |
|
155
|
16
|
|
|
|
|
1029
|
eval "package $options->{package};\n" |
|
156
|
|
|
|
|
|
|
. '$module->import(@{ $options->{imports} });'; |
|
157
|
16
|
|
|
|
|
3376
|
$@; |
|
158
|
|
|
|
|
|
|
}; |
|
159
|
16
|
50
|
|
|
|
48
|
if ($e) { |
|
160
|
0
|
|
|
|
|
0
|
require Carp; |
|
161
|
0
|
|
|
|
|
0
|
Carp::croak("Cannot import Any::Moose: $e"); |
|
162
|
|
|
|
|
|
|
} |
|
163
|
16
|
|
|
|
|
94
|
return; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub any_moose { |
|
167
|
21
|
|
|
21
|
0
|
1247
|
my $fragment = _canonicalize_fragment(shift); |
|
168
|
21
|
|
66
|
|
|
64
|
my $package = shift || caller; |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# Mouse gets first dibs because it doesn't introspect existing classes |
|
171
|
|
|
|
|
|
|
|
|
172
|
21
|
|
100
|
|
|
44
|
my $backer = _backer_of($package) || ''; |
|
173
|
|
|
|
|
|
|
|
|
174
|
21
|
100
|
|
|
|
62
|
if ($backer =~ /^Mouse/) { |
|
175
|
6
|
|
|
|
|
18
|
$fragment =~ s/^Moose/Mouse/; |
|
176
|
6
|
|
|
|
|
19
|
return $fragment; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
15
|
50
|
|
|
|
33
|
return $fragment if $backer =~ /^Moose/; |
|
180
|
|
|
|
|
|
|
|
|
181
|
15
|
50
|
|
|
|
33
|
$fragment =~ s/^Moose/Mouse/ if mouse_is_preferred(); |
|
182
|
15
|
|
|
|
|
36
|
return $fragment; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
for my $name (qw/ |
|
186
|
|
|
|
|
|
|
load_class |
|
187
|
|
|
|
|
|
|
is_class_loaded |
|
188
|
|
|
|
|
|
|
class_of |
|
189
|
|
|
|
|
|
|
get_metaclass_by_name |
|
190
|
|
|
|
|
|
|
get_all_metaclass_instances |
|
191
|
|
|
|
|
|
|
get_all_metaclass_names |
|
192
|
|
|
|
|
|
|
load_first_existing_class |
|
193
|
|
|
|
|
|
|
/) { |
|
194
|
11
|
|
|
11
|
|
68
|
no strict 'refs'; |
|
|
11
|
|
|
|
|
16
|
|
|
|
11
|
|
|
|
|
2836
|
|
|
195
|
|
|
|
|
|
|
*{__PACKAGE__."::$name"} = moose_is_preferred() |
|
196
|
|
|
|
|
|
|
? *{"Class::MOP::$name"} |
|
197
|
|
|
|
|
|
|
: *{"Mouse::Util::$name"}; |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
|
|
200
|
77
|
|
|
77
|
0
|
203
|
sub moose_is_preferred { $PREFERRED eq 'Moose' } |
|
201
|
15
|
|
|
15
|
0
|
76
|
sub mouse_is_preferred { $PREFERRED eq 'Mouse' } |
|
202
|
|
|
|
|
|
|
|
|
203
|
27
|
|
|
27
|
|
2343
|
sub _is_moose_loaded { exists $INC{'Moose.pm'} } |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub is_moose_loaded { |
|
206
|
0
|
|
|
0
|
0
|
0
|
require Carp; |
|
207
|
0
|
|
|
|
|
0
|
Carp::carp("Any::Moose::is_moose_loaded is deprecated. Please use Any::Moose::moose_is_preferred instead"); |
|
208
|
0
|
|
|
|
|
0
|
goto \&_is_moose_loaded; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub _canonicalize_fragment { |
|
212
|
34
|
|
|
34
|
|
5573
|
my $fragment = shift; |
|
213
|
|
|
|
|
|
|
|
|
214
|
34
|
100
|
|
|
|
86
|
return 'Moose' if !$fragment; |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# any_moose("X::Types") -> any_moose("MooseX::Types") |
|
217
|
30
|
|
|
|
|
62
|
$fragment =~ s/^X::/MooseX::/; |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
# any_moose("::Util") -> any_moose("Moose::Util") |
|
220
|
30
|
|
|
|
|
67
|
$fragment =~ s/^::/Moose::/; |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
# any_moose("Mouse::Util") -> any_moose("Moose::Util") |
|
223
|
30
|
|
|
|
|
62
|
$fragment =~ s/^Mouse(X?)\b/Moose$1/; |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# any_moose("Util") -> any_moose("Moose::Util") |
|
226
|
30
|
|
|
|
|
71
|
$fragment =~ s/^(?!Moose)/Moose::/; |
|
227
|
|
|
|
|
|
|
|
|
228
|
30
|
|
|
|
|
52
|
return $fragment; |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
1; |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
__END__ |