← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Install.pm
StatementsExecuted 154 statements in 1.31ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
61188µs119µsSub::Install::::__ANON__[:100] Sub::Install::__ANON__[:100]
62177µs231µsSub::Install::::__ANON__[:57] Sub::Install::__ANON__[:57]
11138µs74µsSub::Install::::BEGIN@115 Sub::Install::BEGIN@115
61131µs31µsSub::Install::::__ANON__[:112] Sub::Install::__ANON__[:112]
61123µs36µsSub::Install::::_CODELIKE Sub::Install::_CODELIKE
33114µs18µsSub::Install::::_do_with_warn Sub::Install::_do_with_warn
22212µs12µsSub::Install::::exporter Sub::Install::exporter
11112µs14µsSub::Install::::BEGIN@64 Sub::Install::BEGIN@64
11110µs21µsData::OptList::::BEGIN@1Data::OptList::BEGIN@1
1119µs15µsSub::Install::::BEGIN@174 Sub::Install::BEGIN@174
3318µs8µsSub::Install::::__ANON__[:101] Sub::Install::__ANON__[:101]
1118µs19µsSub::Install::::BEGIN@109 Sub::Install::BEGIN@109
1118µs41µsSub::Install::::BEGIN@9 Sub::Install::BEGIN@9
2217µs7µsSub::Install::::_build_public_installer Sub::Install::_build_public_installer
1117µs10µsData::OptList::::BEGIN@2Data::OptList::BEGIN@2
1116µs7µsSub::Install::::BEGIN@73 Sub::Install::BEGIN@73
3316µs6µsSub::Install::::_installer Sub::Install::_installer
3313µs3µsSub::Install::::CORE:qr Sub::Install::CORE:qr (opcode)
1113µs3µsSub::Install::::BEGIN@10 Sub::Install::BEGIN@10
0000s0sSub::Install::::__ANON__[:153] Sub::Install::__ANON__[:153]
0000s0sSub::Install::::__ANON__[:171] Sub::Install::__ANON__[:171]
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
1217µs232µs
# spent 21µs (10+11) within Data::OptList::BEGIN@1 which was called: # once (10µs+11µs) by Data::OptList::BEGIN@11 at line 1
use strict;
# spent 21µs making 1 call to Data::OptList::BEGIN@1 # spent 11µs making 1 call to strict::import
2231µs213µs
# spent 10µs (7+3) within Data::OptList::BEGIN@2 which was called: # once (7µs+3µs) by Data::OptList::BEGIN@11 at line 2
use warnings;
# spent 10µs making 1 call to Data::OptList::BEGIN@2 # spent 3µs making 1 call to warnings::import
3package Sub::Install;
4{
52900ns $Sub::Install::VERSION = '0.927';
6}
7# ABSTRACT: install subroutines into packages easily
8
9219µs275µs
# spent 41µs (8+34) within Sub::Install::BEGIN@9 which was called: # once (8µs+34µs) by Data::OptList::BEGIN@11 at line 9
use Carp;
# spent 41µs making 1 call to Sub::Install::BEGIN@9 # spent 34µs making 1 call to Exporter::import
102307µs13µs
# spent 3µs within Sub::Install::BEGIN@10 which was called: # once (3µs+0s) by Data::OptList::BEGIN@11 at line 10
use Scalar::Util ();
# spent 3µ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 36µs (23+13) within Sub::Install::_CODELIKE which was called 6 times, avg 6µs/call: # 6 times (23µs+13µs) by Sub::Install::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Install.pm:57] at line 42, avg 6µs/call
sub _CODELIKE {
23643µs612µs (Scalar::Util::reftype($_[0])||'') eq 'CODE'
# spent 12µs making 6 calls to Scalar::Util::reftype, avg 2µs/call
24 || Scalar::Util::blessed($_[0])
25 && (overload::Method($_[0],'&{}') ? $_[0] : undef);
26}
27
28# do the heavy lifting
29
# spent 7µs within Sub::Install::_build_public_installer which was called 2 times, avg 4µs/call: # once (5µs+0s) by Sub::Install::BEGIN@115 at line 120 # once (2µs+0s) by Sub::Install::BEGIN@115 at line 127
sub _build_public_installer {
302400ns my ($installer) = @_;
31
32
# spent 231µs (77+155) within Sub::Install::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Install.pm:57] which was called 6 times, avg 39µs/call: # 5 times (60µs+114µs) by Sub::Exporter::default_installer at line 442 of Sub/Exporter.pm, avg 35µs/call # once (17µs+40µs) by Sub::Exporter::setup_exporter at line 198 of Sub/Exporter.pm
sub {
3361µs my ($arg) = @_;
34618µs my ($calling_pkg) = caller(0);
35
36 # I'd rather use ||= but I'm whoring for Devel::Cover.
371811µs for (qw(into from)) { $arg->{$_} = $calling_pkg unless $arg->{$_} }
38
39 # This is the only absolutely required argument, in many cases.
4061µs Carp::croak "named argument 'code' is not optional" unless $arg->{code};
41
4268µs636µs if (_CODELIKE($arg->{code})) {
# spent 36µs making 6 calls to Sub::Install::_CODELIKE, avg 6µs/call
43 $arg->{as} ||= _name_of_code($arg->{code});
44 } else {
45 Carp::croak
46 "couldn't find subroutine named $arg->{code} in package $arg->{from}"
47 unless my $code = $arg->{from}->can($arg->{code});
48
49 $arg->{as} = $arg->{code} unless $arg->{as};
50 $arg->{code} = $code;
51 }
52
536800ns Carp::croak "couldn't determine name under which to install subroutine"
54 unless $arg->{as};
55
56621µs6119µs $installer->(@$arg{qw(into as code) });
# spent 119µs making 6 calls to Sub::Install::__ANON__[Sub/Install.pm:100], avg 20µs/call
57 }
58211µs}
59
60# do the ugly work
61
621100nsmy $_misc_warn_re;
6310smy $_redef_warn_re;
64
# spent 14µs (12+2) within Sub::Install::BEGIN@64 which was called: # once (12µs+2µs) by Data::OptList::BEGIN@11 at line 70
BEGIN {
6517µs11µs $_misc_warn_re = qr/
# spent 1µs making 1 call to Sub::Install::CORE:qr
66 Prototype\ mismatch:\ sub\ .+? |
67 Constant subroutine \S+ redefined
68 /x;
6919µs1800ns $_redef_warn_re = qr/Subroutine\ \S+\ redefined/x;
# spent 800ns making 1 call to Sub::Install::CORE:qr
70129µs114µs}
# spent 14µs making 1 call to Sub::Install::BEGIN@64
71
7210smy $eow_re;
731238µs28µs
# spent 7µs (6+1) within Sub::Install::BEGIN@73 which was called: # once (6µs+1µs) by Data::OptList::BEGIN@11 at line 73
BEGIN { $eow_re = qr/ at .+? line \d+\.\Z/ };
# spent 7µs making 1 call to Sub::Install::BEGIN@73 # spent 1µs making 1 call to Sub::Install::CORE:qr
74
75
# spent 18µs (14+4) within Sub::Install::_do_with_warn which was called 3 times, avg 6µs/call: # once (6µs+4µs) by Sub::Install::BEGIN@115 at line 129 # once (5µs+0s) by Sub::Install::BEGIN@115 at line 116 # once (3µs+0s) by Sub::Install::BEGIN@115 at line 122
sub _do_with_warn {
763700ns my ($arg) = @_;
7732µs my $code = delete $arg->{code};
78
# spent 8µs within Sub::Install::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Install.pm:101] which was called 3 times, avg 3µs/call: # once (4µs+0s) by Sub::Install::_do_with_warn at line 102 # once (2µs+0s) by Sub::Install::BEGIN@115 at line 120 # once (2µs+0s) by Sub::Install::BEGIN@115 at line 127
my $wants_code = sub {
793400ns my $code = shift;
80
# spent 119µs (88+31) within Sub::Install::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Install.pm:100] which was called 6 times, avg 20µs/call: # 6 times (88µs+31µs) by Sub::Install::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Install.pm:57] at line 56, avg 20µs/call
sub {
81614µ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);
98622µs };
99649µs631µs $code->(@_);
# spent 31µs making 6 calls to Sub::Install::__ANON__[Sub/Install.pm:112], avg 5µs/call
100313µs };
10134µs };
10236µs14µs return $wants_code->($code) if $code;
# spent 4µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:101]
10327µs return $wants_code;
104}
105
106
# spent 6µs within Sub::Install::_installer which was called 3 times, avg 2µs/call: # once (2µ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 31µs within Sub::Install::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Install.pm:112] which was called 6 times, avg 5µs/call: # 6 times (31µs+0s) by Sub::Install::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Install.pm:100] at line 99, avg 5µs/call
sub {
10862µs my ($pkg, $name, $code) = @_;
1092110µs230µs
# spent 19µs (8+11) within Sub::Install::BEGIN@109 which was called: # once (8µs+11µs) by Data::OptList::BEGIN@11 at line 109
no strict 'refs'; ## no critic ProhibitNoStrict
# spent 19µs making 1 call to Sub::Install::BEGIN@109 # spent 11µs making 1 call to strict::unimport
110619µs *{"$pkg\::$name"} = $code;
111616µs return $code;
112 }
113310µs}
114
115
# spent 74µs (38+35) within Sub::Install::BEGIN@115 which was called: # once (38µs+35µs) by Data::OptList::BEGIN@11 at line 133
BEGIN {
11613µs15µs *_ignore_warnings = _do_with_warn({
# spent 5µs making 1 call to Sub::Install::_do_with_warn
117 carp => [ $_misc_warn_re, $_redef_warn_re ]
118 });
119
12013µs310µs *install_sub = _build_public_installer(_ignore_warnings(_installer));
# spent 5µs making 1 call to Sub::Install::_build_public_installer # spent 2µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:101] # spent 2µs making 1 call to Sub::Install::_installer
121
12212µs13µs *_carp_warnings = _do_with_warn({
# spent 3µs making 1 call to Sub::Install::_do_with_warn
123 carp => [ $_misc_warn_re ],
124 suppress => [ $_redef_warn_re ],
125 });
126
12713µs36µs *reinstall_sub = _build_public_installer(_carp_warnings(_installer));
# spent 2µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:101] # spent 2µs making 1 call to Sub::Install::_build_public_installer # spent 2µs making 1 call to Sub::Install::_installer
128
12915µs212µs *_install_fatal = _do_with_warn({
# spent 10µ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 });
1331197µs174µs}
# spent 74µ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 12µs within Sub::Install::exporter which was called 2 times, avg 6µs/call: # once (6µs+0s) by Sub::Install::BEGIN@174 at line 174 # once (6µs+0s) by Data::OptList::BEGIN@100 at line 101 of Data/OptList.pm
sub exporter {
1602700ns my ($arg) = @_;
161
16226µs my %is_exported = map { $_ => undef } @{ $arg->{exports} };
163
164 sub {
165 my $class = shift;
166 my $target = caller;
167 for (@_) {
168 Carp::croak "'$_' is not exported by $class" if !exists $is_exported{$_};
169 install_sub({ code => $_, from => $class, into => $target });
170 }
171 }
172214µs}
173
174126µs221µs
# spent 15µs (9+6) within Sub::Install::BEGIN@174 which was called: # once (9µs+6µs) by Data::OptList::BEGIN@11 at line 174
BEGIN { *import = exporter({ exports => [ qw(install_sub reinstall_sub) ] }); }
# spent 15µs making 1 call to Sub::Install::BEGIN@174 # spent 6µs making 1 call to Sub::Install::exporter
175
176
17713µs1;
178
179__END__
 
# spent 3µs within Sub::Install::CORE:qr which was called 3 times, avg 1µs/call: # once (1µs+0s) by Sub::Install::BEGIN@64 at line 65 # once (1µs+0s) by Sub::Install::BEGIN@73 at line 73 # once (800ns+0s) by Sub::Install::BEGIN@64 at line 69
sub Sub::Install::CORE:qr; # opcode