| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Exporter.pm |
| Statements | Executed 439 statements in 2.61ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 532µs | 1.82ms | Sub::Exporter::BEGIN@11 |
| 4 | 1 | 1 | 125µs | 565µs | Sub::Exporter::_rewrite_build_config |
| 5 | 5 | 3 | 98µs | 922µs | Sub::Exporter::__ANON__[:337] |
| 5 | 1 | 1 | 81µs | 548µs | Sub::Exporter::_do_import |
| 5 | 1 | 1 | 76µs | 150µs | Sub::Exporter::_collect_collections |
| 5 | 1 | 1 | 46µs | 56µs | Sub::Exporter::_expand_groups |
| 5 | 1 | 1 | 40µs | 252µs | Sub::Exporter::default_generator |
| 5 | 1 | 1 | 39µs | 214µs | Sub::Exporter::default_installer |
| 3 | 1 | 1 | 33µs | 45µs | Sub::Exporter::__ANON__[:159] |
| 5 | 1 | 1 | 29µs | 29µs | Sub::Exporter::_mk_collection_builder |
| 4 | 3 | 2 | 29µs | 594µs | Sub::Exporter::build_exporter |
| 4 | 1 | 1 | 19µs | 23µs | Sub::Exporter::_assert_collector_names_ok |
| 4 | 1 | 1 | 18µs | 18µs | Sub::Exporter::_key_intersection |
| 1 | 1 | 1 | 16µs | 304µs | Sub::Exporter::setup_exporter |
| 1 | 1 | 1 | 14µs | 14µs | Path::IsDev::BEGIN@1 |
| 1 | 1 | 1 | 12µs | 19µs | Sub::Exporter::BEGIN@12 |
| 5 | 1 | 1 | 10µs | 10µs | Sub::Exporter::_group_name |
| 2 | 1 | 1 | 10µs | 10µs | Sub::Exporter::_setup |
| 1 | 1 | 1 | 9µs | 9µs | Sub::Exporter::BEGIN@217 |
| 2 | 1 | 1 | 8µs | 168µs | Sub::Exporter::__ANON__[:460] |
| 1 | 1 | 1 | 7µs | 13µs | Sub::Exporter::BEGIN@13 |
| 1 | 1 | 1 | 6µs | 10µs | Path::IsDev::BEGIN@3 |
| 1 | 1 | 1 | 6µs | 17µs | Path::IsDev::BEGIN@2 |
| 2 | 1 | 1 | 4µs | 4µs | Sub::Exporter::CORE:match (opcode) |
| 1 | 1 | 1 | 3µs | 3µs | Sub::Exporter::BEGIN@10 |
| 0 | 0 | 0 | 0s | 0s | Sub::Exporter::__ANON__[:354] |
| 0 | 0 | 0 | 0s | 0s | Sub::Exporter::_expand_group |
| 0 | 0 | 0 | 0s | 0s | Sub::Exporter::default_exporter |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | 2 | 34µs | 1 | 14µs | # spent 14µs within Path::IsDev::BEGIN@1 which was called:
# once (14µs+0s) by Path::IsDev::BEGIN@261 at line 1 # spent 14µs making 1 call to Path::IsDev::BEGIN@1 |
| 2 | 2 | 17µs | 2 | 28µs | # spent 17µs (6+11) within Path::IsDev::BEGIN@2 which was called:
# once (6µs+11µs) by Path::IsDev::BEGIN@261 at line 2 # spent 17µs making 1 call to Path::IsDev::BEGIN@2
# spent 11µs making 1 call to strict::import |
| 3 | 2 | 32µs | 2 | 13µs | # spent 10µs (6+3) within Path::IsDev::BEGIN@3 which was called:
# once (6µs+3µs) by Path::IsDev::BEGIN@261 at line 3 # spent 10µs making 1 call to Path::IsDev::BEGIN@3
# spent 3µs making 1 call to warnings::import |
| 4 | package Sub::Exporter; | ||||
| 5 | { | ||||
| 6 | 2 | 1µs | $Sub::Exporter::VERSION = '0.987'; | ||
| 7 | } | ||||
| 8 | # ABSTRACT: a sophisticated exporter for custom-built routines | ||||
| 9 | |||||
| 10 | 2 | 26µs | 1 | 3µs | # spent 3µs within Sub::Exporter::BEGIN@10 which was called:
# once (3µs+0s) by Path::IsDev::BEGIN@261 at line 10 # spent 3µs making 1 call to Sub::Exporter::BEGIN@10 |
| 11 | 3 | 83µs | 2 | 1.83ms | # spent 1.82ms (532µs+1.29) within Sub::Exporter::BEGIN@11 which was called:
# once (532µs+1.29ms) by Path::IsDev::BEGIN@261 at line 11 # spent 1.82ms making 1 call to Sub::Exporter::BEGIN@11
# spent 8µs making 1 call to UNIVERSAL::VERSION |
| 12 | 3 | 34µs | 2 | 26µs | # spent 19µs (12+7) within Sub::Exporter::BEGIN@12 which was called:
# once (12µs+7µs) by Path::IsDev::BEGIN@261 at line 12 # spent 19µs making 1 call to Sub::Exporter::BEGIN@12
# spent 7µs making 1 call to UNIVERSAL::VERSION |
| 13 | 3 | 774µs | 2 | 20µs | # spent 13µs (7+6) within Sub::Exporter::BEGIN@13 which was called:
# once (7µs+6µs) by Path::IsDev::BEGIN@261 at line 13 # spent 13µs making 1 call to Sub::Exporter::BEGIN@13
# spent 6µs making 1 call to UNIVERSAL::VERSION |
| 14 | |||||
| 15 | |||||
| 16 | # Given a potential import name, this returns the group name -- if it's got a | ||||
| 17 | # group prefix. | ||||
| 18 | # spent 10µs within Sub::Exporter::_group_name which was called 5 times, avg 2µs/call:
# 5 times (10µs+0s) by Sub::Exporter::_expand_groups at line 36, avg 2µs/call | ||||
| 19 | 5 | 1µs | my ($name) = @_; | ||
| 20 | |||||
| 21 | 5 | 14µs | return if (index q{-:}, (substr $name, 0, 1)) == -1; | ||
| 22 | return substr $name, 1; | ||||
| 23 | } | ||||
| 24 | |||||
| 25 | # \@groups is a canonicalized opt list of exports and groups this returns | ||||
| 26 | # another canonicalized opt list with groups replaced with relevant exports. | ||||
| 27 | # \%seen is groups we've already expanded and can ignore. | ||||
| 28 | # \%merge is merged options from the group we're descending through. | ||||
| 29 | # spent 56µs (46+10) within Sub::Exporter::_expand_groups which was called 5 times, avg 11µs/call:
# 5 times (46µs+10µs) by Sub::Exporter::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Exporter.pm:337] at line 323, avg 11µs/call | ||||
| 30 | 5 | 2µs | my ($class, $config, $groups, $collection, $seen, $merge) = @_; | ||
| 31 | 5 | 2µs | $seen ||= {}; | ||
| 32 | 5 | 600ns | $merge ||= {}; | ||
| 33 | 5 | 2µs | my @groups = @$groups; | ||
| 34 | |||||
| 35 | 5 | 8µs | for my $i (reverse 0 .. $#groups) { | ||
| 36 | 5 | 7µs | 5 | 10µs | if (my $group_name = _group_name($groups[$i][0])) { # spent 10µs making 5 calls to Sub::Exporter::_group_name, avg 2µs/call |
| 37 | my $seen = { %$seen }; # faux-dynamic scoping | ||||
| 38 | |||||
| 39 | splice @groups, $i, 1, | ||||
| 40 | _expand_group($class, $config, $groups[$i], $collection, $seen, $merge); | ||||
| 41 | } else { | ||||
| 42 | # there's nothing to munge in this export's args | ||||
| 43 | 5 | 7µs | next unless my %merge = %$merge; | ||
| 44 | |||||
| 45 | # we have things to merge in; do so | ||||
| 46 | my $prefix = (delete $merge{-prefix}) || ''; | ||||
| 47 | my $suffix = (delete $merge{-suffix}) || ''; | ||||
| 48 | |||||
| 49 | if ( | ||||
| 50 | Params::Util::_CODELIKE($groups[$i][1]) ## no critic Private | ||||
| 51 | or | ||||
| 52 | Params::Util::_SCALAR0($groups[$i][1]) ## no critic Private | ||||
| 53 | ) { | ||||
| 54 | # this entry was build by a group generator | ||||
| 55 | $groups[$i][0] = $prefix . $groups[$i][0] . $suffix; | ||||
| 56 | } else { | ||||
| 57 | my $as | ||||
| 58 | = ref $groups[$i][1]{-as} ? $groups[$i][1]{-as} | ||||
| 59 | : $groups[$i][1]{-as} ? $prefix . $groups[$i][1]{-as} . $suffix | ||||
| 60 | : $prefix . $groups[$i][0] . $suffix; | ||||
| 61 | |||||
| 62 | $groups[$i][1] = { %{ $groups[$i][1] }, %merge, -as => $as }; | ||||
| 63 | } | ||||
| 64 | } | ||||
| 65 | } | ||||
| 66 | |||||
| 67 | 5 | 14µs | return \@groups; | ||
| 68 | } | ||||
| 69 | |||||
| 70 | # \@group is a name/value pair from an opt list. | ||||
| 71 | sub _expand_group { | ||||
| 72 | my ($class, $config, $group, $collection, $seen, $merge) = @_; | ||||
| 73 | $merge ||= {}; | ||||
| 74 | |||||
| 75 | my ($group_name, $group_arg) = @$group; | ||||
| 76 | $group_name = _group_name($group_name); | ||||
| 77 | |||||
| 78 | Carp::croak qq(group "$group_name" is not exported by the $class module) | ||||
| 79 | unless exists $config->{groups}{$group_name}; | ||||
| 80 | |||||
| 81 | return if $seen->{$group_name}++; | ||||
| 82 | |||||
| 83 | if (ref $group_arg) { | ||||
| 84 | my $prefix = (delete $merge->{-prefix}||'') . ($group_arg->{-prefix}||''); | ||||
| 85 | my $suffix = ($group_arg->{-suffix}||'') . (delete $merge->{-suffix}||''); | ||||
| 86 | $merge = { | ||||
| 87 | %$merge, | ||||
| 88 | %$group_arg, | ||||
| 89 | ($prefix ? (-prefix => $prefix) : ()), | ||||
| 90 | ($suffix ? (-suffix => $suffix) : ()), | ||||
| 91 | }; | ||||
| 92 | } | ||||
| 93 | |||||
| 94 | my $exports = $config->{groups}{$group_name}; | ||||
| 95 | |||||
| 96 | if ( | ||||
| 97 | Params::Util::_CODELIKE($exports) ## no critic Private | ||||
| 98 | or | ||||
| 99 | Params::Util::_SCALAR0($exports) ## no critic Private | ||||
| 100 | ) { | ||||
| 101 | # I'm not very happy with this code for hiding -prefix and -suffix, but | ||||
| 102 | # it's needed, and I'm not sure, offhand, how to make it better. | ||||
| 103 | # -- rjbs, 2006-12-05 | ||||
| 104 | my $group_arg = $merge ? { %$merge } : {}; | ||||
| 105 | delete $group_arg->{-prefix}; | ||||
| 106 | delete $group_arg->{-suffix}; | ||||
| 107 | |||||
| 108 | my $group = Params::Util::_CODELIKE($exports) ## no critic Private | ||||
| 109 | ? $exports->($class, $group_name, $group_arg, $collection) | ||||
| 110 | : $class->$$exports($group_name, $group_arg, $collection); | ||||
| 111 | |||||
| 112 | Carp::croak qq(group generator "$group_name" did not return a hashref) | ||||
| 113 | if ref $group ne 'HASH'; | ||||
| 114 | |||||
| 115 | my $stuff = [ map { [ $_ => $group->{$_} ] } keys %$group ]; | ||||
| 116 | return @{ | ||||
| 117 | _expand_groups($class, $config, $stuff, $collection, $seen, $merge) | ||||
| 118 | }; | ||||
| 119 | } else { | ||||
| 120 | $exports | ||||
| 121 | = Data::OptList::mkopt($exports, "$group_name exports"); | ||||
| 122 | |||||
| 123 | return @{ | ||||
| 124 | _expand_groups($class, $config, $exports, $collection, $seen, $merge) | ||||
| 125 | }; | ||||
| 126 | } | ||||
| 127 | } | ||||
| 128 | |||||
| 129 | # spent 29µs within Sub::Exporter::_mk_collection_builder which was called 5 times, avg 6µs/call:
# 5 times (29µs+0s) by Sub::Exporter::_collect_collections at line 175, avg 6µs/call | ||||
| 130 | 5 | 10µs | my ($col, $etc) = @_; | ||
| 131 | 5 | 3µs | my ($config, $import_args, $class, $into) = @$etc; | ||
| 132 | |||||
| 133 | 5 | 500ns | my %seen; | ||
| 134 | # spent 45µs (33+11) within Sub::Exporter::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Exporter.pm:159] which was called 3 times, avg 15µs/call:
# 3 times (33µs+11µs) by Sub::Exporter::_collect_collections at line 177, avg 15µs/call | ||||
| 135 | 3 | 600ns | my ($collection) = @_; | ||
| 136 | 3 | 1µs | my ($name, $value) = @$collection; | ||
| 137 | |||||
| 138 | 3 | 2µs | Carp::croak "collection $name provided multiple times in import" | ||
| 139 | if $seen{ $name }++; | ||||
| 140 | |||||
| 141 | 3 | 2µs | if (ref(my $hook = $config->{collectors}{$name})) { | ||
| 142 | 2 | 4µs | my $arg = { | ||
| 143 | name => $name, | ||||
| 144 | config => $config, | ||||
| 145 | import_args => $import_args, | ||||
| 146 | class => $class, | ||||
| 147 | into => $into, | ||||
| 148 | }; | ||||
| 149 | |||||
| 150 | 2 | 2µs | my $error_msg = "collection $name failed validation"; | ||
| 151 | 2 | 11µs | 2 | 2µs | if (Params::Util::_SCALAR0($hook)) { ## no critic Private # spent 2µs making 2 calls to Params::Util::_SCALAR0, avg 950ns/call |
| 152 | Carp::croak $error_msg unless $class->$$hook($value, $arg); | ||||
| 153 | } else { | ||||
| 154 | 2 | 2µs | 2 | 10µs | Carp::croak $error_msg unless $hook->($value, $arg); # spent 10µs making 2 calls to Sub::Exporter::_setup, avg 5µs/call |
| 155 | } | ||||
| 156 | } | ||||
| 157 | |||||
| 158 | 3 | 8µs | $col->{ $name } = $value; | ||
| 159 | } | ||||
| 160 | 5 | 22µs | } | ||
| 161 | |||||
| 162 | # Given a config and pre-canonicalized importer args, remove collections from | ||||
| 163 | # the args and return them. | ||||
| 164 | # spent 150µs (76+74) within Sub::Exporter::_collect_collections which was called 5 times, avg 30µs/call:
# 5 times (76µs+74µs) by Sub::Exporter::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Exporter.pm:337] at line 321, avg 30µs/call | ||||
| 165 | 5 | 2µs | my ($config, $import_args, $class, $into) = @_; | ||
| 166 | |||||
| 167 | my @collections | ||||
| 168 | = map { splice @$import_args, $_, 1 } | ||||
| 169 | 5 | 15µs | grep { exists $config->{collectors}{ $import_args->[$_][0] } } | ||
| 170 | reverse 0 .. $#$import_args; | ||||
| 171 | |||||
| 172 | 5 | 1µs | unshift @collections, [ INIT => {} ] if $config->{collectors}{INIT}; | ||
| 173 | |||||
| 174 | 5 | 2µs | my $col = {}; | ||
| 175 | 5 | 7µs | 5 | 29µs | my $builder = _mk_collection_builder($col, \@_); # spent 29µs making 5 calls to Sub::Exporter::_mk_collection_builder, avg 6µs/call |
| 176 | 5 | 3µs | for my $collection (@collections) { | ||
| 177 | 3 | 6µs | 3 | 45µs | $builder->($collection) # spent 45µs making 3 calls to Sub::Exporter::__ANON__[Sub/Exporter.pm:159], avg 15µs/call |
| 178 | } | ||||
| 179 | |||||
| 180 | 5 | 34µs | return $col; | ||
| 181 | } | ||||
| 182 | |||||
| 183 | |||||
| 184 | # spent 304µs (16+288) within Sub::Exporter::setup_exporter which was called:
# once (16µs+288µs) by Path::IsDev::BEGIN@261 at line 461 | ||||
| 185 | 1 | 400ns | my ($config) = @_; | ||
| 186 | |||||
| 187 | 1 | 400ns | Carp::croak 'into and into_level may not both be supplied to exporter' | ||
| 188 | if exists $config->{into} and exists $config->{into_level}; | ||||
| 189 | |||||
| 190 | 1 | 700ns | my $as = delete $config->{as} || 'import'; | ||
| 191 | 1 | 800ns | my $into | ||
| 192 | = exists $config->{into} ? delete $config->{into} | ||||
| 193 | : exists $config->{into_level} ? caller(delete $config->{into_level}) | ||||
| 194 | : caller(0); | ||||
| 195 | |||||
| 196 | 1 | 1µs | 1 | 232µs | my $import = build_exporter($config); # spent 232µs making 1 call to Sub::Exporter::build_exporter |
| 197 | |||||
| 198 | 1 | 6µs | 1 | 57µs | Sub::Install::reinstall_sub({ # spent 57µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:57] |
| 199 | code => $import, | ||||
| 200 | into => $into, | ||||
| 201 | as => $as, | ||||
| 202 | }); | ||||
| 203 | } | ||||
| 204 | |||||
| 205 | |||||
| 206 | # spent 18µs within Sub::Exporter::_key_intersection which was called 4 times, avg 5µs/call:
# 4 times (18µs+0s) by Sub::Exporter::_rewrite_build_config at line 262, avg 5µs/call | ||||
| 207 | 4 | 900ns | my ($x, $y) = @_; | ||
| 208 | 4 | 9µs | my %seen = map { $_ => 1 } keys %$x; | ||
| 209 | 4 | 12µs | my @names = grep { $seen{$_} } keys %$y; | ||
| 210 | } | ||||
| 211 | |||||
| 212 | # Given the config passed to setup_exporter, which contains sugary opt list | ||||
| 213 | # data, rewrite the opt lists into hashes, catch a few kinds of invalid | ||||
| 214 | # configurations, and set up defaults. Since the config is a reference, it's | ||||
| 215 | # rewritten in place. | ||||
| 216 | 1 | 100ns | my %valid_config_key; | ||
| 217 | # spent 9µs within Sub::Exporter::BEGIN@217 which was called:
# once (9µs+0s) by Path::IsDev::BEGIN@261 at line 222 | ||||
| 218 | %valid_config_key = | ||||
| 219 | 1 | 10µs | map { $_ => 1 } | ||
| 220 | qw(as collectors installer generator exports groups into into_level), | ||||
| 221 | qw(exporter), # deprecated | ||||
| 222 | 1 | 959µs | 1 | 9µs | } # spent 9µs making 1 call to Sub::Exporter::BEGIN@217 |
| 223 | |||||
| 224 | # spent 23µs (19+4) within Sub::Exporter::_assert_collector_names_ok which was called 4 times, avg 6µs/call:
# 4 times (19µs+4µs) by Sub::Exporter::_rewrite_build_config at line 260, avg 6µs/call | ||||
| 225 | 4 | 800ns | my ($collectors) = @_; | ||
| 226 | |||||
| 227 | 6 | 26µs | 2 | 4µs | for my $reserved_name (grep { /\A[_A-Z]+\z/ } keys %$collectors) { # spent 4µs making 2 calls to Sub::Exporter::CORE:match, avg 2µs/call |
| 228 | Carp::croak "unknown reserved collector name: $reserved_name" | ||||
| 229 | if $reserved_name ne 'INIT'; | ||||
| 230 | } | ||||
| 231 | } | ||||
| 232 | |||||
| 233 | # spent 565µs (125+439) within Sub::Exporter::_rewrite_build_config which was called 4 times, avg 141µs/call:
# 4 times (125µs+439µs) by Sub::Exporter::build_exporter at line 290, avg 141µs/call | ||||
| 234 | 4 | 500ns | my ($config) = @_; | ||
| 235 | |||||
| 236 | 4 | 9µs | if (my @keys = grep { not exists $valid_config_key{$_} } keys %$config) { | ||
| 237 | Carp::croak "unknown options (@keys) passed to Sub::Exporter"; | ||||
| 238 | } | ||||
| 239 | |||||
| 240 | 4 | 1µs | Carp::croak q(into and into_level may not both be supplied to exporter) | ||
| 241 | if exists $config->{into} and exists $config->{into_level}; | ||||
| 242 | |||||
| 243 | # XXX: Remove after deprecation period. | ||||
| 244 | 4 | 700ns | if ($config->{exporter}) { | ||
| 245 | Carp::cluck "'exporter' argument to build_exporter is deprecated. Use 'installer' instead; the semantics are identical."; | ||||
| 246 | $config->{installer} = delete $config->{exporter}; | ||||
| 247 | } | ||||
| 248 | |||||
| 249 | 4 | 400ns | Carp::croak q(into and into_level may not both be supplied to exporter) | ||
| 250 | if exists $config->{into} and exists $config->{into_level}; | ||||
| 251 | |||||
| 252 | 4 | 2µs | for (qw(exports collectors)) { | ||
| 253 | 8 | 35µs | 8 | 271µs | $config->{$_} = Data::OptList::mkopt_hash( # spent 271µs making 8 calls to Data::OptList::mkopt_hash, avg 34µs/call |
| 254 | $config->{$_}, | ||||
| 255 | $_, | ||||
| 256 | [ 'CODE', 'SCALAR' ], | ||||
| 257 | ); | ||||
| 258 | } | ||||
| 259 | |||||
| 260 | 4 | 6µs | 4 | 23µs | _assert_collector_names_ok($config->{collectors}); # spent 23µs making 4 calls to Sub::Exporter::_assert_collector_names_ok, avg 6µs/call |
| 261 | |||||
| 262 | 4 | 7µs | 4 | 18µs | if (my @names = _key_intersection(@$config{qw(exports collectors)})) { # spent 18µs making 4 calls to Sub::Exporter::_key_intersection, avg 5µs/call |
| 263 | Carp::croak "names (@names) used in both collections and exports"; | ||||
| 264 | } | ||||
| 265 | |||||
| 266 | 4 | 13µs | 4 | 127µs | $config->{groups} = Data::OptList::mkopt_hash( # spent 127µs making 4 calls to Data::OptList::mkopt_hash, avg 32µs/call |
| 267 | $config->{groups}, | ||||
| 268 | 'groups', | ||||
| 269 | [ | ||||
| 270 | 'HASH', # standard opt list | ||||
| 271 | 'ARRAY', # standard opt list | ||||
| 272 | 'CODE', # group generator | ||||
| 273 | 'SCALAR', # name of group generation method | ||||
| 274 | ] | ||||
| 275 | ); | ||||
| 276 | |||||
| 277 | # by default, export nothing | ||||
| 278 | 4 | 2µs | $config->{groups}{default} ||= []; | ||
| 279 | |||||
| 280 | # by default, build an all-inclusive 'all' group | ||||
| 281 | 4 | 2µs | $config->{groups}{all} ||= [ keys %{ $config->{exports} } ]; | ||
| 282 | |||||
| 283 | 4 | 2µs | $config->{generator} ||= \&default_generator; | ||
| 284 | 4 | 20µs | $config->{installer} ||= \&default_installer; | ||
| 285 | } | ||||
| 286 | |||||
| 287 | # spent 594µs (29+565) within Sub::Exporter::build_exporter which was called 4 times, avg 148µs/call:
# 2 times (14µs+146µs) by Sub::Exporter::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Exporter.pm:460] at line 460, avg 80µs/call
# once (8µs+224µs) by Sub::Exporter::setup_exporter at line 196
# once (7µs+195µs) by Pod::Wordlist::BEGIN@5 at line 239 of File/ShareDir/ProjectDistDir.pm | ||||
| 288 | 4 | 1µs | my ($config) = @_; | ||
| 289 | |||||
| 290 | 4 | 4µs | 4 | 565µs | _rewrite_build_config($config); # spent 565µs making 4 calls to Sub::Exporter::_rewrite_build_config, avg 141µs/call |
| 291 | |||||
| 292 | # spent 922µs (98+825) within Sub::Exporter::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Exporter.pm:337] which was called 5 times, avg 184µs/call:
# once (23µs+238µs) by Path::IsDev::BEGIN@261 at line 261 of Path/IsDev.pm
# once (19µs+220µs) by Path::FindDev::BEGIN@57 at line 57 of Path/FindDev.pm
# once (19µs+166µs) by Pod::Wordlist::BEGIN@5 at line 460 of File/ShareDir/ProjectDistDir.pm
# once (18µs+102µs) by File::ShareDir::ProjectDistDir::BEGIN@235 at line 235 of File/ShareDir/ProjectDistDir.pm
# once (18µs+98µs) by File::ShareDir::ProjectDistDir::BEGIN@236 at line 236 of File/ShareDir/ProjectDistDir.pm | ||||
| 293 | 5 | 2µs | my ($class) = shift; | ||
| 294 | |||||
| 295 | # XXX: clean this up -- rjbs, 2006-03-16 | ||||
| 296 | 5 | 3µs | my $special = (ref $_[0]) ? shift(@_) : {}; | ||
| 297 | 5 | 2µs | Carp::croak q(into and into_level may not both be supplied to exporter) | ||
| 298 | if exists $special->{into} and exists $special->{into_level}; | ||||
| 299 | |||||
| 300 | 5 | 1µs | if ($special->{exporter}) { | ||
| 301 | Carp::cluck "'exporter' special import argument is deprecated. Use 'installer' instead; the semantics are identical."; | ||||
| 302 | $special->{installer} = delete $special->{exporter}; | ||||
| 303 | } | ||||
| 304 | |||||
| 305 | 5 | 5µs | my $into | ||
| 306 | = defined $special->{into} ? delete $special->{into} | ||||
| 307 | : defined $special->{into_level} ? caller(delete $special->{into_level}) | ||||
| 308 | : defined $config->{into} ? $config->{into} | ||||
| 309 | : defined $config->{into_level} ? caller($config->{into_level}) | ||||
| 310 | : caller(0); | ||||
| 311 | |||||
| 312 | 5 | 2µs | my $generator = delete $special->{generator} || $config->{generator}; | ||
| 313 | 5 | 1µs | my $installer = delete $special->{installer} || $config->{installer}; | ||
| 314 | |||||
| 315 | # this builds a AOA, where the inner arrays are [ name => value_ref ] | ||||
| 316 | 5 | 10µs | 5 | 71µs | my $import_args = Data::OptList::mkopt([ @_ ]); # spent 71µs making 5 calls to Data::OptList::mkopt, avg 14µs/call |
| 317 | |||||
| 318 | # is this right? defaults first or collectors first? -- rjbs, 2006-06-24 | ||||
| 319 | 5 | 900ns | $import_args = [ [ -default => undef ] ] unless @$import_args; | ||
| 320 | |||||
| 321 | 5 | 6µs | 5 | 150µs | my $collection = _collect_collections($config, $import_args, $class, $into); # spent 150µs making 5 calls to Sub::Exporter::_collect_collections, avg 30µs/call |
| 322 | |||||
| 323 | 5 | 6µs | 5 | 56µs | my $to_import = _expand_groups($class, $config, $import_args, $collection); # spent 56µs making 5 calls to Sub::Exporter::_expand_groups, avg 11µs/call |
| 324 | |||||
| 325 | # now, finally $import_arg is really the "to do" list | ||||
| 326 | 5 | 34µs | 5 | 548µs | _do_import( # spent 548µs making 5 calls to Sub::Exporter::_do_import, avg 110µs/call |
| 327 | { | ||||
| 328 | class => $class, | ||||
| 329 | col => $collection, | ||||
| 330 | config => $config, | ||||
| 331 | into => $into, | ||||
| 332 | generator => $generator, | ||||
| 333 | installer => $installer, | ||||
| 334 | }, | ||||
| 335 | $to_import, | ||||
| 336 | ); | ||||
| 337 | 4 | 12µs | }; | ||
| 338 | |||||
| 339 | 4 | 16µs | return $import; | ||
| 340 | } | ||||
| 341 | |||||
| 342 | # spent 548µs (81+467) within Sub::Exporter::_do_import which was called 5 times, avg 110µs/call:
# 5 times (81µs+467µs) by Sub::Exporter::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Exporter.pm:337] at line 326, avg 110µs/call | ||||
| 343 | 5 | 1µs | my ($arg, $to_import) = @_; | ||
| 344 | |||||
| 345 | 5 | 500ns | my @todo; | ||
| 346 | |||||
| 347 | 5 | 3µs | for my $pair (@$to_import) { | ||
| 348 | 5 | 1µs | my ($name, $import_arg) = @$pair; | ||
| 349 | |||||
| 350 | 5 | 300ns | my ($generator, $as); | ||
| 351 | |||||
| 352 | 5 | 7µs | 2 | 2µs | if ($import_arg and Params::Util::_CODELIKE($import_arg)) { ## no critic # spent 2µs making 2 calls to Params::Util::_CODELIKE, avg 800ns/call |
| 353 | # This is the case when a group generator has inserted name/code pairs. | ||||
| 354 | $generator = sub { $import_arg }; | ||||
| 355 | $as = $name; | ||||
| 356 | } else { | ||||
| 357 | 5 | 5µs | $import_arg = { $import_arg ? %$import_arg : () }; | ||
| 358 | |||||
| 359 | 5 | 3µs | Carp::croak qq("$name" is not exported by the $arg->{class} module) | ||
| 360 | unless exists $arg->{config}{exports}{$name}; | ||||
| 361 | |||||
| 362 | 5 | 2µs | $generator = $arg->{config}{exports}{$name}; | ||
| 363 | |||||
| 364 | 5 | 4µs | $as = exists $import_arg->{-as} ? (delete $import_arg->{-as}) : $name; | ||
| 365 | } | ||||
| 366 | |||||
| 367 | 5 | 17µs | 5 | 252µs | my $code = $arg->{generator}->( # spent 252µs making 5 calls to Sub::Exporter::default_generator, avg 50µs/call |
| 368 | { | ||||
| 369 | class => $arg->{class}, | ||||
| 370 | name => $name, | ||||
| 371 | arg => $import_arg, | ||||
| 372 | col => $arg->{col}, | ||||
| 373 | generator => $generator, | ||||
| 374 | } | ||||
| 375 | ); | ||||
| 376 | |||||
| 377 | 5 | 7µs | push @todo, $as, $code; | ||
| 378 | } | ||||
| 379 | |||||
| 380 | 5 | 22µs | 5 | 214µs | $arg->{installer}->( # spent 214µs making 5 calls to Sub::Exporter::default_installer, avg 43µs/call |
| 381 | { | ||||
| 382 | class => $arg->{class}, | ||||
| 383 | into => $arg->{into}, | ||||
| 384 | col => $arg->{col}, | ||||
| 385 | }, | ||||
| 386 | \@todo, | ||||
| 387 | ); | ||||
| 388 | } | ||||
| 389 | |||||
| 390 | ## Cute idea, possibly for future use: also supply an "unimport" for: | ||||
| 391 | ## no Module::Whatever qw(arg arg arg); | ||||
| 392 | # sub _unexport { | ||||
| 393 | # my (undef, undef, undef, undef, undef, $as, $into) = @_; | ||||
| 394 | # | ||||
| 395 | # if (ref $as eq 'SCALAR') { | ||||
| 396 | # undef $$as; | ||||
| 397 | # } elsif (ref $as) { | ||||
| 398 | # Carp::croak "invalid reference type for $as: " . ref $as; | ||||
| 399 | # } else { | ||||
| 400 | # no strict 'refs'; | ||||
| 401 | # delete &{$into . '::' . $as}; | ||||
| 402 | # } | ||||
| 403 | # } | ||||
| 404 | |||||
| 405 | |||||
| 406 | # spent 252µs (40+212) within Sub::Exporter::default_generator which was called 5 times, avg 50µs/call:
# 5 times (40µs+212µs) by Sub::Exporter::_do_import at line 367, avg 50µs/call | ||||
| 407 | 5 | 1µs | my ($arg) = @_; | ||
| 408 | 5 | 4µs | my ($class, $name, $generator) = @$arg{qw(class name generator)}; | ||
| 409 | |||||
| 410 | 5 | 600ns | if (not defined $generator) { | ||
| 411 | 1 | 8µs | 1 | 2µs | my $code = $class->can($name) # spent 2µs making 1 call to UNIVERSAL::can |
| 412 | or Carp::croak "can't locate exported subroutine $name via $class"; | ||||
| 413 | 1 | 2µs | return $code; | ||
| 414 | } | ||||
| 415 | |||||
| 416 | # I considered making this "$class->$generator(" but it seems that | ||||
| 417 | # overloading precedence would turn an overloaded-as-code generator object | ||||
| 418 | # into a string before code. -- rjbs, 2006-06-11 | ||||
| 419 | 4 | 24µs | 8 | 210µs | return $generator->($class, $name, $arg->{arg}, $arg->{col}) # spent 168µs making 2 calls to Sub::Exporter::__ANON__[Sub/Exporter.pm:460], avg 84µs/call
# spent 36µs making 1 call to File::ShareDir::ProjectDistDir::build_dist_file
# spent 3µs making 1 call to Path::FindDev::_build_find_dev
# spent 3µs making 4 calls to Params::Util::_CODELIKE, avg 675ns/call |
| 420 | if Params::Util::_CODELIKE($generator); ## no critic Private | ||||
| 421 | |||||
| 422 | # This "must" be a scalar reference, to a generator method name. | ||||
| 423 | # -- rjbs, 2006-12-05 | ||||
| 424 | return $class->$$generator($name, $arg->{arg}, $arg->{col}); | ||||
| 425 | } | ||||
| 426 | |||||
| 427 | |||||
| 428 | # spent 214µs (39+174) within Sub::Exporter::default_installer which was called 5 times, avg 43µs/call:
# 5 times (39µs+174µs) by Sub::Exporter::_do_import at line 380, avg 43µs/call | ||||
| 429 | 5 | 1µs | my ($arg, $to_export) = @_; | ||
| 430 | |||||
| 431 | 5 | 18µs | for (my $i = 0; $i < @$to_export; $i += 2) { | ||
| 432 | 5 | 4µs | my ($as, $code) = @$to_export[ $i, $i+1 ]; | ||
| 433 | |||||
| 434 | # Allow as isa ARRAY to push onto an array? | ||||
| 435 | # Allow into isa HASH to install name=>code into hash? | ||||
| 436 | |||||
| 437 | 5 | 2µs | if (ref $as eq 'SCALAR') { | ||
| 438 | $$as = $code; | ||||
| 439 | } elsif (ref $as) { | ||||
| 440 | Carp::croak "invalid reference type for $as: " . ref $as; | ||||
| 441 | } else { | ||||
| 442 | 5 | 10µs | 5 | 174µs | Sub::Install::reinstall_sub({ # spent 174µs making 5 calls to Sub::Install::__ANON__[Sub/Install.pm:57], avg 35µs/call |
| 443 | code => $code, | ||||
| 444 | into => $arg->{into}, | ||||
| 445 | as => $as | ||||
| 446 | }); | ||||
| 447 | } | ||||
| 448 | } | ||||
| 449 | } | ||||
| 450 | |||||
| 451 | sub default_exporter { | ||||
| 452 | Carp::cluck "default_exporter is deprecated; call default_installer instead; the semantics are identical"; | ||||
| 453 | goto &default_installer; | ||||
| 454 | } | ||||
| 455 | |||||
| 456 | |||||
| 457 | setup_exporter({ | ||||
| 458 | exports => [ | ||||
| 459 | qw(setup_exporter build_exporter), | ||||
| 460 | 2 | 6µs | 2 | 160µs | # spent 168µs (8+160) within Sub::Exporter::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Exporter.pm:460] which was called 2 times, avg 84µs/call:
# 2 times (8µs+160µs) by Sub::Exporter::default_generator at line 419, avg 84µs/call # spent 160µs making 2 calls to Sub::Exporter::build_exporter, avg 80µs/call |
| 461 | 1 | 9µs | 1 | 304µs | ], # spent 304µs making 1 call to Sub::Exporter::setup_exporter |
| 462 | groups => { | ||||
| 463 | all => [ qw(setup_exporter build_export) ], | ||||
| 464 | }, | ||||
| 465 | collectors => { -setup => \&_setup }, | ||||
| 466 | }); | ||||
| 467 | |||||
| 468 | # spent 10µs within Sub::Exporter::_setup which was called 2 times, avg 5µs/call:
# 2 times (10µs+0s) by Sub::Exporter::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Sub/Exporter.pm:159] at line 154, avg 5µs/call | ||||
| 469 | 2 | 400ns | my ($value, $arg) = @_; | ||
| 470 | |||||
| 471 | 2 | 800ns | if (ref $value eq 'HASH') { | ||
| 472 | 2 | 5µs | push @{ $arg->{import_args} }, [ _import => { -as => 'import', %$value } ]; | ||
| 473 | 2 | 6µs | return 1; | ||
| 474 | } elsif (ref $value eq 'ARRAY') { | ||||
| 475 | push @{ $arg->{import_args} }, | ||||
| 476 | [ _import => { -as => 'import', exports => $value } ]; | ||||
| 477 | return 1; | ||||
| 478 | } | ||||
| 479 | return; | ||||
| 480 | } | ||||
| 481 | |||||
| - - | |||||
| 484 | 1 | 6µs | "jn8:32"; # <-- magic true value | ||
| 485 | |||||
| 486 | __END__ | ||||
# spent 4µs within Sub::Exporter::CORE:match which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by Sub::Exporter::_assert_collector_names_ok at line 227, avg 2µs/call |