← Index
NYTProf Performance Profile   « block view • line view • sub view »
For reply.pl
  Run on Thu Oct 21 22:40:13 2010
Reported on Thu Oct 21 22:44:38 2010

Filename/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/Any/Moose.pm
StatementsExecuted 688 statements in 4.38ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
13111.78ms6.11msAny::Moose::::_install_moduleAny::Moose::_install_module
13139546µs8.37msAny::Moose::::importAny::Moose::import
1311349µs1.20msAny::Moose::::any_mooseAny::Moose::any_moose
1311302µs396µsAny::Moose::::_backer_ofAny::Moose::_backer_of
1311295µs1.50msAny::Moose::::_canonicalize_optionsAny::Moose::_canonicalize_options
1311266µs363µsAny::Moose::::_canonicalize_fragmentAny::Moose::_canonicalize_fragment
7871161µs161µsAny::Moose::::CORE:substAny::Moose::CORE:subst (opcode)
102237µs37µsAny::Moose::::moose_is_preferredAny::Moose::moose_is_preferred
102136µs36µsAny::Moose::::_is_moose_loadedAny::Moose::_is_moose_loaded
11132µs32µsAny::Moose::::BEGIN@7Any::Moose::BEGIN@7
91132µs32µsAny::Moose::::mouse_is_preferredAny::Moose::mouse_is_preferred
222132µs32µsAny::Moose::::CORE:matchAny::Moose::CORE:match (opcode)
11120µs20µsAny::Moose::::BEGIN@2Any::Moose::BEGIN@2
11114µs20µsAny::Moose::::BEGIN@8Any::Moose::BEGIN@8
11112µs36µsAny::Moose::::BEGIN@191Any::Moose::BEGIN@191
11111µs23µsAny::Moose::::BEGIN@9Any::Moose::BEGIN@9
11111µs40µsAny::Moose::::BEGIN@69Any::Moose::BEGIN@69
0000s0sAny::Moose::::is_moose_loadedAny::Moose::is_moose_loaded
0000s0sAny::Moose::::unimportAny::Moose::unimport
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Any::Moose;
2
# spent 20µs within Any::Moose::BEGIN@2 which was called: # once (20µs+0s) by Hailo::BEGIN@11 at line 4
BEGIN {
316µs $Any::Moose::VERSION = '0.13';
4121µs120µs}
# spent 20µs making 1 call to Any::Moose::BEGIN@2
5# ABSTRACT: use Moose or Mouse modules
6
7250µs132µs
# spent 32µs within Any::Moose::BEGIN@7 which was called: # once (32µs+0s) by Hailo::BEGIN@11 at line 7
use 5.006_002;
# spent 32µs making 1 call to Any::Moose::BEGIN@7
8227µs227µs
# spent 20µs (14+7) within Any::Moose::BEGIN@8 which was called: # once (14µs+7µs) by Hailo::BEGIN@11 at line 8
use strict;
# spent 20µs making 1 call to Any::Moose::BEGIN@8 # spent 7µs making 1 call to strict::import
92240µs235µs
# spent 23µs (11+12) within Any::Moose::BEGIN@9 which was called: # once (11µs+12µs) by Hailo::BEGIN@11 at line 9
use warnings;
# spent 23µs making 1 call to Any::Moose::BEGIN@9 # spent 12µs making 1 call to warnings::import
10
11# decide which backend to use
121900nsour $PREFERRED;
1312µsdo {
1411µs local $@;
1519µs14µs if ($ENV{ANY_MOOSE}) {
# spent 4µs making 1 call to Any::Moose::_is_moose_loaded
16 $PREFERRED = $ENV{'ANY_MOOSE'};
17 warn "ANY_MOOSE is not set to Moose or Mouse"
18 unless $PREFERRED eq 'Moose'
19 || $PREFERRED eq 'Mouse';
20
21 # if we die here, then perl gives "unknown error" which doesn't tell
22 # you what the problem is at all. argh.
23 if ($PREFERRED eq 'Moose' && !eval { require Moose }) {
24 warn "\$ANY_MOOSE is set to Moose but we cannot load it";
25 }
26 elsif ($PREFERRED eq 'Mouse' && !eval { require Mouse }) {
27 warn "\$ANY_MOOSE is set to Mouse but we cannot load it";
28 }
29 }
30 elsif (_is_moose_loaded()) {
31 $PREFERRED = 'Moose';
32 }
331108µs elsif (eval { require Mouse }) {
3412µs $PREFERRED = 'Mouse';
35 }
36 elsif (eval { require Moose }) {
37 $PREFERRED = 'Moose';
38 }
39 else {
40 require Carp;
41 warn "Unable to locate Mouse or Moose in INC";
42 }
43};
44
45
# spent 8.37ms (546µs+7.82) within Any::Moose::import which was called 13 times, avg 643µs/call: # once (45µs+1.68ms) by Hailo::Role::Arguments::BEGIN@10 at line 10 of Hailo/Role/Arguments.pm # once (59µs+848µs) by Hailo::Engine::Default::BEGIN@10 at line 10 of Hailo/Engine/Default.pm # once (35µs+724µs) by Hailo::BEGIN@12 at line 12 of Hailo.pm # once (45µs+680µs) by Hailo::BEGIN@11 at line 11 of Hailo.pm # once (46µs+625µs) by Hailo::Storage::SQLite::BEGIN@10 at line 10 of Hailo/Storage/SQLite.pm # once (41µs+594µs) by Hailo::Storage::BEGIN@10 at line 10 of Hailo/Storage.pm # once (43µs+581µs) by Hailo::Tokenizer::Words::BEGIN@11 at line 11 of Hailo/Tokenizer/Words.pm # once (44µs+401µs) by Hailo::Role::Engine::BEGIN@10 at line 10 of Hailo/Role/Engine.pm # once (44µs+392µs) by Hailo::Role::Tokenizer::BEGIN@10 at line 10 of Hailo/Role/Tokenizer.pm # once (40µs+347µs) by Hailo::Role::Storage::BEGIN@10 at line 10 of Hailo/Role/Storage.pm # once (37µs+339µs) by Hailo::Tokenizer::Words::BEGIN@12 at line 12 of Hailo/Tokenizer/Words.pm # once (34µs+308µs) by Hailo::Storage::BEGIN@11 at line 11 of Hailo/Storage.pm # once (34µs+302µs) by Hailo::Storage::SQLite::BEGIN@11 at line 11 of Hailo/Storage/SQLite.pm
sub import {
46130512µs my $self = shift;
47 my $pkg = caller;
48
49 # Any::Moose gives you strict and warnings
501364µs strict->import;
# spent 64µs making 13 calls to strict::import, avg 5µs/call
5113149µs warnings->import;
# spent 149µs making 13 calls to warnings::import, avg 11µs/call
52
53 # first options are for Mo*se
54 unshift @_, 'Moose' if !@_ || ref($_[0]);
55
56 while (my $module = shift) {
57 my $options = @_ && ref($_[0]) ? shift : [];
58
59131.50ms $options = $self->_canonicalize_options(
# spent 1.50ms making 13 calls to Any::Moose::_canonicalize_options, avg 115µs/call
60 module => $module,
61 options => $options,
62 package => $pkg,
63 );
64
65136.11ms $self->_install_module($options);
# spent 6.11ms making 13 calls to Any::Moose::_install_module, avg 470µs/call
66 }
67
68 # give them any_moose too
692561µs268µs
# spent 40µs (11+28) within Any::Moose::BEGIN@69 which was called: # once (11µs+28µs) by Hailo::BEGIN@11 at line 69
no strict 'refs';
# spent 40µs making 1 call to Any::Moose::BEGIN@69 # spent 28µs making 1 call to strict::unimport
70 *{$pkg.'::any_moose'} = \&any_moose;
71}
72
73sub unimport {
74 my $sel = shift;
75 my $pkg = caller;
76 my $module;
77
78 if(@_){
79 $module = any_moose(shift, $pkg);
80 }
81 else {
82 $module = _backer_of($pkg);
83 }
84 my $e = do{
85 local $@;
86 eval "package $pkg;\n"
87 . '$module->unimport();';
88 $@;
89 };
90
91 if ($e) {
92 require Carp;
93 Carp::croak("Cannot unimport Any::Moose: $e");
94 }
95
96 return;
97}
98
99
# spent 396µs (302+94) within Any::Moose::_backer_of which was called 13 times, avg 30µs/call: # 13 times (302µs+94µs) by Any::Moose::any_moose at line 169, avg 30µs/call
sub _backer_of {
10078292µs my $pkg = shift;
101
102 if(exists $INC{'Mouse.pm'}){
1031343µs my $meta = Mouse::Util::get_metaclass_by_name($pkg);
# spent 43µs making 13 calls to Mouse::Meta::Module::_get_metaclass_by_name, avg 3µs/call
104 if ($meta) {
105413µs return 'Mouse::Role' if $meta->isa('Mouse::Meta::Role');
# spent 13µs making 4 calls to UNIVERSAL::isa, avg 3µs/call
10646µs return 'Mouse' if $meta->isa('Mouse::Meta::Class');
# spent 6µs making 4 calls to UNIVERSAL::isa, avg 2µs/call
107 }
108 }
109
110932µs if (_is_moose_loaded()) {
# spent 32µs making 9 calls to Any::Moose::_is_moose_loaded, avg 4µs/call
111 my $meta = Class::MOP::get_metaclass_by_name($pkg);
112 if ($meta) {
113 return 'Moose::Role' if $meta->isa('Moose::Meta::Role');
114 return 'Moose' if $meta->isa('Moose::Meta::Class');
115 }
116 }
117
118 return undef;
119}
120
121
# spent 1.50ms (295µs+1.20) within Any::Moose::_canonicalize_options which was called 13 times, avg 115µs/call: # 13 times (295µs+1.20ms) by Any::Moose::import at line 59, avg 115µs/call
sub _canonicalize_options {
122104290µs my $self = shift;
123 my %args = @_;
124
125 my %options;
126 if (ref($args{options}) eq 'HASH') {
127 %options = %{ $args{options} };
128 }
129 else {
130 %options = (
131 imports => $args{options},
132 );
133 }
134
135 $options{package} = $args{package};
136131.20ms $options{module} = any_moose($args{module}, $args{package});
# spent 1.20ms making 13 calls to Any::Moose::any_moose, avg 93µs/call
137
138 return \%options;
139}
140
141
# spent 6.11ms (1.78+4.33) within Any::Moose::_install_module which was called 13 times, avg 470µs/call: # 13 times (1.78ms+4.33ms) by Any::Moose::import at line 65, avg 470µs/call
sub _install_module {
142143990µs my $self = shift;
143 my $options = shift;
144
145 my $module = $options->{module};
1461330µs (my $file = $module . '.pm') =~ s{::}{/}g;
# spent 30µs making 13 calls to Any::Moose::CORE:subst, avg 2µs/call
147
148 require $file;
149
150 my $e = do {
151 local $@;
152 eval "package $options->{package};\n"
# spent 20µs executing statements in 2 string evals (merged) # spent 18µs executing statements in 2 string evals (merged) # spent 17µs executing statements in 2 string evals (merged) # spent 16µs executing statements in 2 string evals (merged) # spent 15µs executing statements in string eval # spent 10µs executing statements in string eval # spent 10µs executing statements in string eval # spent 9µs executing statements in string eval # spent 8µs executing statements in string eval
153 . '$module->import(@{ $options->{imports} });';
154 $@;
155 };
156 if ($e) {
157 require Carp;
158 Carp::croak("Cannot import Any::Moose: $e");
159 }
160 return;
161}
162
163
# spent 1.20ms (349µs+856µs) within Any::Moose::any_moose which was called 13 times, avg 93µs/call: # 13 times (349µs+856µs) by Any::Moose::_canonicalize_options at line 136, avg 93µs/call
sub any_moose {
16487406µs13363µs my $fragment = _canonicalize_fragment(shift);
# spent 363µs making 13 calls to Any::Moose::_canonicalize_fragment, avg 28µs/call
165 my $package = shift || caller;
166
167 # Mouse gets first dibs because it doesn't introspect existing classes
168
16913396µs my $backer = _backer_of($package) || '';
# spent 396µs making 13 calls to Any::Moose::_backer_of, avg 30µs/call
170
1711322µs if ($backer =~ /^Mouse/) {
# spent 22µs making 13 calls to Any::Moose::CORE:match, avg 2µs/call
17247µs $fragment =~ s/^Moose/Mouse/;
# spent 7µs making 4 calls to Any::Moose::CORE:subst, avg 2µs/call
173 return $fragment;
174 }
175
176910µs return $fragment if $backer =~ /^Moose/;
# spent 10µs making 9 calls to Any::Moose::CORE:match, avg 1µs/call
177
1781859µs $fragment =~ s/^Moose/Mouse/ if mouse_is_preferred();
# spent 32µs making 9 calls to Any::Moose::mouse_is_preferred, avg 4µs/call # spent 26µs making 9 calls to Any::Moose::CORE:subst, avg 3µs/call
179 return $fragment;
180}
181
18214µsfor my $name (qw/
183 load_class
184 is_class_loaded
185 class_of
186 get_metaclass_by_name
187 get_all_metaclass_instances
188 get_all_metaclass_names
189 load_first_existing_class
190 /) {
1912269µs260µs
# spent 36µs (12+24) within Any::Moose::BEGIN@191 which was called: # once (12µs+24µs) by Hailo::BEGIN@11 at line 191
no strict 'refs';
# spent 36µs making 1 call to Any::Moose::BEGIN@191 # spent 24µs making 1 call to strict::unimport
192 *{__PACKAGE__."::$name"} = moose_is_preferred()
193 ? *{"Class::MOP::$name"}
194761µs722µs : *{"Mouse::Util::$name"};
# spent 22µs making 7 calls to Any::Moose::moose_is_preferred, avg 3µs/call
195}
196
1971045µs
# spent 37µs within Any::Moose::moose_is_preferred which was called 10 times, avg 4µs/call: # 7 times (22µs+0s) by Hailo::BEGIN@11 at line 194, avg 3µs/call # 3 times (15µs+0s) by Hailo::_new_class at line 199 of Hailo.pm, avg 5µs/call
sub moose_is_preferred { $PREFERRED eq 'Moose' }
198938µs
# spent 32µs within Any::Moose::mouse_is_preferred which was called 9 times, avg 4µs/call: # 9 times (32µs+0s) by Any::Moose::any_moose at line 178, avg 4µs/call
sub mouse_is_preferred { $PREFERRED eq 'Mouse' }
199
2001048µs
# spent 36µs within Any::Moose::_is_moose_loaded which was called 10 times, avg 4µs/call: # 9 times (32µs+0s) by Any::Moose::_backer_of at line 110, avg 4µs/call # once (4µs+0s) by Hailo::BEGIN@11 at line 15
sub _is_moose_loaded { exists $INC{'Moose.pm'} }
201
202sub is_moose_loaded {
203 require Carp;
204 Carp::carp("Any::Moose::is_moose_loaded is deprecated. Please use Any::Moose::moose_is_preferred instead");
205 goto \&_is_moose_loaded;
206}
207
208
# spent 363µs (266+97) within Any::Moose::_canonicalize_fragment which was called 13 times, avg 28µs/call: # 13 times (266µs+97µs) by Any::Moose::any_moose at line 164, avg 28µs/call
sub _canonicalize_fragment {
20991377µs my $fragment = shift;
210
211 return 'Moose' if !$fragment;
212
213 # any_moose("X::Types") -> any_moose("MooseX::Types")
2141329µs $fragment =~ s/^X::/MooseX::/;
# spent 29µs making 13 calls to Any::Moose::CORE:subst, avg 2µs/call
215
216 # any_moose("::Util") -> any_moose("Moose::Util")
2171323µs $fragment =~ s/^::/Moose::/;
# spent 23µs making 13 calls to Any::Moose::CORE:subst, avg 2µs/call
218
219 # any_moose("Mouse::Util") -> any_moose("Moose::Util")
2201317µs $fragment =~ s/^Mouse(X?)\b/Moose$1/;
# spent 17µs making 13 calls to Any::Moose::CORE:subst, avg 1µs/call
221
222 # any_moose("Util") -> any_moose("Moose::Util")
2231329µs $fragment =~ s/^(?!Moose)/Moose::/;
# spent 29µs making 13 calls to Any::Moose::CORE:subst, avg 2µs/call
224
225 return $fragment;
226}
227
228119µs1;
229
230
231=pod
232
233=head1 NAME
234
235Any::Moose - use Moose or Mouse modules
236
237=head1 VERSION
238
239version 0.13
240
241=head1 SYNOPSIS
242
243
244=head2 BASIC
245
246
247 package Class;
248
249 # uses Moose if it's loaded or demanded, Mouse otherwise
250 use Any::Moose;
251
252 # cleans the namespace up
253 no Any::Moose;
254
255=head2 OTHER MODULES
256
257
258 package Other::Class;
259 use Any::Moose;
260
261 # uses Moose::Util::TypeConstraints if the class has loaded Moose,
262 # Mouse::Util::TypeConstraints otherwise.
263 use Any::Moose '::Util::TypeConstraints';
264
265=head2 ROLES
266
267
268 package My::Sorter;
269 use Any::Moose 'Role';
270
271 requires 'cmp';
272
273=head2 COMPLEX USAGE
274
275
276 package My::Meta::Class;
277 use Any::Moose;
278
279 # uses subtype from Moose::Util::TypeConstraints if the class loaded Moose,
280 # subtype from Mouse::Util::TypeConstraints otherwise.
281 # similarly for Mo*se::Util's does_role
282 use Any::Moose (
283 '::Util::TypeConstraints' => ['subtype'],
284 '::Util' => ['does_role'],
285 );
286
287 # uses MouseX::Types or MooseX::Types
288 use Any::Moose 'X::Types';
289
290 # gives you the right class name depending on which Mo*se was loaded
291 extends any_moose('::Meta::Class');
292
293=head1 DESCRIPTION
294
295
296Though we recommend that people generally use L<Moose>, we accept that Moose
297cannot yet be used for everything everywhere. People generally like the Moose
298sugar, so many people use L<Mouse>, a lightweight replacement for parts of
299Moose.
300
301
302Because Mouse strives for compatibility with Moose, it's easy to substitute one
303for the other. This module facilitates that substitution. By default, Mouse
304will be provided to libraries, unless Moose is already loaded -or-
305explicitly requested by the end-user. The end-user can force the decision
306of which backend to use by setting the environment variable C<ANY_MOOSE> to
307be C<Moose> or C<Mouse>.
308
309
310Note that the decision of which backend to use is made only once, so that if
311Any-Moose picks Mouse, then a third-party library loads Moose, anything else
312that uses Any-Moose will continue to pick Mouse.
313
314
315So, if you have to use L<Mouse>, please be considerate to the Moose fanboys
316(like myself!) and use L<Any-Moose> instead. C<:)>
317
318=head1 SEE ALSO
319
320
321L<Moose>
322
323
324L<Mouse>
325
326
327L<Squirrel> - a deprecated first-stab at Any-Moose-like logic. Its biggest
328fault was in making the decision of which backend to use every time it was
329used, rather than just once.
330
331=head1 AUTHORS
332
333 Shawn M Moore <sartak@bestpractical.com>
334 Florian Ragwitz <rafl@debian.org>
335 Stevan Little <stevan@iinteractive.com>
336 Tokuhiro Matsuno <tokuhirom@gmail.com>
337 Goro Fuji <gfuji@cpan.org>
338
339=head1 COPYRIGHT AND LICENSE
340
341This software is copyright (c) 2010 by Best Practical Solutions.
342
343This is free software; you can redistribute it and/or modify it under
344the same terms as the Perl 5 programming language system itself.
345
346=cut
347
348
349__END__
 
# spent 32µs within Any::Moose::CORE:match which was called 22 times, avg 1µs/call: # 13 times (22µs+0s) by Any::Moose::any_moose at line 171, avg 2µs/call # 9 times (10µs+0s) by Any::Moose::any_moose at line 176, avg 1µs/call
sub Any::Moose::CORE:match; # opcode
# spent 161µs within Any::Moose::CORE:subst which was called 78 times, avg 2µs/call: # 13 times (30µs+0s) by Any::Moose::_install_module at line 146, avg 2µs/call # 13 times (29µs+0s) by Any::Moose::_canonicalize_fragment at line 214, avg 2µs/call # 13 times (29µs+0s) by Any::Moose::_canonicalize_fragment at line 223, avg 2µs/call # 13 times (23µs+0s) by Any::Moose::_canonicalize_fragment at line 217, avg 2µs/call # 13 times (17µs+0s) by Any::Moose::_canonicalize_fragment at line 220, avg 1µs/call # 9 times (26µs+0s) by Any::Moose::any_moose at line 178, avg 3µs/call # 4 times (7µs+0s) by Any::Moose::any_moose at line 172, avg 2µs/call
sub Any::Moose::CORE:subst; # opcode