| Filename | /usr/local/share/perl/5.10.1/Any/Moose.pm |
| Statements | Executed 580 statements in 3.38ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 9 | 1 | 1 | 556µs | 2.65ms | Any::Moose::_install_module |
| 9 | 9 | 8 | 278µs | 3.62ms | Any::Moose::import |
| 5 | 5 | 5 | 274µs | 625µs | Any::Moose::unimport |
| 14 | 2 | 1 | 157µs | 223µs | Any::Moose::_backer_of |
| 9 | 1 | 1 | 151µs | 443µs | Any::Moose::any_moose |
| 9 | 1 | 1 | 130µs | 573µs | Any::Moose::_canonicalize_options |
| 9 | 1 | 1 | 103µs | 136µs | Any::Moose::_canonicalize_fragment |
| 54 | 7 | 1 | 59µs | 59µs | Any::Moose::CORE:subst (opcode) |
| 1 | 1 | 1 | 21µs | 21µs | Any::Moose::BEGIN@7 |
| 9 | 2 | 1 | 19µs | 19µs | Any::Moose::_is_moose_loaded |
| 8 | 1 | 1 | 16µs | 16µs | Any::Moose::mouse_is_preferred |
| 7 | 1 | 1 | 12µs | 12µs | Any::Moose::moose_is_preferred |
| 1 | 1 | 1 | 10µs | 10µs | Any::Moose::BEGIN@2 |
| 1 | 1 | 1 | 9µs | 22µs | Any::Moose::BEGIN@9 |
| 1 | 1 | 1 | 9µs | 27µs | Any::Moose::BEGIN@69 |
| 1 | 1 | 1 | 9µs | 22µs | Any::Moose::BEGIN@191 |
| 1 | 1 | 1 | 9µs | 12µs | Any::Moose::BEGIN@8 |
| 17 | 2 | 1 | 7µs | 7µs | Any::Moose::CORE:match (opcode) |
| 0 | 0 | 0 | 0s | 0s | Any::Moose::is_moose_loaded |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package 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 | ||||
| 3 | 1 | 6µs | $Any::Moose::VERSION = '0.13'; | ||
| 4 | 1 | 26µs | 1 | 10µs | } # spent 10µs making 1 call to Any::Moose::BEGIN@2 |
| 5 | # ABSTRACT: use Moose or Mouse modules | ||||
| 6 | |||||
| 7 | 3 | 47µs | 1 | 21µs | # spent 21µs within Any::Moose::BEGIN@7 which was called:
# once (21µs+0s) by MongoDB::Cursor::BEGIN@21 at line 7 # spent 21µs making 1 call to Any::Moose::BEGIN@7 |
| 8 | 3 | 30µs | 2 | 16µ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 # spent 12µs making 1 call to Any::Moose::BEGIN@8
# spent 3µs making 1 call to strict::import |
| 9 | 3 | 358µs | 2 | 34µ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 # 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 | ||||
| 12 | 1 | 100ns | our $PREFERRED; | ||
| 13 | 1 | 800ns | do { | ||
| 14 | 1 | 1µs | local $@; | ||
| 15 | 1 | 5µs | 1 | 3µ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 | } | ||||
| 33 | 1 | 74µs | elsif (eval { require Mouse }) { | ||
| 34 | 1 | 1µ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 | ||||
| 46 | 9 | 8µs | my $self = shift; | ||
| 47 | 9 | 5µs | my $pkg = caller; | ||
| 48 | |||||
| 49 | # Any::Moose gives you strict and warnings | ||||
| 50 | 9 | 13µs | 9 | 23µs | strict->import; # spent 23µs making 9 calls to strict::import, avg 3µs/call |
| 51 | 9 | 18µs | 9 | 96µs | warnings->import; # spent 96µs making 9 calls to warnings::import, avg 11µs/call |
| 52 | |||||
| 53 | # first options are for Mo*se | ||||
| 54 | 9 | 14µs | unshift @_, 'Moose' if !@_ || ref($_[0]); | ||
| 55 | |||||
| 56 | 9 | 20µs | while (my $module = shift) { | ||
| 57 | 9 | 8µs | my $options = @_ && ref($_[0]) ? shift : []; | ||
| 58 | |||||
| 59 | 9 | 26µs | 9 | 573µ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 | |||||
| 65 | 9 | 32µs | 9 | 2.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 | ||||
| 69 | 3 | 796µs | 2 | 44µ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 # spent 27µs making 1 call to Any::Moose::BEGIN@69
# spent 17µs making 1 call to strict::unimport |
| 70 | 9 | 85µ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 | ||||
| 74 | 5 | 5µs | my $sel = shift; | ||
| 75 | 5 | 4µs | my $pkg = caller; | ||
| 76 | 5 | 1µs | my $module; | ||
| 77 | |||||
| 78 | 5 | 4µs | if(@_){ | ||
| 79 | $module = any_moose(shift, $pkg); | ||||
| 80 | } | ||||
| 81 | else { | ||||
| 82 | 5 | 10µs | 5 | 106µs | $module = _backer_of($pkg); # spent 106µs making 5 calls to Any::Moose::_backer_of, avg 21µs/call |
| 83 | } | ||||
| 84 | 5 | 4µs | my $e = do{ | ||
| 85 | 5 | 2µs | local $@; | ||
| 86 | 5 | 176µ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();'; | ||||
| 88 | 5 | 5µs | $@; | ||
| 89 | }; | ||||
| 90 | |||||
| 91 | 5 | 800ns | if ($e) { | ||
| 92 | require Carp; | ||||
| 93 | Carp::croak("Cannot unimport Any::Moose: $e"); | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | 5 | 19µs | return; | ||
| 97 | } | ||||
| 98 | |||||
| 99 | sub _backer_of { | ||||
| 100 | 14 | 5µs | my $pkg = shift; | ||
| 101 | |||||
| 102 | 14 | 10µs | if(exists $INC{'Mouse.pm'}){ | ||
| 103 | 14 | 21µs | 14 | 25µ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 |
| 104 | 14 | 7µs | if ($meta) { | ||
| 105 | 6 | 41µs | 6 | 18µs | return 'Mouse::Role' if $meta->isa('Mouse::Meta::Role'); # spent 18µs making 6 calls to UNIVERSAL::isa, avg 3µs/call |
| 106 | 6 | 41µs | 6 | 7µ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 | |||||
| 110 | 8 | 14µs | 8 | 16µ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 | |||||
| 118 | 8 | 18µ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 | ||||
| 122 | 9 | 4µs | my $self = shift; | ||
| 123 | 9 | 27µs | my %args = @_; | ||
| 124 | |||||
| 125 | 9 | 2µs | my %options; | ||
| 126 | 9 | 11µs | if (ref($args{options}) eq 'HASH') { | ||
| 127 | %options = %{ $args{options} }; | ||||
| 128 | } | ||||
| 129 | else { | ||||
| 130 | 9 | 13µs | %options = ( | ||
| 131 | imports => $args{options}, | ||||
| 132 | ); | ||||
| 133 | } | ||||
| 134 | |||||
| 135 | 9 | 12µs | $options{package} = $args{package}; | ||
| 136 | 9 | 26µs | 9 | 443µ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 | |||||
| 138 | 9 | 44µ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 | ||||
| 142 | 9 | 5µs | my $self = shift; | ||
| 143 | 9 | 3µs | my $options = shift; | ||
| 144 | |||||
| 145 | 9 | 7µs | my $module = $options->{module}; | ||
| 146 | 9 | 37µs | 9 | 11µs | (my $file = $module . '.pm') =~ s{::}{/}g; # spent 11µs making 9 calls to Any::Moose::CORE:subst, avg 1µs/call |
| 147 | |||||
| 148 | 9 | 4µs | require $file; | ||
| 149 | |||||
| 150 | 9 | 6µs | my $e = do { | ||
| 151 | 9 | 3µs | local $@; | ||
| 152 | 9 | 383µ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} });'; | ||||
| 154 | 9 | 8µs | $@; | ||
| 155 | }; | ||||
| 156 | 9 | 2µs | if ($e) { | ||
| 157 | require Carp; | ||||
| 158 | Carp::croak("Cannot import Any::Moose: $e"); | ||||
| 159 | } | ||||
| 160 | 9 | 26µ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 | ||||
| 164 | 9 | 17µs | 9 | 136µs | my $fragment = _canonicalize_fragment(shift); # spent 136µs making 9 calls to Any::Moose::_canonicalize_fragment, avg 15µs/call |
| 165 | 9 | 5µs | my $package = shift || caller; | ||
| 166 | |||||
| 167 | # Mouse gets first dibs because it doesn't introspect existing classes | ||||
| 168 | |||||
| 169 | 9 | 19µs | 9 | 117µs | my $backer = _backer_of($package) || ''; # spent 117µs making 9 calls to Any::Moose::_backer_of, avg 13µs/call |
| 170 | |||||
| 171 | 9 | 25µs | 9 | 6µs | if ($backer =~ /^Mouse/) { # spent 6µs making 9 calls to Any::Moose::CORE:match, avg 611ns/call |
| 172 | 1 | 5µs | 1 | 2µs | $fragment =~ s/^Moose/Mouse/; # spent 2µs making 1 call to Any::Moose::CORE:subst |
| 173 | 1 | 3µs | return $fragment; | ||
| 174 | } | ||||
| 175 | |||||
| 176 | 8 | 14µs | 8 | 1µs | return $fragment if $backer =~ /^Moose/; # spent 1µs making 8 calls to Any::Moose::CORE:match, avg 187ns/call |
| 177 | |||||
| 178 | 8 | 44µs | 16 | 30µ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 |
| 179 | 8 | 26µs | return $fragment; | ||
| 180 | } | ||||
| 181 | |||||
| 182 | 1 | 2µs | for 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 | /) { | ||||
| 191 | 3 | 346µs | 2 | 35µ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 # 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"} | ||||
| 194 | 7 | 45µs | 7 | 12µs | : *{"Mouse::Util::$name"}; # spent 12µs making 7 calls to Any::Moose::moose_is_preferred, avg 2µs/call |
| 195 | } | ||||
| 196 | |||||
| 197 | 7 | 22µ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 | ||
| 198 | 8 | 23µ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 | ||
| 199 | |||||
| 200 | 9 | 31µs | sub _is_moose_loaded { exists $INC{'Moose.pm'} } | ||
| 201 | |||||
| 202 | sub 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 | ||||
| 209 | 9 | 4µs | my $fragment = shift; | ||
| 210 | |||||
| 211 | 9 | 2µs | return 'Moose' if !$fragment; | ||
| 212 | |||||
| 213 | # any_moose("X::Types") -> any_moose("MooseX::Types") | ||||
| 214 | 9 | 35µs | 9 | 7µ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") | ||||
| 217 | 9 | 19µs | 9 | 3µ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") | ||||
| 220 | 9 | 20µs | 9 | 4µ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") | ||||
| 223 | 9 | 35µs | 9 | 18µs | $fragment =~ s/^(?!Moose)/Moose::/; # spent 18µs making 9 calls to Any::Moose::CORE:subst, avg 2µs/call |
| 224 | |||||
| 225 | 9 | 30µs | return $fragment; | ||
| 226 | } | ||||
| 227 | |||||
| 228 | 1 | 24µs | 1; | ||
| 229 | |||||
| 230 | |||||
| 231 | =pod | ||||
| 232 | |||||
| - - | |||||
| 349 | __END__ | ||||
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 |