← Index
NYTProf Performance Profile   « block view • line view • sub view »
For xt/tapper-mcp-scheduler-with-db-longrun.t
  Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:35 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/Any/Moose.pm
StatementsExecuted 90 statements in 1.25ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111979µs7.03msAny::Moose::::_install_moduleAny::Moose::_install_module
11130µs34µsAny::Moose::::_backer_ofAny::Moose::_backer_of
11130µs7.15msAny::Moose::::importAny::Moose::import
11118µs18µsAny::Moose::::BEGIN@7Any::Moose::BEGIN@7
11116µs73µsAny::Moose::::any_mooseAny::Moose::any_moose
11116µs21µsAny::Moose::::_canonicalize_fragmentAny::Moose::_canonicalize_fragment
11111µs84µsAny::Moose::::_canonicalize_optionsAny::Moose::_canonicalize_options
1119µs25µsAny::Moose::::BEGIN@9Any::Moose::BEGIN@9
1117µs12µsAny::Moose::::BEGIN@8Any::Moose::BEGIN@8
5517µs7µsAny::Moose::::CORE:substAny::Moose::CORE:subst (opcode)
1117µs22µsAny::Moose::::BEGIN@69Any::Moose::BEGIN@69
1117µs15µsAny::Moose::::BEGIN@191Any::Moose::BEGIN@191
7116µs6µsAny::Moose::::moose_is_preferredAny::Moose::moose_is_preferred
2213µs3µsAny::Moose::::_is_moose_loadedAny::Moose::_is_moose_loaded
1111µs1µsAny::Moose::::mouse_is_preferredAny::Moose::mouse_is_preferred
221800ns800nsAny::Moose::::CORE:matchAny::Moose::CORE:match (opcode)
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{
32800ns $Any::Moose::VERSION = '0.18';
4}
5# ABSTRACT: use Moose or Mouse modules
6
7330µs118µs
# spent 18µs within Any::Moose::BEGIN@7 which was called: # once (18µs+0s) by MooseX::Log::Log4perl::BEGIN@4 at line 7
use 5.006_002;
# spent 18µs making 1 call to Any::Moose::BEGIN@7
8317µs216µs
# spent 12µs (7+4) within Any::Moose::BEGIN@8 which was called: # once (7µs+4µs) by MooseX::Log::Log4perl::BEGIN@4 at line 8
use strict;
# spent 12µs making 1 call to Any::Moose::BEGIN@8 # spent 4µs making 1 call to strict::import
93223µs241µs
# spent 25µs (9+16) within Any::Moose::BEGIN@9 which was called: # once (9µs+16µs) by MooseX::Log::Log4perl::BEGIN@4 at line 9
use warnings;
# spent 25µs making 1 call to Any::Moose::BEGIN@9 # spent 16µs making 1 call to warnings::import
10
11# decide which backend to use
121100nsour $PREFERRED;
131400nsdo {
141300ns local $@;
1513µs12µs if ($ENV{ANY_MOOSE}) {
# spent 2µ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()) {
311600ns $PREFERRED = 'Moose';
32 }
33 elsif (eval { require Mouse }) {
34 $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 7.15ms (30µs+7.12) within Any::Moose::import which was called: # once (30µs+7.12ms) by MooseX::Log::Log4perl::BEGIN@4 at line 4 of MooseX/Log/Log4perl.pm
sub import {
461023µs my $self = shift;
47 my $pkg = caller;
48
49 # Any::Moose gives you strict and warnings
5012µs strict->import;
# spent 2µs making 1 call to strict::import
5118µs warnings->import;
# spent 8µs making 1 call to warnings::import
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
59184µs $options = $self->_canonicalize_options(
# spent 84µs making 1 call to Any::Moose::_canonicalize_options
60 module => $module,
61 options => $options,
62 package => $pkg,
63 );
64
6517.03ms $self->_install_module($options);
# spent 7.03ms making 1 call to Any::Moose::_install_module
66 }
67
68 # give them any_moose too
693446µs236µs
# spent 22µs (7+15) within Any::Moose::BEGIN@69 which was called: # once (7µs+15µs) by MooseX::Log::Log4perl::BEGIN@4 at line 69
no strict 'refs';
# spent 22µs making 1 call to Any::Moose::BEGIN@69 # spent 15µ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 34µs (30+4) within Any::Moose::_backer_of which was called: # once (30µs+4µs) by Any::Moose::any_moose at line 169
sub _backer_of {
10067µs my $pkg = shift;
101
102 if(exists $INC{'Mouse.pm'}){
103 my $meta = Mouse::Util::get_metaclass_by_name($pkg);
104 if ($meta) {
105 return 'Mouse::Role' if $meta->isa('Mouse::Meta::Role');
106 return 'Mouse' if $meta->isa('Mouse::Meta::Class');
107 }
108 }
109
11011µs if (_is_moose_loaded()) {
# spent 1µs making 1 call to Any::Moose::_is_moose_loaded
11113µs my $meta = Class::MOP::get_metaclass_by_name($pkg);
# spent 3µs making 1 call to Class::MOP::get_metaclass_by_name
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 84µs (11+73) within Any::Moose::_canonicalize_options which was called: # once (11µs+73µs) by Any::Moose::import at line 59
sub _canonicalize_options {
122812µ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};
136173µs $options{module} = any_moose($args{module}, $args{package});
# spent 73µs making 1 call to Any::Moose::any_moose
137
138 return \%options;
139}
140
141
# spent 7.03ms (979µs+6.05) within Any::Moose::_install_module which was called: # once (979µs+6.05ms) by Any::Moose::import at line 65
sub _install_module {
14211126µs my $self = shift;
143 my $options = shift;
144
145 my $module = $options->{module};
14612µs (my $file = $module . '.pm') =~ s{::}{/}g;
# spent 2µs making 1 call to Any::Moose::CORE:subst
147
148 require $file;
149
150 my $e = do {
151 local $@;
152 eval "package $options->{package};\n"
# spent 10µ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 73µs (16+57) within Any::Moose::any_moose which was called: # once (16µs+57µs) by Any::Moose::_canonicalize_options at line 136
sub any_moose {
164713µs121µs my $fragment = _canonicalize_fragment(shift);
# spent 21µs making 1 call to Any::Moose::_canonicalize_fragment
165 my $package = shift || caller;
166
167 # Mouse gets first dibs because it doesn't introspect existing classes
168
169134µs my $backer = _backer_of($package) || '';
# spent 34µs making 1 call to Any::Moose::_backer_of
170
1711600ns if ($backer =~ /^Mouse/) {
# spent 600ns making 1 call to Any::Moose::CORE:match
172 $fragment =~ s/^Moose/Mouse/;
173 return $fragment;
174 }
175
1761200ns return $fragment if $backer =~ /^Moose/;
# spent 200ns making 1 call to Any::Moose::CORE:match
177
17811µs $fragment =~ s/^Moose/Mouse/ if mouse_is_preferred();
# spent 1µs making 1 call to Any::Moose::mouse_is_preferred
179 return $fragment;
180}
181
18211µ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 /) {
1913225µs224µs
# spent 15µs (7+8) within Any::Moose::BEGIN@191 which was called: # once (7µs+8µs) by MooseX::Log::Log4perl::BEGIN@4 at line 191
no strict 'refs';
# spent 15µs making 1 call to Any::Moose::BEGIN@191 # spent 8µs making 1 call to strict::unimport
192 *{__PACKAGE__."::$name"} = moose_is_preferred()
193 ? *{"Class::MOP::$name"}
194734µs76µs : *{"Mouse::Util::$name"};
# spent 6µs making 7 calls to Any::Moose::moose_is_preferred, avg 929ns/call
195}
196
197714µs
# spent 6µs within Any::Moose::moose_is_preferred which was called 7 times, avg 929ns/call: # 7 times (6µs+0s) by MooseX::Log::Log4perl::BEGIN@4 at line 194, avg 929ns/call
sub moose_is_preferred { $PREFERRED eq 'Moose' }
19813µs
# spent 1µs within Any::Moose::mouse_is_preferred which was called: # once (1µs+0s) by Any::Moose::any_moose at line 178
sub mouse_is_preferred { $PREFERRED eq 'Mouse' }
199
200231µs
# spent 3µs within Any::Moose::_is_moose_loaded which was called 2 times, avg 2µs/call: # once (2µs+0s) by MooseX::Log::Log4perl::BEGIN@4 at line 15 # once (1µs+0s) by Any::Moose::_backer_of at line 110
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 21µs (16+5) within Any::Moose::_canonicalize_fragment which was called: # once (16µs+5µs) by Any::Moose::any_moose at line 164
sub _canonicalize_fragment {
209723µs my $fragment = shift;
210
211 return 'Moose' if !$fragment;
212
213 # any_moose("X::Types") -> any_moose("MooseX::Types")
2141800ns $fragment =~ s/^X::/MooseX::/;
# spent 800ns making 1 call to Any::Moose::CORE:subst
215
216 # any_moose("::Util") -> any_moose("Moose::Util")
2171300ns $fragment =~ s/^::/Moose::/;
# spent 300ns making 1 call to Any::Moose::CORE:subst
218
219 # any_moose("Mouse::Util") -> any_moose("Moose::Util")
2201300ns $fragment =~ s/^Mouse(X?)\b/Moose$1/;
# spent 300ns making 1 call to Any::Moose::CORE:subst
221
222 # any_moose("Util") -> any_moose("Moose::Util")
22314µs $fragment =~ s/^(?!Moose)/Moose::/;
# spent 4µs making 1 call to Any::Moose::CORE:subst
224
225 return $fragment;
226}
227
228114µs1;
229
230
231=pod
232
233=head1 NAME
234
235Any::Moose - use Moose or Mouse modules
236
237=head1 VERSION
238
239version 0.18
240
241=head1 SYNOPSIS
242
243=head2 BASIC
244
245 package Class;
246
247 # uses Moose if it's loaded or demanded, Mouse otherwise
248 use Any::Moose;
249
250 # cleans the namespace up
251 no Any::Moose;
252
253=head2 OTHER MODULES
254
255 package Other::Class;
256 use Any::Moose;
257
258 # uses Moose::Util::TypeConstraints if the class has loaded Moose,
259 # Mouse::Util::TypeConstraints otherwise.
260 use Any::Moose '::Util::TypeConstraints';
261
262=head2 ROLES
263
264 package My::Sorter;
265 use Any::Moose 'Role';
266
267 requires 'cmp';
268
269=head2 COMPLEX USAGE
270
271 package My::Meta::Class;
272 use Any::Moose;
273
274 # uses subtype from Moose::Util::TypeConstraints if the class loaded Moose,
275 # subtype from Mouse::Util::TypeConstraints otherwise.
276 # similarly for Mo*se::Util's does_role
277 use Any::Moose (
278 '::Util::TypeConstraints' => ['subtype'],
279 '::Util' => ['does_role'],
280 );
281
282 # uses MouseX::Types or MooseX::Types
283 use Any::Moose 'X::Types';
284
285 # gives you the right class name depending on which Mo*se was loaded
286 extends any_moose('::Meta::Class');
287
288=head1 DESCRIPTION
289
290Though we recommend that people generally use L<Moose>, we accept that Moose
291cannot yet be used for everything everywhere. People generally like the Moose
292sugar, so many people use L<Mouse>, a lightweight replacement for parts of
293Moose.
294
295Because Mouse strives for compatibility with Moose, it's easy to substitute one
296for the other. This module facilitates that substitution. By default, Mouse
297will be provided to libraries, unless Moose is already loaded -or-
298explicitly requested by the end-user. The end-user can force the decision
299of which backend to use by setting the environment variable C<ANY_MOOSE> to
300be C<Moose> or C<Mouse>.
301
302Note that the decision of which backend to use is made only once, so that if
303Any-Moose picks Mouse, then a third-party library loads Moose, anything else
304that uses Any-Moose will continue to pick Mouse.
305
306So, if you have to use L<Mouse>, please be considerate to the Moose fanboys
307(like myself!) and use L<Any-Moose> instead. C<:)>
308
309=head1 SEE ALSO
310
311L<Moose>
312
313L<Mouse>
314
315L<Squirrel> - a deprecated first-stab at Any-Moose-like logic. Its biggest
316fault was in making the decision of which backend to use every time it was
317used, rather than just once.
318
319=head1 AUTHORS
320
321=over 4
322
323=item *
324
325Shawn M Moore <sartak@gmail.com>
326
327=item *
328
329Florian Ragwitz <rafl@debian.org>
330
331=item *
332
333Stevan Little <stevan@iinteractive.com>
334
335=item *
336
337Tokuhiro Matsuno <tokuhirom@gmail.com>
338
339=item *
340
341Goro Fuji <gfuji@cpan.org>
342
343=item *
344
345Ricardo Signes <rjbs@cpan.org>
346
347=back
348
349=head1 COPYRIGHT AND LICENSE
350
351This software is copyright (c) 2011 by Best Practical Solutions.
352
353This is free software; you can redistribute it and/or modify it under
354the same terms as the Perl 5 programming language system itself.
355
356=cut
357
358
359__END__
 
# spent 800ns within Any::Moose::CORE:match which was called 2 times, avg 400ns/call: # once (600ns+0s) by Any::Moose::any_moose at line 171 # once (200ns+0s) by Any::Moose::any_moose at line 176
sub Any::Moose::CORE:match; # opcode
# spent 7µs within Any::Moose::CORE:subst which was called 5 times, avg 1µs/call: # once (4µs+0s) by Any::Moose::_canonicalize_fragment at line 223 # once (2µs+0s) by Any::Moose::_install_module at line 146 # once (800ns+0s) by Any::Moose::_canonicalize_fragment at line 214 # once (300ns+0s) by Any::Moose::_canonicalize_fragment at line 217 # once (300ns+0s) by Any::Moose::_canonicalize_fragment at line 220
sub Any::Moose::CORE:subst; # opcode