Filename | /Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/Sub/Exporter/Progressive.pm |
Statements | Executed 150 statements in 1.07ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 1 | 1 | 128µs | 162µs | sub_export_options | Sub::Exporter::Progressive::
4 | 4 | 4 | 62µs | 94µs | __ANON__[:40] | Sub::Exporter::Progressive::
3 | 3 | 3 | 55µs | 217µs | import | Sub::Exporter::Progressive::
15 | 4 | 1 | 15µs | 15µs | CORE:match (opcode) | Sub::Exporter::Progressive::
1 | 1 | 1 | 10µs | 29µs | BEGIN@3 | Sub::Exporter::Progressive::
1 | 1 | 1 | 8µs | 43µs | BEGIN@9 | Sub::Exporter::Progressive::
1 | 1 | 1 | 8µs | 20µs | BEGIN@23 | Sub::Exporter::Progressive::
1 | 1 | 1 | 6µs | 9µs | BEGIN@4 | Sub::Exporter::Progressive::
1 | 1 | 1 | 6µs | 25µs | BEGIN@8 | Sub::Exporter::Progressive::
1 | 1 | 1 | 6µs | 15µs | BEGIN@18 | Sub::Exporter::Progressive::
3 | 1 | 1 | 1µs | 1µs | CORE:subst (opcode) | Sub::Exporter::Progressive::
0 | 0 | 0 | 0s | 0s | __ANON__[:26] | Sub::Exporter::Progressive::
0 | 0 | 0 | 0s | 0s | __ANON__[:32] | Sub::Exporter::Progressive::
0 | 0 | 0 | 0s | 0s | __ANON__[:66] | Sub::Exporter::Progressive::
0 | 0 | 0 | 0s | 0s | __ANON__[:71] | Sub::Exporter::Progressive::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Sub::Exporter::Progressive; | ||||
2 | |||||
3 | 2 | 20µs | 2 | 48µs | # spent 29µs (10+19) within Sub::Exporter::Progressive::BEGIN@3 which was called:
# once (10µs+19µs) by Devel::GlobalDestruction::BEGIN@8 at line 3 # spent 29µs making 1 call to Sub::Exporter::Progressive::BEGIN@3
# spent 19µs making 1 call to strict::import |
4 | 2 | 28µs | 2 | 12µs | # spent 9µs (6+3) within Sub::Exporter::Progressive::BEGIN@4 which was called:
# once (6µs+3µs) by Devel::GlobalDestruction::BEGIN@8 at line 4 # spent 9µs making 1 call to Sub::Exporter::Progressive::BEGIN@4
# spent 3µs making 1 call to warnings::import |
5 | |||||
6 | 1 | 500ns | our $VERSION = '0.001010'; | ||
7 | |||||
8 | 2 | 20µs | 2 | 43µs | # spent 25µs (6+19) within Sub::Exporter::Progressive::BEGIN@8 which was called:
# once (6µs+19µs) by Devel::GlobalDestruction::BEGIN@8 at line 8 # spent 25µs making 1 call to Sub::Exporter::Progressive::BEGIN@8
# spent 19µs making 1 call to Exporter::import |
9 | 2 | 58µs | 2 | 77µs | # spent 43µs (8+35) within Sub::Exporter::Progressive::BEGIN@9 which was called:
# once (8µs+35µs) by Devel::GlobalDestruction::BEGIN@8 at line 9 # spent 43µs making 1 call to Sub::Exporter::Progressive::BEGIN@9
# spent 35µs making 1 call to Exporter::import |
10 | |||||
11 | # spent 217µs (55+162) within Sub::Exporter::Progressive::import which was called 3 times, avg 72µs/call:
# once (20µs+79µs) by Devel::GlobalDestruction::BEGIN@8 at line 11 of Devel/GlobalDestruction.pm
# once (20µs+47µs) by B::Hooks::EndOfScope::XS::BEGIN@19 at line 22 of B/Hooks/EndOfScope/XS.pm
# once (15µs+36µs) by B::Hooks::EndOfScope::BEGIN@34 at line 37 of B/Hooks/EndOfScope.pm | ||||
12 | 3 | 3µs | my ($self, @args) = @_; | ||
13 | |||||
14 | 3 | 2µs | my $inner_target = caller; | ||
15 | 3 | 4µs | 3 | 162µs | my $export_data = sub_export_options($inner_target, @args); # spent 162µs making 3 calls to Sub::Exporter::Progressive::sub_export_options, avg 54µs/call |
16 | |||||
17 | 3 | 200ns | my $full_exporter; | ||
18 | 2 | 67µs | 2 | 24µs | # spent 15µs (6+9) within Sub::Exporter::Progressive::BEGIN@18 which was called:
# once (6µs+9µs) by Devel::GlobalDestruction::BEGIN@8 at line 18 # spent 15µs making 1 call to Sub::Exporter::Progressive::BEGIN@18
# spent 9µs making 1 call to strict::unimport |
19 | 3 | 8µs | @{"${inner_target}::EXPORT_OK"} = @{$export_data->{exports}}; | ||
20 | 3 | 7µs | @{"${inner_target}::EXPORT"} = @{$export_data->{defaults}}; | ||
21 | 3 | 7µs | %{"${inner_target}::EXPORT_TAGS"} = %{$export_data->{tags}}; | ||
22 | # spent 94µs (62+33) within Sub::Exporter::Progressive::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/Sub/Exporter/Progressive.pm:40] which was called 4 times, avg 24µs/call:
# once (18µs+12µs) by Class::MOP::Package::BEGIN@15 at line 15 of Class/MOP/Package.pm
# once (17µs+11µs) by Moose::Meta::Role::BEGIN@16 at line 16 of Moose/Meta/Role.pm
# once (13µs+9µs) by namespace::clean::BEGIN@11 at line 11 of namespace/clean.pm
# once (13µs+900ns) by namespace::autoclean::BEGIN@14 at line 14 of namespace/autoclean.pm | ||||
23 | 2 | 570µs | 2 | 32µs | # spent 20µs (8+12) within Sub::Exporter::Progressive::BEGIN@23 which was called:
# once (8µs+12µs) by Devel::GlobalDestruction::BEGIN@8 at line 23 # spent 20µs making 1 call to Sub::Exporter::Progressive::BEGIN@23
# spent 12µs making 1 call to strict::import |
24 | 4 | 3µs | my ($self, @args) = @_; | ||
25 | |||||
26 | 7 | 45µs | 11 | 38µs | if (first { ref || !m/ \A [:-]? \w+ \z /xm } @args) { # spent 32µs making 8 calls to List::Util::first, avg 4µs/call
# spent 7µs making 3 calls to Sub::Exporter::Progressive::CORE:match, avg 2µs/call |
27 | croak 'your usage of Sub::Exporter::Progressive requires Sub::Exporter to be installed' | ||||
28 | unless eval { require Sub::Exporter }; | ||||
29 | $full_exporter ||= Sub::Exporter::build_exporter($export_data->{original}); | ||||
30 | |||||
31 | goto $full_exporter; | ||||
32 | 3 | 13µs | 3 | 2µs | } elsif (defined(my $num = first { !ref and m/^\d/ } @args)) { # spent 2µs making 3 calls to Sub::Exporter::Progressive::CORE:match, avg 700ns/call |
33 | die "cannot export symbols with a leading digit: '$num'"; | ||||
34 | } else { | ||||
35 | 4 | 2µs | require Exporter; | ||
36 | 4 | 13µs | 3 | 1µs | s/ \A - /:/xm for @args; # spent 1µs making 3 calls to Sub::Exporter::Progressive::CORE:subst, avg 400ns/call |
37 | 4 | 4µs | @_ = ($self, @args); | ||
38 | 4 | 20µs | 4 | 94µs | goto \&Exporter::import; # spent 94µs making 4 calls to Exporter::import, avg 24µs/call |
39 | } | ||||
40 | 3 | 13µs | }; | ||
41 | 3 | 10µs | return; | ||
42 | } | ||||
43 | |||||
44 | 1 | 200ns | my $too_complicated = <<'DEATH'; | ||
45 | You are using Sub::Exporter::Progressive, but the features your program uses from | ||||
46 | Sub::Exporter cannot be implemented without Sub::Exporter, so you might as well | ||||
47 | just use vanilla Sub::Exporter | ||||
48 | DEATH | ||||
49 | |||||
50 | # spent 162µs (128+34) within Sub::Exporter::Progressive::sub_export_options which was called 3 times, avg 54µs/call:
# 3 times (128µs+34µs) by Sub::Exporter::Progressive::import at line 15, avg 54µs/call | ||||
51 | 3 | 1µs | my ($inner_target, $setup, $options) = @_; | ||
52 | |||||
53 | 3 | 100ns | my @exports; | ||
54 | 3 | 100ns | my @defaults; | ||
55 | 3 | 400ns | my %tags; | ||
56 | |||||
57 | 3 | 1µs | if ($setup eq '-setup') { | ||
58 | 3 | 5µs | my %options = %$options; | ||
59 | |||||
60 | OPTIONS: | ||||
61 | 3 | 3µs | for my $opt (keys %options) { | ||
62 | 6 | 6µs | if ($opt eq 'exports') { | ||
63 | |||||
64 | 3 | 2µs | croak $too_complicated if ref $options{exports} ne 'ARRAY'; | ||
65 | 3 | 2µs | @exports = @{$options{exports}}; | ||
66 | 6 | 12µs | 3 | 3µs | croak $too_complicated if first { ref } @exports; # spent 3µs making 3 calls to List::Util::first, avg 967ns/call |
67 | |||||
68 | } elsif ($opt eq 'groups') { | ||||
69 | 3 | 3µs | %tags = %{$options{groups}}; | ||
70 | 3 | 2µs | for my $tagset (values %tags) { | ||
71 | 6 | 46µs | 6 | 31µs | croak $too_complicated if first { / \A - (?! all \b ) /x || ref } @{$tagset}; # spent 28µs making 3 calls to List::Util::first, avg 9µs/call
# spent 3µs making 3 calls to Sub::Exporter::Progressive::CORE:match, avg 1µs/call |
72 | } | ||||
73 | 3 | 3µs | @defaults = @{$tags{default} || [] }; | ||
74 | } else { | ||||
75 | croak $too_complicated; | ||||
76 | } | ||||
77 | } | ||||
78 | 9 | 42µs | 6 | 3µs | @{$_} = map { / \A [:-] all \z /x ? @exports : $_ } @{$_} for \@defaults, values %tags; # spent 3µs making 6 calls to Sub::Exporter::Progressive::CORE:match, avg 500ns/call |
79 | 3 | 3µs | $tags{all} ||= [ @exports ]; | ||
80 | 3 | 4µs | my %exports = map { $_ => 1 } @exports; | ||
81 | 3 | 2µs | my @errors = grep { not $exports{$_} } @defaults; | ||
82 | 3 | 3µs | croak join(', ', @errors) . " is not exported by the $inner_target module\n" if @errors; | ||
83 | } | ||||
84 | |||||
85 | return { | ||||
86 | 3 | 12µs | exports => \@exports, | ||
87 | defaults => \@defaults, | ||||
88 | original => $options, | ||||
89 | tags => \%tags, | ||||
90 | }; | ||||
91 | } | ||||
92 | |||||
93 | 1 | 3µs | 1; | ||
94 | |||||
95 | =encoding utf8 | ||||
96 | |||||
97 | =head1 NAME | ||||
98 | |||||
99 | Sub::Exporter::Progressive - Only use Sub::Exporter if you need it | ||||
100 | |||||
101 | =head1 SYNOPSIS | ||||
102 | |||||
103 | package Syntax::Keyword::Gather; | ||||
104 | |||||
105 | use Sub::Exporter::Progressive -setup => { | ||||
106 | exports => [qw( break gather gathered take )], | ||||
107 | groups => { | ||||
108 | defaults => [qw( break gather gathered take )], | ||||
109 | }, | ||||
110 | }; | ||||
111 | |||||
112 | # elsewhere | ||||
113 | |||||
114 | # uses Exporter for speed | ||||
115 | use Syntax::Keyword::Gather; | ||||
116 | |||||
117 | # somewhere else | ||||
118 | |||||
119 | # uses Sub::Exporter for features | ||||
120 | use Syntax::Keyword::Gather 'gather', take => { -as => 'grab' }; | ||||
121 | |||||
122 | =head1 DESCRIPTION | ||||
123 | |||||
124 | L<Sub::Exporter> is an incredibly powerful module, but with that power comes | ||||
125 | great responsibility, er- as well as some runtime penalties. This module | ||||
126 | is a C<Sub::Exporter> wrapper that will let your users just use L<Exporter> | ||||
127 | if all they are doing is picking exports, but use C<Sub::Exporter> if your | ||||
128 | users try to use C<Sub::Exporter>'s more advanced features features, like | ||||
129 | renaming exports, if they try to use them. | ||||
130 | |||||
131 | Note that this module will export C<@EXPORT>, C<@EXPORT_OK> and | ||||
132 | C<%EXPORT_TAGS> package variables for C<Exporter> to work. Additionally, if | ||||
133 | your package uses advanced C<Sub::Exporter> features like currying, this module | ||||
134 | will only ever use C<Sub::Exporter>, so you might as well use it directly. | ||||
135 | |||||
136 | =head1 AUTHOR | ||||
137 | |||||
138 | frew - Arthur Axel Schmidt (cpan:FREW) <frioux+cpan@gmail.com> | ||||
139 | |||||
140 | =head1 CONTRIBUTORS | ||||
141 | |||||
142 | ilmari - Dagfinn Ilmari Mannsåker (cpan:ILMARI) <ilmari@ilmari.org> | ||||
143 | |||||
144 | mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk> | ||||
145 | |||||
146 | leont - Leon Timmermans (cpan:LEONT) <leont@cpan.org> | ||||
147 | |||||
148 | =head1 COPYRIGHT | ||||
149 | |||||
150 | Copyright (c) 2012 the Sub::Exporter::Progressive L</AUTHOR> and | ||||
151 | L</CONTRIBUTORS> as listed above. | ||||
152 | |||||
153 | =head1 LICENSE | ||||
154 | |||||
155 | This library is free software and may be distributed under the same terms | ||||
156 | as perl itself. | ||||
157 | |||||
158 | =cut | ||||
# spent 15µs within Sub::Exporter::Progressive::CORE:match which was called 15 times, avg 1µs/call:
# 6 times (3µs+0s) by Sub::Exporter::Progressive::sub_export_options at line 78, avg 500ns/call
# 3 times (7µs+0s) by List::Util::first at line 26, avg 2µs/call
# 3 times (3µs+0s) by List::Util::first at line 71, avg 1µs/call
# 3 times (2µs+0s) by List::Util::first at line 32, avg 700ns/call | |||||
# spent 1µs within Sub::Exporter::Progressive::CORE:subst which was called 3 times, avg 400ns/call:
# 3 times (1µs+0s) by Sub::Exporter::Progressive::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/Sub/Exporter/Progressive.pm:40] at line 36, avg 400ns/call |