← 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:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/Exporter/Tiny.pm
StatementsExecuted 1781 statements in 5.11ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
995910µs4.84msExporter::Tiny::::importExporter::Tiny::import
5311808µs954µsExporter::Tiny::::_exporter_install_subExporter::Tiny::_exporter_install_sub
5322600µs1.07msExporter::Tiny::::_exporter_expand_subExporter::Tiny::_exporter_expand_sub
6221360µs360µsExporter::Tiny::::CORE:regcompExporter::Tiny::CORE:regcomp (opcode)
922154µs496µsExporter::Tiny::::_exporter_permitted_regexpExporter::Tiny::_exporter_permitted_regexp
10821138µs138µsExporter::Tiny::::CORE:matchExporter::Tiny::CORE:match (opcode)
91192µs92µsExporter::Tiny::::mkoptExporter::Tiny::mkopt
91150µs50µsExporter::Tiny::::CORE:sortExporter::Tiny::CORE:sort (opcode)
11120µs20µsExporter::Tiny::::BEGIN@3Exporter::Tiny::BEGIN@3
91116µs16µsExporter::Tiny::::CORE:qrExporter::Tiny::CORE:qr (opcode)
11114µs28µsExporter::Tiny::::BEGIN@60Exporter::Tiny::BEGIN@60
11114µs18µsExporter::Tiny::::BEGIN@5Exporter::Tiny::BEGIN@5
11110µs28µsExporter::Tiny::::BEGIN@5.2Exporter::Tiny::BEGIN@5.2
92210µs10µsExporter::Tiny::::_exporter_validate_optsExporter::Tiny::_exporter_validate_opts
1119µs23µsExporter::Tiny::::BEGIN@104Exporter::Tiny::BEGIN@104
1119µs22µsExporter::Tiny::::BEGIN@87Exporter::Tiny::BEGIN@87
1119µs23µsExporter::Tiny::::BEGIN@160Exporter::Tiny::BEGIN@160
1119µs24µsExporter::Tiny::::BEGIN@17Exporter::Tiny::BEGIN@17
1119µs9µsExporter::Tiny::::_exporter_expand_tagExporter::Tiny::_exporter_expand_tag
1118µs24µsExporter::Tiny::::BEGIN@4Exporter::Tiny::BEGIN@4
0000s0sExporter::Tiny::::_croakExporter::Tiny::_croak
0000s0sExporter::Tiny::::_exporter_failExporter::Tiny::_exporter_fail
0000s0sExporter::Tiny::::mkopt_hashExporter::Tiny::mkopt_hash
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Exporter::Tiny;
2
3258µs120µs
# spent 20µs within Exporter::Tiny::BEGIN@3 which was called: # once (20µs+0s) by Eval::TypeTiny::import at line 3
use 5.006001;
# spent 20µs making 1 call to Exporter::Tiny::BEGIN@3
4237µs240µs
# spent 24µs (8+16) within Exporter::Tiny::BEGIN@4 which was called: # once (8µs+16µs) by Eval::TypeTiny::import at line 4
use strict;
# spent 24µs making 1 call to Exporter::Tiny::BEGIN@4 # spent 16µs making 1 call to strict::import
54201µs468µs
# spent 18µs (14+5) within Exporter::Tiny::BEGIN@5 which was called: # once (14µs+5µs) by Eval::TypeTiny::import at line 5 # spent 28µs (10+18) within Exporter::Tiny::BEGIN@5.2 which was called: # once (10µs+18µs) by Eval::TypeTiny::import at line 5
use warnings; no warnings qw(void once uninitialized numeric redefine);
# spent 28µs making 1 call to Exporter::Tiny::BEGIN@5.2 # spent 18µs making 1 call to Exporter::Tiny::BEGIN@5 # spent 18µs making 1 call to warnings::unimport # spent 5µs making 1 call to warnings::import
6
71800nsour $AUTHORITY = 'cpan:TOBYINK';
81200nsour $VERSION = '0.030';
911µsour @EXPORT_OK = qw< mkopt mkopt_hash _croak >;
10
11sub _croak ($;@) { require Carp; my $fmt = shift; @_ = sprintf($fmt, @_); goto \&Carp::croak }
12
13sub import
14
# spent 4.84ms (910µs+3.93) within Exporter::Tiny::import which was called 9 times, avg 538µs/call: # once (464µs+2.42ms) by Typed::BEGIN@10 at line 10 of Typed.pm # once (87µs+376µs) by Typed::import at line 23 of Typed.pm # once (91µs+270µs) by Typed::import at line 22 of Typed.pm # once (81µs+258µs) by Type::Utils::BEGIN@17 at line 17 of Type/Utils.pm # once (55µs+157µs) by Types::TypeTiny::import at line 26 of Types/TypeTiny.pm # once (34µs+173µs) by Types::Standard::BEGIN@18 at line 18 of Types/Standard.pm # once (58µs+142µs) by Eval::TypeTiny::import at line 42 of Eval/TypeTiny.pm # once (19µs+87µs) by Type::Utils::BEGIN@15 at line 15 of Type/Utils.pm # once (22µs+42µs) by Typed::BEGIN@12 at line 12 of Typed.pm
{
1594µs my $class = shift;
16918µs my $global_opts = +{ @_ && ref($_[0]) eq q(HASH) ? %{+shift} : () };
1720313µs239µs
# spent 24µs (9+15) within Exporter::Tiny::BEGIN@17 which was called: # once (9µs+15µs) by Eval::TypeTiny::import at line 17
my @args = do { no strict qw(refs); @_ ? @_ : @{"$class\::EXPORT"} };
# spent 24µs making 1 call to Exporter::Tiny::BEGIN@17 # spent 15µs making 1 call to strict::unimport
18914µs992µs my $opts = mkopt(\@args);
# spent 92µs making 9 calls to Exporter::Tiny::mkopt, avg 10µs/call
19
20910µs $global_opts->{into} = caller unless exists $global_opts->{into};
2191µs my @want;
22
2393µs while (@$opts)
24 {
255511µs my $opt = shift @{$opts};
265513µs my ($name, $value) = @$opt;
27
2855160µs57101µs $name =~ /^[:-](.+)$/
# spent 71µs making 2 calls to Type::Library::_exporter_expand_tag, avg 35µs/call # spent 30µs making 55 calls to Exporter::Tiny::CORE:match, avg 551ns/call
29 ? push(@$opts, $class->_exporter_expand_tag($1, $value, $global_opts))
30 : push(@want, $opt);
31 }
32
33926µs941µs $class->_exporter_validate_opts($global_opts);
# spent 34µs making 3 calls to Type::Library::_exporter_validate_opts, avg 11µs/call # spent 7µs making 6 calls to Exporter::Tiny::_exporter_validate_opts, avg 1µs/call
34922µs9885µs my $permitted = $class->_exporter_permitted_regexp($global_opts);
# spent 457µs making 3 calls to Type::Library::_exporter_permitted_regexp, avg 152µs/call # spent 428µs making 6 calls to Exporter::Tiny::_exporter_permitted_regexp, avg 71µs/call
35
36979µs for my $wanted (@want)
37 {
3853142µs531.86ms my %symbols = $class->_exporter_expand_sub(@$wanted, $global_opts, $permitted);
# spent 1.48ms making 35 calls to Type::Library::_exporter_expand_sub, avg 42µs/call # spent 380µs making 18 calls to Exporter::Tiny::_exporter_expand_sub, avg 21µs/call
39 $class->_exporter_install_sub($_, $wanted->[1], $global_opts, $symbols{$_})
4053213µs53954µs for keys %symbols;
# spent 954µs making 53 calls to Exporter::Tiny::_exporter_install_sub, avg 18µs/call
41 }
42}
43
44# Called once per import, passed the "global" import options. Expected to
45# validate the import options and carp or croak if there are problems. Can
46# also take the opportunity to do other stuff if needed.
47#
48sub _exporter_validate_opts
49
# spent 10µs within Exporter::Tiny::_exporter_validate_opts which was called 9 times, avg 1µs/call: # 6 times (7µs+0s) by Exporter::Tiny::import at line 33, avg 1µs/call # 3 times (3µs+0s) by Type::Library::_exporter_validate_opts at line 42 of Type/Library.pm, avg 1µs/call
{
50924µs 1;
51}
52
53# Given a tag name, looks it up in %EXPORT_TAGS and returns the list of
54# associated functions. The default implementation magically handles tags
55# "all" and "default". The default implementation interprets any undefined
56# tags as being global options.
57#
58sub _exporter_expand_tag
59
# spent 9µs within Exporter::Tiny::_exporter_expand_tag which was called: # once (9µs+0s) by Type::Library::_exporter_expand_tag at line 73 of Type/Library.pm
{
602220µs242µs
# spent 28µs (14+14) within Exporter::Tiny::BEGIN@60 which was called: # once (14µs+14µs) by Eval::TypeTiny::import at line 60
no strict qw(refs);
# spent 28µs making 1 call to Exporter::Tiny::BEGIN@60 # spent 14µs making 1 call to strict::unimport
61
621500ns my $class = shift;
631800ns my ($name, $value, $globals) = @_;
6414µs my $tags = \%{"$class\::EXPORT_TAGS"};
65
661700ns return map [$_ => $value], $tags->{$name}->($class, @_)
67 if ref($tags->{$name}) eq q(CODE);
68
691400ns return map [$_ => $value], @{$tags->{$name}}
70 if exists $tags->{$name};
71
721100ns return map [$_ => $value], @{"$class\::EXPORT"}, @{"$class\::EXPORT_OK"}
73 if $name eq 'all';
74
751200ns return map [$_ => $value], @{"$class\::EXPORT"}
76 if $name eq 'default';
77
781600ns $globals->{$name} = $value || 1;
7915µs return;
80}
81
82# Helper for _exporter_expand_sub. Returns a regexp matching all subs in
83# the exporter package which are available for export.
84#
85sub _exporter_permitted_regexp
86
# spent 496µs (154+341) within Exporter::Tiny::_exporter_permitted_regexp which was called 9 times, avg 55µs/call: # 6 times (119µs+310µs) by Exporter::Tiny::import at line 34, avg 71µs/call # 3 times (36µs+32µs) by Type::Library::_exporter_permitted_regexp at line 114 of Type/Library.pm, avg 22µs/call
{
872174µs236µs
# spent 22µs (9+13) within Exporter::Tiny::BEGIN@87 which was called: # once (9µs+13µs) by Eval::TypeTiny::import at line 87
no strict qw(refs);
# spent 22µs making 1 call to Exporter::Tiny::BEGIN@87 # spent 13µs making 1 call to strict::unimport
8892µs my $class = shift;
89 my $re = join "|", map quotemeta, sort {
90 length($b) <=> length($a) or $a cmp $b
919140µs950µs } @{"$class\::EXPORT"}, @{"$class\::EXPORT_OK"};
# spent 50µs making 9 calls to Exporter::Tiny::CORE:sort, avg 6µs/call
929364µs18292µs qr{^(?:$re)$}ms;
# spent 275µs making 9 calls to Exporter::Tiny::CORE:regcomp, avg 31µs/call # spent 16µs making 9 calls to Exporter::Tiny::CORE:qr, avg 2µs/call
93}
94
95# Given a sub name, returns a hash of subs to install (usually just one sub).
96# Keys are sub names, values are coderefs.
97#
98sub _exporter_expand_sub
99
# spent 1.07ms (600µs+475µs) within Exporter::Tiny::_exporter_expand_sub which was called 53 times, avg 20µs/call: # 35 times (384µs+311µs) by Type::Library::_exporter_expand_sub at line 151 of Type/Library.pm, avg 20µs/call # 18 times (216µs+164µs) by Exporter::Tiny::import at line 38, avg 21µs/call
{
1005312µs my $class = shift;
1015318µs my ($name, $value, $globals, $permitted) = @_;
102536µs $permitted ||= $class->_exporter_permitted_regexp($globals);
103
1042398µs236µs
# spent 23µs (9+13) within Exporter::Tiny::BEGIN@104 which was called: # once (9µs+13µs) by Eval::TypeTiny::import at line 104
no strict qw(refs);
# spent 23µs making 1 call to Exporter::Tiny::BEGIN@104 # spent 13µs making 1 call to strict::unimport
105
10653373µs106193µs if ($name =~ $permitted)
# spent 108µs making 53 calls to Exporter::Tiny::CORE:match, avg 2µs/call # spent 85µs making 53 calls to Exporter::Tiny::CORE:regcomp, avg 2µs/call
107 {
10853364µs53223µs my $generator = $class->can("_generate_$name");
# spent 223µs making 53 calls to UNIVERSAL::can, avg 4µs/call
109535µs return $name => $class->$generator($name, $value, $globals) if $generator;
110
11153162µs5358µs my $sub = $class->can($name);
# spent 58µs making 53 calls to UNIVERSAL::can, avg 1µs/call
11253147µs return $name => $sub if $sub;
113 }
114
115 $class->_exporter_fail(@_);
116}
117
118# Called by _exporter_expand_sub if it is unable to generate a key-value
119# pair for a sub.
120#
121sub _exporter_fail
122{
123 my $class = shift;
124 my ($name, $value, $globals) = @_;
125 _croak("Could not find sub '$name' to export in package '$class'");
126}
127
128# Actually performs the installation of the sub into the target package. This
129# also handles renaming the sub.
130#
131sub _exporter_install_sub
132
# spent 954µs (808+146) within Exporter::Tiny::_exporter_install_sub which was called 53 times, avg 18µs/call: # 53 times (808µs+146µs) by Exporter::Tiny::import at line 40, avg 18µs/call
{
1335311µs my $class = shift;
1345327µs my ($name, $value, $globals, $sym) = @_;
135
1365317µs my $into = $globals->{into};
1375317µs my $installer = $globals->{installer} || $globals->{exporter};
138
1395326µs $name = $value->{-as} || $name;
1405322µs unless (ref($name) eq q(SCALAR))
141 {
1425386µs my ($prefix) = grep defined, $value->{-prefix}, $globals->{prefix}, q();
1435354µs my ($suffix) = grep defined, $value->{-suffix}, $globals->{suffix}, q();
1445339µs $name = "$prefix$name$suffix";
145 }
146
147535µs return $installer->($globals, [$name, $sym]) if $installer;
148536µs return ($$name = $sym) if ref($name) eq q(SCALAR);
149535µs return ($into->{$name} = $sym) if ref($into) eq q(HASH);
150
1515314µs require B;
15253378µs53146µs for (grep ref, $into->can($name))
# spent 146µs making 53 calls to UNIVERSAL::can, avg 3µs/call
153 {
154 my $stash = B::svref_2object($_)->STASH;
155 next unless $stash->can("NAME");
156 $stash->NAME eq $into
157 and _croak("Refusing to overwrite local sub '$name' with export from $class");
158 }
159
1602307µs236µs
# spent 23µs (9+14) within Exporter::Tiny::BEGIN@160 which was called: # once (9µs+14µs) by Eval::TypeTiny::import at line 160
no strict qw(refs);
# spent 23µs making 1 call to Exporter::Tiny::BEGIN@160 # spent 14µs making 1 call to strict::unimport
16153238µs *{"$into\::$name"} = $sym;
162}
163
164sub mkopt
165
# spent 92µs within Exporter::Tiny::mkopt which was called 9 times, avg 10µs/call: # 9 times (92µs+0s) by Exporter::Tiny::import at line 18, avg 10µs/call
{
16693µs my $in = shift or return [];
16791µs my @out;
168
16994µs $in = [map(($_ => ref($in->{$_}) ? $in->{$_} : ()), sort keys %$in)]
170 if ref($in) eq q(HASH);
171
172914µs for (my $i = 0; $i < @$in; $i++)
173 {
174206µs my $k = $in->[$i];
17520300ns my $v;
176
1772014µs ($i == $#$in) ? ($v = undef) :
178 !defined($in->[$i+1]) ? (++$i, ($v = undef)) :
179 !ref($in->[$i+1]) ? ($v = undef) :
180 ($v = $in->[++$i]);
181
1822018µs push @out, [ $k => $v ];
183 }
184
185940µs \@out;
186}
187
188sub mkopt_hash
189{
190 my $in = shift or return;
191 my %out = map +($_->[0] => $_->[1]), @{ mkopt($in) };
192 \%out;
193}
194
19515µs1;
196
197__END__
 
# spent 138µs within Exporter::Tiny::CORE:match which was called 108 times, avg 1µs/call: # 55 times (30µs+0s) by Exporter::Tiny::import at line 28, avg 551ns/call # 53 times (108µs+0s) by Exporter::Tiny::_exporter_expand_sub at line 106, avg 2µs/call
sub Exporter::Tiny::CORE:match; # opcode
# spent 16µs within Exporter::Tiny::CORE:qr which was called 9 times, avg 2µs/call: # 9 times (16µs+0s) by Exporter::Tiny::_exporter_permitted_regexp at line 92, avg 2µs/call
sub Exporter::Tiny::CORE:qr; # opcode
# spent 360µs within Exporter::Tiny::CORE:regcomp which was called 62 times, avg 6µs/call: # 53 times (85µs+0s) by Exporter::Tiny::_exporter_expand_sub at line 106, avg 2µs/call # 9 times (275µs+0s) by Exporter::Tiny::_exporter_permitted_regexp at line 92, avg 31µs/call
sub Exporter::Tiny::CORE:regcomp; # opcode
# spent 50µs within Exporter::Tiny::CORE:sort which was called 9 times, avg 6µs/call: # 9 times (50µs+0s) by Exporter::Tiny::_exporter_permitted_regexp at line 91, avg 6µs/call
sub Exporter::Tiny::CORE:sort; # opcode