Filename | /usr/lib/perl5/5.20.1/Exporter.pm |
Statements | Executed 348 statements in 1.09ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
23 | 23 | 14 | 902µs | 1.02ms | import | Exporter::
3 | 2 | 1 | 883µs | 925µs | as_heavy | Exporter::
246 | 2 | 1 | 48µs | 48µs | CORE:match (opcode) | Exporter::
201 | 2 | 1 | 9µs | 9µs | CORE:subst (opcode) | Exporter::
2 | 2 | 2 | 6µs | 20µs | export | Exporter::
1 | 1 | 1 | 3µs | 915µs | export_to_level | Exporter::
0 | 0 | 0 | 0s | 0s | __ANON__[:64] | Exporter::
0 | 0 | 0 | 0s | 0s | export_fail | Exporter::
0 | 0 | 0 | 0s | 0s | export_ok_tags | Exporter::
0 | 0 | 0 | 0s | 0s | export_tags | Exporter::
0 | 0 | 0 | 0s | 0s | require_version | Exporter::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Exporter; | ||||
2 | |||||
3 | 1 | 5µs | require 5.006; | ||
4 | |||||
5 | # Be lean. | ||||
6 | #use strict; | ||||
7 | #no strict 'refs'; | ||||
8 | |||||
9 | 1 | 200ns | our $Debug = 0; | ||
10 | 1 | 0s | our $ExportLevel = 0; | ||
11 | 1 | 200ns | our $Verbose ||= 0; | ||
12 | 1 | 200ns | our $VERSION = '5.71'; | ||
13 | 1 | 100ns | our (%Cache); | ||
14 | |||||
15 | sub as_heavy { | ||||
16 | 3 | 56µs | require Exporter::Heavy; | ||
17 | # Unfortunately, this does not work if the caller is aliased as *name = \&foo | ||||
18 | # Thus the need to create a lot of identical subroutines | ||||
19 | 3 | 4µs | my $c = (caller(1))[3]; | ||
20 | 3 | 14µs | 3 | 6µs | $c =~ s/.*:://; # spent 6µs making 3 calls to Exporter::CORE:subst, avg 2µs/call |
21 | 3 | 8µs | \&{"Exporter::Heavy::heavy_$c"}; | ||
22 | } | ||||
23 | |||||
24 | # spent 20µs (6+13) within Exporter::export which was called 2 times, avg 10µs/call:
# once (4µs+9µs) by Exporter::import at line 62
# once (2µs+4µs) by Exporter::Heavy::heavy_export_to_level at line 219 of Exporter/Heavy.pm | ||||
25 | 2 | 7µs | 4 | 160µs | goto &{as_heavy()}; # spent 146µs making 2 calls to Exporter::Heavy::heavy_export, avg 73µs/call
# spent 13µs making 2 calls to Exporter::as_heavy, avg 7µs/call |
26 | } | ||||
27 | |||||
28 | # spent 1.02ms (902µs+122µs) within Exporter::import which was called 23 times, avg 45µs/call:
# once (156µs+3µs) by IO::Seekable::BEGIN@104 at line 104 of IO/Seekable.pm
# once (97µs+4µs) by Date::Manip::Delta::BEGIN@21 at line 21 of Date/Manip/Delta.pm
# once (96µs+5µs) by Date::Manip::TZ::BEGIN@22 at line 22 of Date/Manip/TZ.pm
# once (11µs+73µs) by Storable::BEGIN@53 at line 54 of Storable.pm
# once (68µs+3µs) by Date::Manip::Obj::BEGIN@12 at line 147 of IO/File.pm
# once (63µs+4µs) by Date::Manip::Date::BEGIN@22 at line 22 of Date/Manip/Date.pm
# once (60µs+4µs) by Date::Manip::TZ_Base::BEGIN@12 at line 12 of Date/Manip/TZ_Base.pm
# once (56µs+4µs) by Date::Manip::Obj::BEGIN@12 at line 12 of Date/Manip/Obj.pm
# once (55µs+1µs) by Date::Manip::Base::BEGIN@24 at line 24 of Date/Manip/Base.pm
# once (30µs+11µs) by Date::Manip::Obj::BEGIN@13 at line 13 of Date/Manip/Obj.pm
# once (34µs+3µs) by IO::File::BEGIN@130 at line 130 of IO/File.pm
# once (22µs+1µs) by IO::File::BEGIN@131 at line 131 of IO/File.pm
# once (20µs+800ns) by IO::Seekable::BEGIN@98 at line 98 of IO/Seekable.pm
# once (18µs+800ns) by IO::File::BEGIN@133 at line 133 of IO/File.pm
# once (18µs+800ns) by IO::Handle::BEGIN@266 at line 266 of IO/Handle.pm
# once (18µs+700ns) by SelectSaver::BEGIN@38 at line 38 of SelectSaver.pm
# once (16µs+600ns) by Encode::BEGIN@47 at line 47 of Encode.pm
# once (16µs+700ns) by IO::BEGIN@6 at line 6 of IO.pm
# once (15µs+700ns) by IO::Handle::BEGIN@267 at line 267 of IO/Handle.pm
# once (14µs+600ns) by SelectSaver::BEGIN@39 at line 39 of SelectSaver.pm
# once (11µs+400ns) by Date::Manip::Date::BEGIN@23 at line 23 of Date/Manip/Date.pm
# once (4µs+0s) by Encode::BEGIN@12 at line 12 of Encode.pm
# once (3µs+0s) by Encode::Alias::BEGIN@8 at line 8 of Encode/Alias.pm | ||||
29 | 23 | 5µs | my $pkg = shift; | ||
30 | 23 | 9µs | my $callpkg = caller($ExportLevel); | ||
31 | |||||
32 | 23 | 6µs | if ($pkg eq "Exporter" and @_ and $_[0] eq "import") { | ||
33 | 2 | 3µs | *{$callpkg."::import"} = \&import; | ||
34 | 2 | 12µs | return; | ||
35 | } | ||||
36 | |||||
37 | # We *need* to treat @{"$pkg\::EXPORT_FAIL"} since Carp uses it :-( | ||||
38 | 21 | 19µs | my $exports = \@{"$pkg\::EXPORT"}; | ||
39 | # But, avoid creating things if they don't exist, which saves a couple of | ||||
40 | # hundred bytes per package processed. | ||||
41 | 21 | 14µs | my $fail = ${$pkg . '::'}{EXPORT_FAIL} && \@{"$pkg\::EXPORT_FAIL"}; | ||
42 | 21 | 7µs | return export $pkg, $callpkg, @_ | ||
43 | if $Verbose or $Debug or $fail && @$fail > 1; | ||||
44 | 21 | 10µs | my $export_cache = ($Cache{$pkg} ||= {}); | ||
45 | 21 | 29µs | my $args = @_ or @_ = @$exports; | ||
46 | |||||
47 | 21 | 5µs | if ($args and not %$export_cache) { | ||
48 | s/^&//, $export_cache->{$_} = 1 | ||||
49 | 3 | 188µs | 198 | 2µs | foreach (@$exports, @{"$pkg\::EXPORT_OK"}); # spent 2µs making 198 calls to Exporter::CORE:subst, avg 13ns/call |
50 | } | ||||
51 | 21 | 2µs | my $heavy; | ||
52 | # Try very hard not to use {} and hence have to enter scope on the foreach | ||||
53 | # We bomb out of the loop with last as soon as heavy is set. | ||||
54 | 21 | 7µs | if ($args or $fail) { | ||
55 | ($heavy = (/\W/ or $args and not exists $export_cache->{$_} | ||||
56 | or $fail and @$fail and $_ eq $fail->[0])) and last | ||||
57 | 11 | 94µs | 59 | 23µs | foreach (@_); # spent 23µs making 59 calls to Exporter::CORE:match, avg 392ns/call |
58 | } else { | ||||
59 | ($heavy = /\W/) and last | ||||
60 | 10 | 185µs | 187 | 25µs | foreach (@_); # spent 25µs making 187 calls to Exporter::CORE:match, avg 133ns/call |
61 | } | ||||
62 | 21 | 5µs | 1 | 13µs | return export $pkg, $callpkg, ($args ? @_ : ()) if $heavy; # spent 13µs making 1 call to Exporter::export |
63 | local $SIG{__WARN__} = | ||||
64 | 20 | 55µs | sub {require Carp; &Carp::carp} if not $SIG{__WARN__}; | ||
65 | # shortcut for the common case of no type character | ||||
66 | 20 | 331µs | *{"$callpkg\::$_"} = \&{"$pkg\::$_"} foreach @_; | ||
67 | } | ||||
68 | |||||
69 | # Default methods | ||||
70 | |||||
71 | sub export_fail { | ||||
72 | my $self = shift; | ||||
73 | @_; | ||||
74 | } | ||||
75 | |||||
76 | # Unfortunately, caller(1)[3] "does not work" if the caller is aliased as | ||||
77 | # *name = \&foo. Thus the need to create a lot of identical subroutines | ||||
78 | # Otherwise we could have aliased them to export(). | ||||
79 | |||||
80 | # spent 915µs (3+912) within Exporter::export_to_level which was called:
# once (3µs+912µs) by Time::HiRes::import at line 63 of Time/HiRes.pm | ||||
81 | 1 | 5µs | 2 | 1.01ms | goto &{as_heavy()}; # spent 912µs making 1 call to Exporter::as_heavy
# spent 102µs making 1 call to Exporter::Heavy::heavy_export_to_level |
82 | } | ||||
83 | |||||
84 | sub export_tags { | ||||
85 | goto &{as_heavy()}; | ||||
86 | } | ||||
87 | |||||
88 | sub export_ok_tags { | ||||
89 | goto &{as_heavy()}; | ||||
90 | } | ||||
91 | |||||
92 | sub require_version { | ||||
93 | goto &{as_heavy()}; | ||||
94 | } | ||||
95 | |||||
96 | 1 | 3µs | 1; | ||
97 | __END__ | ||||
sub Exporter::CORE:match; # opcode | |||||
sub Exporter::CORE:subst; # opcode |