| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm |
| Statements | Executed 32390 statements in 425ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 2016 | 4 | 2 | 155ms | 415ms | Sub::Install::__ANON__[:132] |
| 2016 | 1 | 1 | 149ms | 211ms | Sub::Install::__ANON__[:175] |
| 2016 | 1 | 1 | 61.3ms | 62.5ms | Sub::Install::__ANON__[:187] |
| 2016 | 1 | 1 | 38.1ms | 48.8ms | Sub::Install::_CODELIKE |
| 20 | 1 | 1 | 811µs | 1.15ms | Sub::Install::__ANON__[:173] |
| 20 | 1 | 1 | 220µs | 220µs | Sub::Install::CORE:match (opcode) |
| 1 | 1 | 1 | 186µs | 440µs | Sub::Install::BEGIN@190 |
| 20 | 1 | 1 | 122µs | 122µs | Sub::Install::CORE:regcomp (opcode) |
| 3 | 3 | 1 | 96µs | 118µs | Sub::Install::_do_with_warn |
| 4 | 4 | 4 | 91µs | 91µs | Sub::Install::__ANON__[:284] |
| 1 | 1 | 1 | 71µs | 145µs | Sub::Install::BEGIN@3 |
| 1 | 1 | 1 | 68µs | 113µs | Sub::Install::BEGIN@139 |
| 2 | 2 | 2 | 67µs | 67µs | Sub::Install::exporter |
| 3 | 3 | 1 | 66µs | 66µs | Sub::Install::__ANON__[:176] |
| 1 | 1 | 1 | 54µs | 87µs | Sub::Install::BEGIN@287 |
| 3 | 3 | 1 | 53µs | 53µs | Sub::Install::CORE:qr (opcode) |
| 2 | 2 | 1 | 48µs | 48µs | Sub::Install::_build_public_installer |
| 3 | 3 | 1 | 44µs | 44µs | Sub::Install::_installer |
| 1 | 1 | 1 | 40µs | 115µs | Sub::Install::BEGIN@184 |
| 1 | 1 | 1 | 36µs | 243µs | Sub::Install::BEGIN@6 |
| 1 | 1 | 1 | 36µs | 52µs | Sub::Install::BEGIN@4 |
| 1 | 1 | 1 | 30µs | 39µs | Sub::Install::BEGIN@148 |
| 1 | 1 | 1 | 19µs | 19µs | Sub::Install::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Sub::Install::__ANON__[:156] |
| 0 | 0 | 0 | 0s | 0s | Sub::Install::__ANON__[:250] |
| 0 | 0 | 0 | 0s | 0s | Sub::Install::_name_of_code |
| 0 | 0 | 0 | 0s | 0s | Sub::Install::install_installers |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Sub::Install; | ||||
| 2 | |||||
| 3 | 3 | 104µs | 2 | 218µs | # spent 145µs (71+73) within Sub::Install::BEGIN@3 which was called:
# once (71µs+73µs) by Data::OptList::BEGIN@8 at line 3 # spent 145µs making 1 call to Sub::Install::BEGIN@3
# spent 73µs making 1 call to warnings::import |
| 4 | 3 | 92µs | 2 | 68µs | # spent 52µs (36+16) within Sub::Install::BEGIN@4 which was called:
# once (36µs+16µs) by Data::OptList::BEGIN@8 at line 4 # spent 52µs making 1 call to Sub::Install::BEGIN@4
# spent 16µs making 1 call to strict::import |
| 5 | |||||
| 6 | 3 | 99µs | 2 | 449µs | # spent 243µs (36+206) within Sub::Install::BEGIN@6 which was called:
# once (36µs+206µs) by Data::OptList::BEGIN@8 at line 6 # spent 243µs making 1 call to Sub::Install::BEGIN@6
# spent 206µs making 1 call to Exporter::import |
| 7 | 3 | 1.57ms | 1 | 19µs | # spent 19µs within Sub::Install::BEGIN@7 which was called:
# once (19µs+0s) by Data::OptList::BEGIN@8 at line 7 # spent 19µs making 1 call to Sub::Install::BEGIN@7 |
| 8 | |||||
| 9 | =head1 NAME | ||||
| 10 | |||||
| - - | |||||
| 19 | 1 | 4µs | our $VERSION = '0.925'; | ||
| 20 | |||||
| 21 | =head1 SYNOPSIS | ||||
| 22 | |||||
| - - | |||||
| 88 | sub _name_of_code { | ||||
| 89 | my ($code) = @_; | ||||
| 90 | require B; | ||||
| 91 | my $name = B::svref_2object($code)->GV->NAME; | ||||
| 92 | return $name unless $name =~ /\A__ANON__/; | ||||
| 93 | return; | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | # See also Params::Util, to which this code was donated. | ||||
| 97 | # spent 48.8ms (38.1+10.6) within Sub::Install::_CODELIKE which was called 2016 times, avg 24µs/call:
# 2016 times (38.1ms+10.6ms) by Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:132] at line 117, avg 24µs/call | ||||
| 98 | 2016 | 53.8ms | 2016 | 10.6ms | (Scalar::Util::reftype($_[0])||'') eq 'CODE' # spent 10.6ms making 2016 calls to Scalar::Util::reftype, avg 5µs/call |
| 99 | || Scalar::Util::blessed($_[0]) | ||||
| 100 | && (overload::Method($_[0],'&{}') ? $_[0] : undef); | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | # do the heavy lifting | ||||
| 104 | sub _build_public_installer { | ||||
| 105 | 4 | 58µs | my ($installer) = @_; | ||
| 106 | |||||
| 107 | # spent 415ms (155+260) within Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:132] which was called 2016 times, avg 206µs/call:
# 2010 times (155ms+259ms) by Sub::Exporter::default_installer at line 896 of Sub/Exporter.pm, avg 206µs/call
# 2 times (189µs+311µs) by Sub::Exporter::setup_exporter at line 607 of Sub/Exporter.pm, avg 250µs/call
# 2 times (143µs+352µs) by Package::DeprecationManager::import at line 37 of Package/DeprecationManager.pm, avg 247µs/call
# 2 times (179µs+303µs) by Package::DeprecationManager::import at line 29 of Package/DeprecationManager.pm, avg 241µs/call | ||||
| 108 | 14112 | 121ms | my ($arg) = @_; | ||
| 109 | my ($calling_pkg) = caller(0); | ||||
| 110 | |||||
| 111 | # I'd rather use ||= but I'm whoring for Devel::Cover. | ||||
| 112 | 4032 | 26.9ms | for (qw(into from)) { $arg->{$_} = $calling_pkg unless $arg->{$_} } | ||
| 113 | |||||
| 114 | # This is the only absolutely required argument, in many cases. | ||||
| 115 | Carp::croak "named argument 'code' is not optional" unless $arg->{code}; | ||||
| 116 | |||||
| 117 | 2016 | 48.8ms | if (_CODELIKE($arg->{code})) { # spent 48.8ms making 2016 calls to Sub::Install::_CODELIKE, avg 24µs/call | ||
| 118 | $arg->{as} ||= _name_of_code($arg->{code}); | ||||
| 119 | } else { | ||||
| 120 | Carp::croak | ||||
| 121 | "couldn't find subroutine named $arg->{code} in package $arg->{from}" | ||||
| 122 | unless my $code = $arg->{from}->can($arg->{code}); | ||||
| 123 | |||||
| 124 | $arg->{as} = $arg->{code} unless $arg->{as}; | ||||
| 125 | $arg->{code} = $code; | ||||
| 126 | } | ||||
| 127 | |||||
| 128 | Carp::croak "couldn't determine name under which to install subroutine" | ||||
| 129 | unless $arg->{as}; | ||||
| 130 | |||||
| 131 | 2016 | 211ms | $installer->(@$arg{qw(into as code) }); # spent 211ms making 2016 calls to Sub::Install::__ANON__[Sub/Install.pm:175], avg 105µs/call | ||
| 132 | } | ||||
| 133 | } | ||||
| 134 | |||||
| 135 | # do the ugly work | ||||
| 136 | |||||
| 137 | 1 | 2µs | my $_misc_warn_re; | ||
| 138 | 1 | 2µs | my $_redef_warn_re; | ||
| 139 | # spent 113µs (68+45) within Sub::Install::BEGIN@139 which was called:
# once (68µs+45µs) by Data::OptList::BEGIN@8 at line 145 | ||||
| 140 | 2 | 103µs | 1 | 24µs | $_misc_warn_re = qr/ # spent 24µs making 1 call to Sub::Install::CORE:qr |
| 141 | Prototype\ mismatch:\ sub\ .+? | | ||||
| 142 | Constant subroutine \S+ redefined | ||||
| 143 | /x; | ||||
| 144 | 1 | 21µs | $_redef_warn_re = qr/Subroutine\ \S+\ redefined/x; # spent 21µs making 1 call to Sub::Install::CORE:qr | ||
| 145 | 1 | 133µs | 1 | 113µs | } # spent 113µs making 1 call to Sub::Install::BEGIN@139 |
| 146 | |||||
| 147 | 1 | 2µs | my $eow_re; | ||
| 148 | 1 | 1.07ms | 2 | 47µs | # spent 39µs (30+8) within Sub::Install::BEGIN@148 which was called:
# once (30µs+8µs) by Data::OptList::BEGIN@8 at line 148 # spent 39µs making 1 call to Sub::Install::BEGIN@148
# spent 8µs making 1 call to Sub::Install::CORE:qr |
| 149 | |||||
| 150 | sub _do_with_warn { | ||||
| 151 | 14 | 109µs | my ($arg) = @_; | ||
| 152 | my $code = delete $arg->{code}; | ||||
| 153 | # spent 66µs within Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:176] which was called 3 times, avg 22µs/call:
# once (27µs+0s) by Sub::Install::BEGIN@190 at line 195
# once (23µs+0s) by Sub::Install::_do_with_warn at line 177
# once (16µs+0s) by Sub::Install::BEGIN@190 at line 202 | ||||
| 154 | 6 | 86µs | my $code = shift; | ||
| 155 | # spent 211ms (149+62.5) within Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:175] which was called 2016 times, avg 105µs/call:
# 2016 times (149ms+62.5ms) by Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:132] at line 131, avg 105µs/call | ||||
| 156 | 6048 | 146ms | my $warn = $SIG{__WARN__} ? $SIG{__WARN__} : sub { warn @_ }; ## no critic | ||
| 157 | # spent 1.15ms (811µs+341µs) within Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:173] which was called 20 times, avg 58µs/call:
# 20 times (811µs+341µs) by Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:187] at line 185, avg 58µs/call | ||||
| 158 | 40 | 188µs | my ($error) = @_; | ||
| 159 | for (@{ $arg->{suppress} }) { | ||||
| 160 | 20 | 1.02ms | 40 | 341µs | return if $error =~ $_; # spent 220µs making 20 calls to Sub::Install::CORE:match, avg 11µs/call
# spent 122µs making 20 calls to Sub::Install::CORE:regcomp, avg 6µs/call |
| 161 | } | ||||
| 162 | for (@{ $arg->{croak} }) { | ||||
| 163 | if (my ($base_error) = $error =~ /\A($_) $eow_re/x) { | ||||
| 164 | Carp::croak $base_error; | ||||
| 165 | } | ||||
| 166 | } | ||||
| 167 | for (@{ $arg->{carp} }) { | ||||
| 168 | if (my ($base_error) = $error =~ /\A($_) $eow_re/x) { | ||||
| 169 | return $warn->(Carp::shortmess $base_error); | ||||
| 170 | } | ||||
| 171 | } | ||||
| 172 | ($arg->{default} || $warn)->($error); | ||||
| 173 | }; | ||||
| 174 | 2016 | 62.5ms | $code->(@_); # spent 62.5ms making 2016 calls to Sub::Install::__ANON__[Sub/Install.pm:187], avg 31µs/call | ||
| 175 | }; | ||||
| 176 | }; | ||||
| 177 | 1 | 23µs | return $wants_code->($code) if $code; # spent 23µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:176] | ||
| 178 | return $wants_code; | ||||
| 179 | } | ||||
| 180 | |||||
| 181 | sub _installer { | ||||
| 182 | # spent 62.5ms (61.3+1.15) within Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:187] which was called 2016 times, avg 31µs/call:
# 2016 times (61.3ms+1.15ms) by Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:175] at line 174, avg 31µs/call | ||||
| 183 | 6048 | 71.0ms | my ($pkg, $name, $code) = @_; | ||
| 184 | 3 | 474µs | 2 | 190µs | # spent 115µs (40+75) within Sub::Install::BEGIN@184 which was called:
# once (40µs+75µs) by Data::OptList::BEGIN@8 at line 184 # spent 115µs making 1 call to Sub::Install::BEGIN@184
# spent 75µs making 1 call to strict::unimport |
| 185 | 1 | 144µs | 20 | 1.15ms | *{"$pkg\::$name"} = $code; # spent 1.15ms making 20 calls to Sub::Install::__ANON__[Sub/Install.pm:173], avg 58µs/call |
| 186 | return $code; | ||||
| 187 | } | ||||
| 188 | 3 | 62µs | } | ||
| 189 | |||||
| 190 | # spent 440µs (186+254) within Sub::Install::BEGIN@190 which was called:
# once (186µs+254µs) by Data::OptList::BEGIN@8 at line 208 | ||||
| 191 | 5 | 122µs | 1 | 28µs | *_ignore_warnings = _do_with_warn({ # spent 28µs making 1 call to Sub::Install::_do_with_warn |
| 192 | carp => [ $_misc_warn_re, $_redef_warn_re ] | ||||
| 193 | }); | ||||
| 194 | |||||
| 195 | 3 | 71µs | *install_sub = _build_public_installer(_ignore_warnings(_installer)); # spent 30µs making 1 call to Sub::Install::_build_public_installer
# spent 27µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:176]
# spent 14µs making 1 call to Sub::Install::_installer | ||
| 196 | |||||
| 197 | 1 | 23µs | *_carp_warnings = _do_with_warn({ # spent 23µs making 1 call to Sub::Install::_do_with_warn | ||
| 198 | carp => [ $_misc_warn_re ], | ||||
| 199 | suppress => [ $_redef_warn_re ], | ||||
| 200 | }); | ||||
| 201 | |||||
| 202 | 3 | 52µs | *reinstall_sub = _build_public_installer(_carp_warnings(_installer)); # spent 19µs making 1 call to Sub::Install::_installer
# spent 17µs making 1 call to Sub::Install::_build_public_installer
# spent 16µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:176] | ||
| 203 | |||||
| 204 | 2 | 80µs | *_install_fatal = _do_with_warn({ # spent 68µs making 1 call to Sub::Install::_do_with_warn
# spent 12µs making 1 call to Sub::Install::_installer | ||
| 205 | code => _installer, | ||||
| 206 | croak => [ $_redef_warn_re ], | ||||
| 207 | }); | ||||
| 208 | 1 | 989µs | 1 | 440µs | } # spent 440µs making 1 call to Sub::Install::BEGIN@190 |
| 209 | |||||
| 210 | =head2 install_installers | ||||
| 211 | |||||
| - - | |||||
| 233 | sub install_installers { | ||||
| 234 | my ($into) = @_; | ||||
| 235 | |||||
| 236 | for my $method (qw(install_sub reinstall_sub)) { | ||||
| 237 | my $code = sub { | ||||
| 238 | my ($package, $subs) = @_; | ||||
| 239 | my ($caller) = caller(0); | ||||
| 240 | my $return; | ||||
| 241 | for (my ($name, $sub) = %$subs) { | ||||
| 242 | $return = Sub::Install->can($method)->({ | ||||
| 243 | code => $sub, | ||||
| 244 | from => $caller, | ||||
| 245 | into => $package, | ||||
| 246 | as => $name | ||||
| 247 | }); | ||||
| 248 | } | ||||
| 249 | return $return; | ||||
| 250 | }; | ||||
| 251 | install_sub({ code => $code, into => $into, as => $method }); | ||||
| 252 | } | ||||
| 253 | } | ||||
| 254 | |||||
| 255 | =head1 EXPORTS | ||||
| 256 | |||||
| - - | |||||
| 272 | # spent 67µs within Sub::Install::exporter which was called 2 times, avg 34µs/call:
# once (35µs+0s) by Data::OptList::BEGIN@214 at line 215 of Data/OptList.pm
# once (32µs+0s) by Sub::Install::BEGIN@287 at line 287 | ||||
| 273 | 6 | 109µs | my ($arg) = @_; | ||
| 274 | |||||
| 275 | my %is_exported = map { $_ => undef } @{ $arg->{exports} }; | ||||
| 276 | |||||
| 277 | # spent 91µs within Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:284] which was called 4 times, avg 23µs/call:
# once (24µs+0s) by Class::MOP::BEGIN@13 at line 13 of Class/MOP.pm
# once (24µs+0s) by Moose::Meta::Class::BEGIN@10 at line 10 of Moose/Meta/Class.pm
# once (22µs+0s) by Moose::Util::BEGIN@6 at line 6 of Moose/Util.pm
# once (21µs+0s) by Package::DeprecationManager::BEGIN@12 at line 12 of Package/DeprecationManager.pm | ||||
| 278 | 12 | 132µs | my $class = shift; | ||
| 279 | my $target = caller; | ||||
| 280 | for (@_) { | ||||
| 281 | Carp::croak "'$_' is not exported by $class" if !exists $is_exported{$_}; | ||||
| 282 | install_sub({ code => $_, from => $class, into => $target }); | ||||
| 283 | } | ||||
| 284 | } | ||||
| 285 | } | ||||
| 286 | |||||
| 287 | 1 | 135µs | 2 | 119µs | # spent 87µs (54+32) within Sub::Install::BEGIN@287 which was called:
# once (54µs+32µs) by Data::OptList::BEGIN@8 at line 287 # spent 87µs making 1 call to Sub::Install::BEGIN@287
# spent 32µs making 1 call to Sub::Install::exporter |
| 288 | |||||
| 289 | =head1 SEE ALSO | ||||
| 290 | |||||
| - - | |||||
| 329 | 1 | 12µs | 1; | ||
# spent 220µs within Sub::Install::CORE:match which was called 20 times, avg 11µs/call:
# 20 times (220µs+0s) by Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:173] at line 160, avg 11µs/call | |||||
sub Sub::Install::CORE:qr; # opcode | |||||
# spent 122µs within Sub::Install::CORE:regcomp which was called 20 times, avg 6µs/call:
# 20 times (122µs+0s) by Sub::Install::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Sub/Install.pm:173] at line 160, avg 6µs/call |