← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:40 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/Sub/Install.pm
StatementsExecuted 734 statements in 3.47ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
4111745µs950µsSub::Install::::__ANON__[:100] Sub::Install::__ANON__[:100]
4153633µs1.80msSub::Install::::__ANON__[:57] Sub::Install::__ANON__[:57]
4111205µs205µsSub::Install::::__ANON__[:112] Sub::Install::__ANON__[:112]
4111177µs214µsSub::Install::::_CODELIKE Sub::Install::_CODELIKE
11156µs104µsSub::Install::::BEGIN@115 Sub::Install::BEGIN@115
55529µs108µsSub::Install::::__ANON__[:171] Sub::Install::__ANON__[:171]
22224µs24µsSub::Install::::exporter Sub::Install::exporter
33119µs22µsSub::Install::::_do_with_warn Sub::Install::_do_with_warn
11116µs19µsSub::Install::::BEGIN@64 Sub::Install::BEGIN@64
11115µs32µsData::OptList::::BEGIN@1Data::OptList::BEGIN@1
22114µs14µsSub::Install::::_build_public_installer Sub::Install::_build_public_installer
11113µs28µsSub::Install::::BEGIN@174 Sub::Install::BEGIN@174
1119µs14µsData::OptList::::BEGIN@2Data::OptList::BEGIN@2
1119µs50µsSub::Install::::BEGIN@9 Sub::Install::BEGIN@9
1119µs23µsSub::Install::::BEGIN@109 Sub::Install::BEGIN@109
3319µs9µsSub::Install::::__ANON__[:101] Sub::Install::__ANON__[:101]
1118µs10µsSub::Install::::BEGIN@73 Sub::Install::BEGIN@73
3318µs8µsSub::Install::::_installer Sub::Install::_installer
3315µs5µsSub::Install::::CORE:qr Sub::Install::CORE:qr (opcode)
1114µs4µsSub::Install::::BEGIN@10 Sub::Install::BEGIN@10
0000s0sSub::Install::::__ANON__[:153] Sub::Install::__ANON__[:153]
0000s0sSub::Install::::__ANON__[:81] Sub::Install::__ANON__[:81]
0000s0sSub::Install::::__ANON__[:98] Sub::Install::__ANON__[:98]
0000s0sSub::Install::::_name_of_code Sub::Install::_name_of_code
0000s0sSub::Install::::install_installers Sub::Install::install_installers
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1231µs248µs
# spent 32µs (15+17) within Data::OptList::BEGIN@1 which was called: # once (15µs+17µs) by Data::OptList::BEGIN@11 at line 1
use strict;
# spent 32µs making 1 call to Data::OptList::BEGIN@1 # spent 17µs making 1 call to strict::import
2252µs219µs
# spent 14µs (9+5) within Data::OptList::BEGIN@2 which was called: # once (9µs+5µs) by Data::OptList::BEGIN@11 at line 2
use warnings;
# spent 14µs making 1 call to Data::OptList::BEGIN@2 # spent 5µs making 1 call to warnings::import
3package Sub::Install;
4{
521µs $Sub::Install::VERSION = '0.927';
6}
7# ABSTRACT: install subroutines into packages easily
8
9238µs291µs
# spent 50µs (9+41) within Sub::Install::BEGIN@9 which was called: # once (9µs+41µs) by Data::OptList::BEGIN@11 at line 9
use Carp;
# spent 50µs making 1 call to Sub::Install::BEGIN@9 # spent 41µs making 1 call to Exporter::import
102456µs14µs
# spent 4µs within Sub::Install::BEGIN@10 which was called: # once (4µs+0s) by Data::OptList::BEGIN@11 at line 10
use Scalar::Util ();
# spent 4µs making 1 call to Sub::Install::BEGIN@10
11
12
13sub _name_of_code {
14 my ($code) = @_;
15 require B;
16 my $name = B::svref_2object($code)->GV->NAME;
17 return $name unless $name =~ /\A__ANON__/;
18 return;
19}
20
21# See also Params::Util, to which this code was donated.
22
# spent 214µs (177+36) within Sub::Install::_CODELIKE which was called 41 times, avg 5µs/call: # 41 times (177µs+36µs) by Sub::Install::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Sub/Install.pm:57] at line 42, avg 5µs/call
sub _CODELIKE {
2341249µs4236µs (Scalar::Util::reftype($_[0])||'') eq 'CODE'
# spent 36µs making 41 calls to Scalar::Util::reftype, avg 871ns/call # spent 700ns making 1 call to Scalar::Util::blessed
24 || Scalar::Util::blessed($_[0])
25 && (overload::Method($_[0],'&{}') ? $_[0] : undef);
26}
27
28# do the heavy lifting
29
# spent 14µs within Sub::Install::_build_public_installer which was called 2 times, avg 7µs/call: # once (10µs+0s) by Sub::Install::BEGIN@115 at line 120 # once (3µs+0s) by Sub::Install::BEGIN@115 at line 127
sub _build_public_installer {
302500ns my ($installer) = @_;
31
32
# spent 1.80ms (633µs+1.16) within Sub::Install::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Sub/Install.pm:57] which was called 41 times, avg 44µs/call: # 34 times (491µs+914µs) by Sub::Exporter::default_installer at line 442 of Sub/Exporter.pm, avg 41µs/call # 2 times (46µs+83µs) by Package::DeprecationManager::import at line 29 of Package/DeprecationManager.pm, avg 64µs/call # 2 times (41µs+68µs) by Sub::Exporter::setup_exporter at line 198 of Sub/Exporter.pm, avg 55µs/call # 2 times (27µs+49µs) by Package::DeprecationManager::import at line 37 of Package/DeprecationManager.pm, avg 38µs/call # once (28µs+51µs) by Sub::Install::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Sub/Install.pm:171] at line 169
sub {
33419µs my ($arg) = @_;
3441161µs my ($calling_pkg) = caller(0);
35
36 # I'd rather use ||= but I'm whoring for Devel::Cover.
3712394µs for (qw(into from)) { $arg->{$_} = $calling_pkg unless $arg->{$_} }
38
39 # This is the only absolutely required argument, in many cases.
404112µs Carp::croak "named argument 'code' is not optional" unless $arg->{code};
41
424163µs41214µs if (_CODELIKE($arg->{code})) {
# spent 214µs making 41 calls to Sub::Install::_CODELIKE, avg 5µs/call
43 $arg->{as} ||= _name_of_code($arg->{code});
44 } else {
4519µs12µs Carp::croak
# spent 2µs making 1 call to UNIVERSAL::can
46 "couldn't find subroutine named $arg->{code} in package $arg->{from}"
47 unless my $code = $arg->{from}->can($arg->{code});
48
491900ns $arg->{as} = $arg->{code} unless $arg->{as};
501700ns $arg->{code} = $code;
51 }
52
53418µs Carp::croak "couldn't determine name under which to install subroutine"
54 unless $arg->{as};
55
5641165µs41950µs $installer->(@$arg{qw(into as code) });
# spent 950µs making 41 calls to Sub::Install::__ANON__[Sub/Install.pm:100], avg 23µs/call
57 }
58218µs}
59
60# do the ugly work
61
621100nsmy $_misc_warn_re;
6310smy $_redef_warn_re;
64
# spent 19µs (16+4) within Sub::Install::BEGIN@64 which was called: # once (16µs+4µs) by Data::OptList::BEGIN@11 at line 70
BEGIN {
65110µs12µs $_misc_warn_re = qr/
# spent 2µs making 1 call to Sub::Install::CORE:qr
66 Prototype\ mismatch:\ sub\ .+? |
67 Constant subroutine \S+ redefined
68 /x;
6918µs11µs $_redef_warn_re = qr/Subroutine\ \S+\ redefined/x;
# spent 1µs making 1 call to Sub::Install::CORE:qr
70144µs119µs}
# spent 19µs making 1 call to Sub::Install::BEGIN@64
71
7210smy $eow_re;
731362µs211µs
# spent 10µs (8+2) within Sub::Install::BEGIN@73 which was called: # once (8µs+2µs) by Data::OptList::BEGIN@11 at line 73
BEGIN { $eow_re = qr/ at .+? line \d+\.\Z/ };
# spent 10µs making 1 call to Sub::Install::BEGIN@73 # spent 2µs making 1 call to Sub::Install::CORE:qr
74
75
# spent 22µs (19+3) within Sub::Install::_do_with_warn which was called 3 times, avg 7µs/call: # once (8µs+3µs) by Sub::Install::BEGIN@115 at line 129 # once (6µs+0s) by Sub::Install::BEGIN@115 at line 116 # once (4µs+0s) by Sub::Install::BEGIN@115 at line 122
sub _do_with_warn {
763900ns my ($arg) = @_;
7732µs my $code = delete $arg->{code};
78
# spent 9µs within Sub::Install::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Sub/Install.pm:101] which was called 3 times, avg 3µs/call: # once (3µs+0s) by Sub::Install::BEGIN@115 at line 120 # once (3µs+0s) by Sub::Install::_do_with_warn at line 102 # once (3µs+0s) by Sub::Install::BEGIN@115 at line 127
my $wants_code = sub {
793600ns my $code = shift;
80
# spent 950µs (745+205) within Sub::Install::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Sub/Install.pm:100] which was called 41 times, avg 23µs/call: # 41 times (745µs+205µs) by Sub::Install::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Sub/Install.pm:57] at line 56, avg 23µs/call
sub {
8141101µs my $warn = $SIG{__WARN__} ? $SIG{__WARN__} : sub { warn @_ }; ## no critic
82 local $SIG{__WARN__} = sub {
83 my ($error) = @_;
84 for (@{ $arg->{suppress} }) {
85 return if $error =~ $_;
86 }
87 for (@{ $arg->{croak} }) {
88 if (my ($base_error) = $error =~ /\A($_) $eow_re/x) {
89 Carp::croak $base_error;
90 }
91 }
92 for (@{ $arg->{carp} }) {
93 if (my ($base_error) = $error =~ /\A($_) $eow_re/x) {
94 return $warn->(Carp::shortmess $base_error);
95 }
96 }
97 ($arg->{default} || $warn)->($error);
9841177µs };
9941423µs41205µs $code->(@_);
# spent 205µs making 41 calls to Sub::Install::__ANON__[Sub/Install.pm:112], avg 5µs/call
100320µs };
10137µs };
10235µs13µs return $wants_code->($code) if $code;
# spent 3µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:101]
103210µs return $wants_code;
104}
105
106
# spent 8µs within Sub::Install::_installer which was called 3 times, avg 3µs/call: # once (3µs+0s) by Sub::Install::BEGIN@115 at line 120 # once (2µs+0s) by Sub::Install::BEGIN@115 at line 127 # once (2µs+0s) by Sub::Install::BEGIN@115 at line 129
sub _installer {
107
# spent 205µs within Sub::Install::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Sub/Install.pm:112] which was called 41 times, avg 5µs/call: # 41 times (205µs+0s) by Sub::Install::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Sub/Install.pm:100] at line 99, avg 5µs/call
sub {
1084117µs my ($pkg, $name, $code) = @_;
1092176µs237µs
# spent 23µs (9+14) within Sub::Install::BEGIN@109 which was called: # once (9µs+14µs) by Data::OptList::BEGIN@11 at line 109
no strict 'refs'; ## no critic ProhibitNoStrict
# spent 23µs making 1 call to Sub::Install::BEGIN@109 # spent 14µs making 1 call to strict::unimport
11041123µs *{"$pkg\::$name"} = $code;
11141134µs return $code;
112 }
113314µs}
114
115
# spent 104µs (56+49) within Sub::Install::BEGIN@115 which was called: # once (56µs+49µs) by Data::OptList::BEGIN@11 at line 133
BEGIN {
11613µs16µs *_ignore_warnings = _do_with_warn({
# spent 6µs making 1 call to Sub::Install::_do_with_warn
117 carp => [ $_misc_warn_re, $_redef_warn_re ]
118 });
119
12014µs316µs *install_sub = _build_public_installer(_ignore_warnings(_installer));
# spent 10µs making 1 call to Sub::Install::_build_public_installer # spent 3µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:101] # spent 3µs making 1 call to Sub::Install::_installer
121
12213µs14µs *_carp_warnings = _do_with_warn({
# spent 4µs making 1 call to Sub::Install::_do_with_warn
123 carp => [ $_misc_warn_re ],
124 suppress => [ $_redef_warn_re ],
125 });
126
12713µs39µs *reinstall_sub = _build_public_installer(_carp_warnings(_installer));
# spent 3µs making 1 call to Sub::Install::_build_public_installer # spent 3µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:101] # spent 2µs making 1 call to Sub::Install::_installer
128
129110µs213µs *_install_fatal = _do_with_warn({
# spent 11µs making 1 call to Sub::Install::_do_with_warn # spent 2µs making 1 call to Sub::Install::_installer
130 code => _installer,
131 croak => [ $_redef_warn_re ],
132 });
1331317µs1104µs}
# spent 104µs making 1 call to Sub::Install::BEGIN@115
134
135
136sub install_installers {
137 my ($into) = @_;
138
139 for my $method (qw(install_sub reinstall_sub)) {
140 my $code = sub {
141 my ($package, $subs) = @_;
142 my ($caller) = caller(0);
143 my $return;
144 for (my ($name, $sub) = %$subs) {
145 $return = Sub::Install->can($method)->({
146 code => $sub,
147 from => $caller,
148 into => $package,
149 as => $name
150 });
151 }
152 return $return;
153 };
154 install_sub({ code => $code, into => $into, as => $method });
155 }
156}
157
158
159
# spent 24µs within Sub::Install::exporter which was called 2 times, avg 12µs/call: # once (15µs+0s) by Sub::Install::BEGIN@174 at line 174 # once (9µs+0s) by Data::OptList::BEGIN@100 at line 101 of Data/OptList.pm
sub exporter {
16021µs my ($arg) = @_;
161
16228µs my %is_exported = map { $_ => undef } @{ $arg->{exports} };
163
164
# spent 108µs (29+79) within Sub::Install::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Sub/Install.pm:171] which was called 5 times, avg 22µs/call: # once (12µs+79µs) by Class::Load::BEGIN@8 at line 8 of Class/Load.pm # once (5µs+0s) by Moose::Meta::Class::BEGIN@16 at line 16 of Moose/Meta/Class.pm # once (4µs+0s) by Package::DeprecationManager::BEGIN@12 at line 12 of Package/DeprecationManager.pm # once (4µs+0s) by Class::MOP::BEGIN@20 at line 20 of Class/MOP.pm # once (4µs+0s) by Moose::Util::BEGIN@13 at line 13 of Moose/Util.pm
sub {
16552µs my $class = shift;
16653µs my $target = caller;
167529µs for (@_) {
1681500ns Carp::croak "'$_' is not exported by $class" if !exists $is_exported{$_};
16915µs179µs install_sub({ code => $_, from => $class, into => $target });
# spent 79µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:57]
170 }
171 }
172229µs}
173
174144µs244µs
# spent 28µs (13+15) within Sub::Install::BEGIN@174 which was called: # once (13µs+15µs) by Data::OptList::BEGIN@11 at line 174
BEGIN { *import = exporter({ exports => [ qw(install_sub reinstall_sub) ] }); }
# spent 28µs making 1 call to Sub::Install::BEGIN@174 # spent 15µs making 1 call to Sub::Install::exporter
175
176
17714µs1;
178
179__END__
 
# spent 5µs within Sub::Install::CORE:qr which was called 3 times, avg 2µs/call: # once (2µs+0s) by Sub::Install::BEGIN@64 at line 65 # once (2µs+0s) by Sub::Install::BEGIN@73 at line 73 # once (1µs+0s) by Sub::Install::BEGIN@64 at line 69
sub Sub::Install::CORE:qr; # opcode