← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mongo_pain.pl
  Run on Fri Mar 25 17:00:29 2011
Reported on Fri Mar 25 17:07:09 2011

Filename/usr/local/share/perl/5.10.1/Any/Moose.pm
StatementsExecuted 580 statements in 3.38ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
911556µs2.65msAny::Moose::::_install_moduleAny::Moose::_install_module
998278µs3.62msAny::Moose::::importAny::Moose::import
555274µs625µsAny::Moose::::unimportAny::Moose::unimport
1421157µs223µsAny::Moose::::_backer_ofAny::Moose::_backer_of
911151µs443µsAny::Moose::::any_mooseAny::Moose::any_moose
911130µs573µsAny::Moose::::_canonicalize_optionsAny::Moose::_canonicalize_options
911103µs136µsAny::Moose::::_canonicalize_fragmentAny::Moose::_canonicalize_fragment
547159µs59µsAny::Moose::::CORE:substAny::Moose::CORE:subst (opcode)
11121µs21µsAny::Moose::::BEGIN@7Any::Moose::BEGIN@7
92119µs19µsAny::Moose::::_is_moose_loadedAny::Moose::_is_moose_loaded
81116µs16µsAny::Moose::::mouse_is_preferredAny::Moose::mouse_is_preferred
71112µs12µsAny::Moose::::moose_is_preferredAny::Moose::moose_is_preferred
11110µs10µsAny::Moose::::BEGIN@2Any::Moose::BEGIN@2
1119µs22µsAny::Moose::::BEGIN@9Any::Moose::BEGIN@9
1119µs27µsAny::Moose::::BEGIN@69Any::Moose::BEGIN@69
1119µs22µsAny::Moose::::BEGIN@191Any::Moose::BEGIN@191
1119µs12µsAny::Moose::::BEGIN@8Any::Moose::BEGIN@8
17217µs7µsAny::Moose::::CORE:matchAny::Moose::CORE:match (opcode)
0000s0sAny::Moose::::is_moose_loadedAny::Moose::is_moose_loaded
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 10µs within Any::Moose::BEGIN@2 which was called: # once (10µs+0s) by MongoDB::Cursor::BEGIN@21 at line 4
BEGIN {
316µs $Any::Moose::VERSION = '0.13';
4126µs110µs}
# spent 10µs making 1 call to Any::Moose::BEGIN@2
5# ABSTRACT: use Moose or Mouse modules
6
7347µs121µs
# spent 21µs within Any::Moose::BEGIN@7 which was called: # once (21µs+0s) by MongoDB::Cursor::BEGIN@21 at line 7
use 5.006_002;
# spent 21µs making 1 call to Any::Moose::BEGIN@7
8330µs216µs
# spent 12µs (9+3) within Any::Moose::BEGIN@8 which was called: # once (9µs+3µs) by MongoDB::Cursor::BEGIN@21 at line 8
use strict;
# spent 12µs making 1 call to Any::Moose::BEGIN@8 # spent 3µs making 1 call to strict::import
93358µs234µs
# spent 22µs (9+12) within Any::Moose::BEGIN@9 which was called: # once (9µs+12µs) by MongoDB::Cursor::BEGIN@21 at line 9
use warnings;
# spent 22µ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
121100nsour $PREFERRED;
131800nsdo {
1411µs local $@;
1515µs13µs if ($ENV{ANY_MOOSE}) {
# spent 3µ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 }
33174µs elsif (eval { require Mouse }) {
3411µ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 3.62ms (278µs+3.34) within Any::Moose::import which was called 9 times, avg 402µs/call: # once (46µs+496µs) by MongoDB::Cursor::BEGIN@21 at line 21 of MongoDB/Cursor.pm # once (37µs+461µs) by MongoDB::OID::BEGIN@21 at line 21 of MongoDB/OID.pm # once (28µs+425µs) by MongoDB::Timestamp::BEGIN@35 at line 35 of MongoDB/Timestamp.pm # once (28µs+381µs) by MongoDB::GridFS::File::BEGIN@22 at line 22 of MongoDB/GridFS/File.pm # once (28µs+373µs) by MongoDB::Database::BEGIN@22 at line 22 of MongoDB/Database.pm # once (27µs+374µs) by MongoDB::GridFS::BEGIN@22 at line 22 of MongoDB/GridFS.pm # once (32µs+315µs) by MongoDB::Collection::BEGIN@48 at line 48 of MongoDB/Collection.pm # once (28µs+314µs) by MongoDB::Connection::BEGIN@25 at line 25 of MongoDB/Connection.pm # once (24µs+201µs) by MongoDB::Connection::BEGIN@26 at line 26 of MongoDB/Connection.pm
sub import {
4698µs my $self = shift;
4795µs my $pkg = caller;
48
49 # Any::Moose gives you strict and warnings
50913µs923µs strict->import;
# spent 23µs making 9 calls to strict::import, avg 3µs/call
51918µs996µs warnings->import;
# spent 96µs making 9 calls to warnings::import, avg 11µs/call
52
53 # first options are for Mo*se
54914µs unshift @_, 'Moose' if !@_ || ref($_[0]);
55
56920µs while (my $module = shift) {
5798µs my $options = @_ && ref($_[0]) ? shift : [];
58
59926µs9573µs $options = $self->_canonicalize_options(
# spent 573µs making 9 calls to Any::Moose::_canonicalize_options, avg 64µs/call
60 module => $module,
61 options => $options,
62 package => $pkg,
63 );
64
65932µs92.65ms $self->_install_module($options);
# spent 2.65ms making 9 calls to Any::Moose::_install_module, avg 294µs/call
66 }
67
68 # give them any_moose too
693796µs244µs
# spent 27µs (9+17) within Any::Moose::BEGIN@69 which was called: # once (9µs+17µs) by MongoDB::Cursor::BEGIN@21 at line 69
no strict 'refs';
# spent 27µs making 1 call to Any::Moose::BEGIN@69 # spent 17µs making 1 call to strict::unimport
70985µs *{$pkg.'::any_moose'} = \&any_moose;
71}
72
73
# spent 625µs (274+351) within Any::Moose::unimport which was called 5 times, avg 125µs/call: # once (57µs+85µs) by MongoDB::Database::BEGIN@328 at line 328 of MongoDB/Database.pm # once (58µs+79µs) by MongoDB::Cursor::BEGIN@487 at line 487 of MongoDB/Cursor.pm # once (56µs+64µs) by MongoDB::Collection::BEGIN@723 at line 723 of MongoDB/Collection.pm # once (51µs+64µs) by MongoDB::Connection::BEGIN@737 at line 737 of MongoDB/Connection.pm # once (52µs+60µs) by MongoDB::OID::BEGIN@143 at line 143 of MongoDB/OID.pm
sub unimport {
7455µs my $sel = shift;
7554µs my $pkg = caller;
7651µs my $module;
77
7854µs if(@_){
79 $module = any_moose(shift, $pkg);
80 }
81 else {
82510µs5106µs $module = _backer_of($pkg);
# spent 106µs making 5 calls to Any::Moose::_backer_of, avg 21µs/call
83 }
8454µs my $e = do{
8552µs local $@;
865176µs eval "package $pkg;\n"
# spent 9µs executing statements in string eval # spent 7µs executing statements in string eval # spent 6µs executing statements in string eval # spent 6µs executing statements in string eval # spent 6µs executing statements in string eval
87 . '$module->unimport();';
8855µs $@;
89 };
90
915800ns if ($e) {
92 require Carp;
93 Carp::croak("Cannot unimport Any::Moose: $e");
94 }
95
96519µs return;
97}
98
99
# spent 223µs (157+66) within Any::Moose::_backer_of which was called 14 times, avg 16µs/call: # 9 times (83µs+35µs) by Any::Moose::any_moose at line 169, avg 13µs/call # 5 times (74µs+31µs) by Any::Moose::unimport at line 82, avg 21µs/call
sub _backer_of {
100145µs my $pkg = shift;
101
1021410µs if(exists $INC{'Mouse.pm'}){
1031421µs1425µs my $meta = Mouse::Util::get_metaclass_by_name($pkg);
# spent 25µs making 14 calls to Mouse::Meta::Module::_get_metaclass_by_name, avg 2µs/call
104147µs if ($meta) {
105641µs618µs return 'Mouse::Role' if $meta->isa('Mouse::Meta::Role');
# spent 18µs making 6 calls to UNIVERSAL::isa, avg 3µs/call
106641µs67µs return 'Mouse' if $meta->isa('Mouse::Meta::Class');
# spent 7µs making 6 calls to UNIVERSAL::isa, avg 1µs/call
107 }
108 }
109
110814µs816µs if (_is_moose_loaded()) {
# spent 16µs making 8 calls to Any::Moose::_is_moose_loaded, avg 2µ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
118818µs return undef;
119}
120
121
# spent 573µs (130+443) within Any::Moose::_canonicalize_options which was called 9 times, avg 64µs/call: # 9 times (130µs+443µs) by Any::Moose::import at line 59, avg 64µs/call
sub _canonicalize_options {
12294µs my $self = shift;
123927µs my %args = @_;
124
12592µs my %options;
126911µs if (ref($args{options}) eq 'HASH') {
127 %options = %{ $args{options} };
128 }
129 else {
130913µs %options = (
131 imports => $args{options},
132 );
133 }
134
135912µs $options{package} = $args{package};
136926µs9443µs $options{module} = any_moose($args{module}, $args{package});
# spent 443µs making 9 calls to Any::Moose::any_moose, avg 49µs/call
137
138944µs return \%options;
139}
140
141
# spent 2.65ms (556µs+2.09) within Any::Moose::_install_module which was called 9 times, avg 294µs/call: # 9 times (556µs+2.09ms) by Any::Moose::import at line 65, avg 294µs/call
sub _install_module {
14295µs my $self = shift;
14393µs my $options = shift;
144
14597µs my $module = $options->{module};
146937µs911µs (my $file = $module . '.pm') =~ s{::}{/}g;
# spent 11µs making 9 calls to Any::Moose::CORE:subst, avg 1µs/call
147
14894µs require $file;
149
15096µs my $e = do {
15193µs local $@;
1529383µs eval "package $options->{package};\n"
# spent 16µs executing statements in 2 string evals (merged) # spent 9µs executing statements in string eval # spent 8µs executing statements in string eval # spent 8µs executing statements in string eval # spent 8µs executing statements in string eval # spent 8µs executing statements in string eval # spent 8µs executing statements in string eval # spent 7µs executing statements in string eval
153 . '$module->import(@{ $options->{imports} });';
15498µs $@;
155 };
15692µs if ($e) {
157 require Carp;
158 Carp::croak("Cannot import Any::Moose: $e");
159 }
160926µs return;
161}
162
163
# spent 443µs (151+292) within Any::Moose::any_moose which was called 9 times, avg 49µs/call: # 9 times (151µs+292µs) by Any::Moose::_canonicalize_options at line 136, avg 49µs/call
sub any_moose {
164917µs9136µs my $fragment = _canonicalize_fragment(shift);
# spent 136µs making 9 calls to Any::Moose::_canonicalize_fragment, avg 15µs/call
16595µs my $package = shift || caller;
166
167 # Mouse gets first dibs because it doesn't introspect existing classes
168
169919µs9117µs my $backer = _backer_of($package) || '';
# spent 117µs making 9 calls to Any::Moose::_backer_of, avg 13µs/call
170
171925µs96µs if ($backer =~ /^Mouse/) {
# spent 6µs making 9 calls to Any::Moose::CORE:match, avg 611ns/call
17215µs12µs $fragment =~ s/^Moose/Mouse/;
# spent 2µs making 1 call to Any::Moose::CORE:subst
17313µs return $fragment;
174 }
175
176814µs81µs return $fragment if $backer =~ /^Moose/;
# spent 1µs making 8 calls to Any::Moose::CORE:match, avg 187ns/call
177
178844µs1630µs $fragment =~ s/^Moose/Mouse/ if mouse_is_preferred();
# spent 16µs making 8 calls to Any::Moose::mouse_is_preferred, avg 2µs/call # spent 14µs making 8 calls to Any::Moose::CORE:subst, avg 2µs/call
179826µs return $fragment;
180}
181
18212µ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 /) {
1913346µs235µs
# spent 22µs (9+13) within Any::Moose::BEGIN@191 which was called: # once (9µs+13µs) by MongoDB::Cursor::BEGIN@21 at line 191
no strict 'refs';
# spent 22µs making 1 call to Any::Moose::BEGIN@191 # spent 13µs making 1 call to strict::unimport
192 *{__PACKAGE__."::$name"} = moose_is_preferred()
193 ? *{"Class::MOP::$name"}
194745µs712µs : *{"Mouse::Util::$name"};
# spent 12µs making 7 calls to Any::Moose::moose_is_preferred, avg 2µs/call
195}
196
197722µs
# spent 12µs within Any::Moose::moose_is_preferred which was called 7 times, avg 2µs/call: # 7 times (12µs+0s) by MongoDB::Cursor::BEGIN@21 at line 194, avg 2µs/call
sub moose_is_preferred { $PREFERRED eq 'Moose' }
198823µs
# spent 16µs within Any::Moose::mouse_is_preferred which was called 8 times, avg 2µs/call: # 8 times (16µs+0s) by Any::Moose::any_moose at line 178, avg 2µs/call
sub mouse_is_preferred { $PREFERRED eq 'Mouse' }
199
200931µs
# spent 19µs within Any::Moose::_is_moose_loaded which was called 9 times, avg 2µs/call: # 8 times (16µs+0s) by Any::Moose::_backer_of at line 110, avg 2µs/call # once (3µs+0s) by MongoDB::Cursor::BEGIN@21 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 136µs (103+33) within Any::Moose::_canonicalize_fragment which was called 9 times, avg 15µs/call: # 9 times (103µs+33µs) by Any::Moose::any_moose at line 164, avg 15µs/call
sub _canonicalize_fragment {
20994µs my $fragment = shift;
210
21192µs return 'Moose' if !$fragment;
212
213 # any_moose("X::Types") -> any_moose("MooseX::Types")
214935µs97µs $fragment =~ s/^X::/MooseX::/;
# spent 7µs making 9 calls to Any::Moose::CORE:subst, avg 822ns/call
215
216 # any_moose("::Util") -> any_moose("Moose::Util")
217919µs93µs $fragment =~ s/^::/Moose::/;
# spent 3µs making 9 calls to Any::Moose::CORE:subst, avg 356ns/call
218
219 # any_moose("Mouse::Util") -> any_moose("Moose::Util")
220920µs94µs $fragment =~ s/^Mouse(X?)\b/Moose$1/;
# spent 4µs making 9 calls to Any::Moose::CORE:subst, avg 500ns/call
221
222 # any_moose("Util") -> any_moose("Moose::Util")
223935µs918µs $fragment =~ s/^(?!Moose)/Moose::/;
# spent 18µs making 9 calls to Any::Moose::CORE:subst, avg 2µs/call
224
225930µs return $fragment;
226}
227
228124µs1;
229
230
231=pod
232
- -
349__END__
 
# spent 7µs within Any::Moose::CORE:match which was called 17 times, avg 412ns/call: # 9 times (6µs+0s) by Any::Moose::any_moose at line 171, avg 611ns/call # 8 times (1µs+0s) by Any::Moose::any_moose at line 176, avg 187ns/call
sub Any::Moose::CORE:match; # opcode
# spent 59µs within Any::Moose::CORE:subst which was called 54 times, avg 1µs/call: # 9 times (18µs+0s) by Any::Moose::_canonicalize_fragment at line 223, avg 2µs/call # 9 times (11µs+0s) by Any::Moose::_install_module at line 146, avg 1µs/call # 9 times (7µs+0s) by Any::Moose::_canonicalize_fragment at line 214, avg 822ns/call # 9 times (4µs+0s) by Any::Moose::_canonicalize_fragment at line 220, avg 500ns/call # 9 times (3µs+0s) by Any::Moose::_canonicalize_fragment at line 217, avg 356ns/call # 8 times (14µs+0s) by Any::Moose::any_moose at line 178, avg 2µs/call # once (2µs+0s) by Any::Moose::any_moose at line 172
sub Any::Moose::CORE:subst; # opcode