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

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm
StatementsExecuted 957 statements in 6.41ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1115.31ms112msMoose::Exporter::::BEGIN@13Moose::Exporter::BEGIN@13
1112.91ms3.56msMoose::Exporter::::BEGIN@17Moose::Exporter::BEGIN@17
1111.06ms1.36msMoose::Exporter::::BEGIN@15Moose::Exporter::BEGIN@15
211283µs436µsMoose::Exporter::::_make_sub_exporter_paramsMoose::Exporter::_make_sub_exporter_params
211153µs2.18msMoose::Exporter::::build_import_methodsMoose::Exporter::build_import_methods
222122µs7.50msMoose::Exporter::::__ANON__[:519]Moose::Exporter::__ANON__[:519]
211122µs906µsMoose::Exporter::::__ANON__[:137]Moose::Exporter::__ANON__[:137]
2921101µs101µsMoose::Exporter::::_sub_from_packageMoose::Exporter::_sub_from_package
81182µs164µsMoose::Exporter::::__ANON__[:379]Moose::Exporter::__ANON__[:379]
81163µs63µsMoose::Exporter::::_late_curry_wrapperMoose::Exporter::_late_curry_wrapper
21146µs46µsMoose::Exporter::::_collect_metarolesMoose::Exporter::_collect_metaroles
81140µs40µsMoose::Exporter::::_make_wrapped_sub_with_metaMoose::Exporter::_make_wrapped_sub_with_meta
21137µs37µsMoose::Exporter::::_make_init_metaMoose::Exporter::_make_init_meta
21132µs1.18msMoose::Exporter::::_make_exporterMoose::Exporter::_make_exporter
21132µs54µsMoose::Exporter::::_strip_traitsMoose::Exporter::_strip_traits
231132µs32µsMoose::Exporter::::__ANON__[:307]Moose::Exporter::__ANON__[:307]
22231µs2.21msMoose::Exporter::::setup_import_methodsMoose::Exporter::setup_import_methods
21128µs99µsMoose::Exporter::::_follow_alsoMoose::Exporter::_follow_also
21128µs98µsMoose::Exporter::::_apply_metarolesMoose::Exporter::_apply_metaroles
21125µs39µsMoose::Exporter::::_die_if_cycle_found_in_also_list_for_packageMoose::Exporter::_die_if_cycle_found_in_also_list_for_package
21120µs20µsMoose::Exporter::::_make_import_subMoose::Exporter::_make_import_sub
21119µs23µsMoose::Exporter::::_strip_metaclassMoose::Exporter::_strip_metaclass
22219µs63µsMoose::Exporter::::importMoose::Exporter::import
21118µs22µsMoose::Exporter::::_strip_meta_nameMoose::Exporter::_strip_meta_name
42117µs39µsMoose::Exporter::::__ANON__[:42]Moose::Exporter::__ANON__[:42]
21113µs16µsMoose::Exporter::::_follow_also_realMoose::Exporter::_follow_also_real
21112µs12µsMoose::Exporter::::_make_unimport_subMoose::Exporter::_make_unimport_sub
42112µs12µsMoose::Exporter::::_also_list_for_packageMoose::Exporter::_also_list_for_package
11111µs11µsMoose::Exporter::::BEGIN@2Moose::Exporter::BEGIN@2
21110µs10µsMoose::Exporter::::_parse_trait_aliasesMoose::Exporter::_parse_trait_aliases
11110µs55µsMoose::Exporter::::BEGIN@14Moose::Exporter::BEGIN@14
11110µs24µsMoose::Exporter::::BEGIN@132Moose::Exporter::BEGIN@132
11110µs25µsMoose::Exporter::::BEGIN@133Moose::Exporter::BEGIN@133
11110µs24µsMoose::Exporter::::BEGIN@321Moose::Exporter::BEGIN@321
21110µs10µsMoose::Exporter::::_flag_as_reexportMoose::Exporter::_flag_as_reexport (xsub)
1119µs38µsMoose::Exporter::::BEGIN@18Moose::Exporter::BEGIN@18
1119µs39µsMoose::Exporter::::BEGIN@16Moose::Exporter::BEGIN@16
1119µs24µsMoose::Exporter::::BEGIN@716Moose::Exporter::BEGIN@716
1119µs14µsMoose::Exporter::::BEGIN@10Moose::Exporter::BEGIN@10
1119µs22µsMoose::Exporter::::BEGIN@726Moose::Exporter::BEGIN@726
1118µs37µsMoose::Exporter::::BEGIN@12Moose::Exporter::BEGIN@12
1118µs24µsMoose::Exporter::::BEGIN@9Moose::Exporter::BEGIN@9
2118µs8µsMoose::Exporter::::_get_callerMoose::Exporter::_get_caller
1117µs14µsMoose::Exporter::::__ANON__[:252]Moose::Exporter::__ANON__[:252]
2116µs6µsMoose::Exporter::::_die_if_also_list_cycles_back_to_existing_stackMoose::Exporter::_die_if_also_list_cycles_back_to_existing_stack
0000s0sMoose::Exporter::::__ANON__[:228]Moose::Exporter::__ANON__[:228]
0000s0sMoose::Exporter::::__ANON__[:356]Moose::Exporter::__ANON__[:356]
0000s0sMoose::Exporter::::__ANON__[:388]Moose::Exporter::__ANON__[:388]
0000s0sMoose::Exporter::::__ANON__[:410]Moose::Exporter::__ANON__[:410]
0000s0sMoose::Exporter::::__ANON__[:523]Moose::Exporter::__ANON__[:523]
0000s0sMoose::Exporter::::__ANON__[:537]Moose::Exporter::__ANON__[:537]
0000s0sMoose::Exporter::::__ANON__[:549]Moose::Exporter::__ANON__[:549]
0000s0sMoose::Exporter::::__ANON__[:706]Moose::Exporter::__ANON__[:706]
0000s0sMoose::Exporter::::__ANON__[:778]Moose::Exporter::__ANON__[:778]
0000s0sMoose::Exporter::::_apply_meta_traitsMoose::Exporter::_apply_meta_traits
0000s0sMoose::Exporter::::_curry_wrapperMoose::Exporter::_curry_wrapper
0000s0sMoose::Exporter::::_make_wrapped_subMoose::Exporter::_make_wrapped_sub
0000s0sMoose::Exporter::::_remove_keywordsMoose::Exporter::_remove_keywords
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Moose::Exporter;
2
# spent 11µs within Moose::Exporter::BEGIN@2 which was called: # once (11µs+0s) by Moose::BEGIN@18 at line 4
BEGIN {
316µs $Moose::Exporter::AUTHORITY = 'cpan:STEVAN';
4145µs111µs}
# spent 11µs making 1 call to Moose::Exporter::BEGIN@2
5{
621µs $Moose::Exporter::VERSION = '2.1005';
7}
8
9231µs241µs
# spent 24µs (8+16) within Moose::Exporter::BEGIN@9 which was called: # once (8µs+16µs) by Moose::BEGIN@18 at line 9
use strict;
# spent 24µs making 1 call to Moose::Exporter::BEGIN@9 # spent 16µs making 1 call to strict::import
10232µs218µs
# spent 14µs (9+5) within Moose::Exporter::BEGIN@10 which was called: # once (9µs+5µs) by Moose::BEGIN@18 at line 10
use warnings;
# spent 14µs making 1 call to Moose::Exporter::BEGIN@10 # spent 5µs making 1 call to warnings::import
11
12231µs266µs
# spent 37µs (8+29) within Moose::Exporter::BEGIN@12 which was called: # once (8µs+29µs) by Moose::BEGIN@18 at line 12
use Class::Load qw(is_class_loaded);
# spent 37µs making 1 call to Moose::Exporter::BEGIN@12 # spent 29µs making 1 call to Exporter::import
132147µs1112ms
# spent 112ms (5.31+106) within Moose::Exporter::BEGIN@13 which was called: # once (5.31ms+106ms) by Moose::BEGIN@18 at line 13
use Class::MOP;
# spent 112ms making 1 call to Moose::Exporter::BEGIN@13
14232µs2100µs
# spent 55µs (10+45) within Moose::Exporter::BEGIN@14 which was called: # once (10µs+45µs) by Moose::BEGIN@18 at line 14
use List::MoreUtils qw( first_index uniq );
# spent 55µs making 1 call to Moose::Exporter::BEGIN@14 # spent 45µs making 1 call to Exporter::import
152147µs11.36ms
# spent 1.36ms (1.06+301µs) within Moose::Exporter::BEGIN@15 which was called: # once (1.06ms+301µs) by Moose::BEGIN@18 at line 15
use Moose::Util::MetaRole;
# spent 1.36ms making 1 call to Moose::Exporter::BEGIN@15
16236µs269µs
# spent 39µs (9+30) within Moose::Exporter::BEGIN@16 which was called: # once (9µs+30µs) by Moose::BEGIN@18 at line 16
use Scalar::Util qw(reftype);
# spent 39µs making 1 call to Moose::Exporter::BEGIN@16 # spent 30µs making 1 call to Exporter::import
173138µs33.71ms
# spent 3.56ms (2.91+642µs) within Moose::Exporter::BEGIN@17 which was called: # once (2.91ms+642µs) by Moose::BEGIN@18 at line 17
use Sub::Exporter 0.980;
# spent 3.56ms making 1 call to Moose::Exporter::BEGIN@17 # spent 142µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] # spent 10µs making 1 call to UNIVERSAL::VERSION
182542µs267µs
# spent 38µs (9+29) within Moose::Exporter::BEGIN@18 which was called: # once (9µs+29µs) by Moose::BEGIN@18 at line 18
use Sub::Name qw(subname);
# spent 38µs making 1 call to Moose::Exporter::BEGIN@18 # spent 29µs making 1 call to Exporter::import
19
201100nsmy %EXPORT_SPEC;
21
22
# spent 2.21ms (31µs+2.18) within Moose::Exporter::setup_import_methods which was called 2 times, avg 1.10ms/call: # once (15µs+1.25ms) by Moose::Meta::Attribute::BEGIN@24 at line 44 of Moose/Util/TypeConstraints.pm # once (16µs+924µs) by Foo::Moose::BEGIN@91 at line 137 of Moose.pm
sub setup_import_methods {
2324µs my ( $class, %args ) = @_;
24
2524µs $args{exporting_package} ||= caller();
26
27219µs22.18ms $class->build_import_methods(
# spent 2.18ms making 2 calls to Moose::Exporter::build_import_methods, avg 1.09ms/call
28 %args,
29 install => [qw(import unimport init_meta)]
30 );
31}
32
33# A reminder to intrepid Moose hackers
34# there may be more than one level of exporter
35# don't make doy cry. -- perigrin
36
37
# spent 2.18ms (153µs+2.02) within Moose::Exporter::build_import_methods which was called 2 times, avg 1.09ms/call: # 2 times (153µs+2.02ms) by Moose::Exporter::setup_import_methods at line 27, avg 1.09ms/call
sub build_import_methods {
3823µs my ( $class, %args ) = @_;
39
4022µs my $exporting_package = $args{exporting_package} ||= caller();
41
42623µs422µs
# spent 39µs (17+22) within Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:42] which was called 4 times, avg 10µs/call: # 2 times (11µs+12µs) by Moose::Exporter::_apply_metaroles at line 566, avg 11µs/call # 2 times (6µs+11µs) by Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:137] at line 108, avg 8µs/call
my $meta_lookup = $args{meta_lookup} || sub { Class::MOP::class_of(shift) };
# spent 22µs making 4 calls to Class::MOP::class_of, avg 6µs/call
43
4422µs $EXPORT_SPEC{$exporting_package} = \%args;
45
4626µs299µs my @exports_from = $class->_follow_also($exporting_package);
# spent 99µs making 2 calls to Moose::Exporter::_follow_also, avg 50µs/call
47
4821µs my $export_recorder = {};
492900ns my $is_reexport = {};
50
51210µs2436µs my $exports = $class->_make_sub_exporter_params(
# spent 436µs making 2 calls to Moose::Exporter::_make_sub_exporter_params, avg 218µs/call
52 [ $exporting_package, @exports_from ],
53 $export_recorder,
54 $is_reexport,
55 $args{meta_lookup}, # so that we don't pass through the default
56 );
57
5827µs21.18ms my $exporter = $class->_make_exporter(
# spent 1.18ms making 2 calls to Moose::Exporter::_make_exporter, avg 591µs/call
59 $exports,
60 $is_reexport,
61 $meta_lookup,
62 );
63
642300ns my %methods;
6528µs220µs $methods{import} = $class->_make_import_sub(
# spent 20µs making 2 calls to Moose::Exporter::_make_import_sub, avg 10µs/call
66 $exporting_package,
67 $exporter,
68 \@exports_from,
69 $is_reexport,
70 $meta_lookup,
71 );
72
7326µs212µs $methods{unimport} = $class->_make_unimport_sub(
# spent 12µs making 2 calls to Moose::Exporter::_make_unimport_sub, avg 6µs/call
74 $exporting_package,
75 $exports,
76 $export_recorder,
77 $is_reexport,
78 $meta_lookup,
79 );
80
8127µs237µs $methods{init_meta} = $class->_make_init_meta(
# spent 37µs making 2 calls to Moose::Exporter::_make_init_meta, avg 19µs/call
82 $exporting_package,
83 \%args,
84 $meta_lookup,
85 );
86
8726µs264µs my $package = Class::MOP::Package->initialize($exporting_package);
# spent 64µs making 2 calls to Class::MOP::Package::initialize, avg 32µs/call
8824µs for my $to_install ( @{ $args{install} || [] } ) {
8963µs my $symbol = '&' . $to_install;
90 next
91612µs4100µs unless $methods{$to_install}
# spent 100µs making 4 calls to Class::MOP::Package::has_package_symbol, avg 25µs/call
92 && !$package->has_package_symbol($symbol);
9349µs473µs $package->add_package_symbol( $symbol, $methods{$to_install} );
# spent 73µs making 4 calls to Class::MOP::Package::add_package_symbol, avg 18µs/call
94 }
95
96211µs return ( $methods{import}, $methods{unimport}, $methods{init_meta} );
97}
98
99
# spent 1.18ms (32µs+1.15) within Moose::Exporter::_make_exporter which was called 2 times, avg 591µs/call: # 2 times (32µs+1.15ms) by Moose::Exporter::build_import_methods at line 58, avg 591µs/call
sub _make_exporter {
10022µs my ($class, $exports, $is_reexport, $meta_lookup) = @_;
101
102 return Sub::Exporter::build_exporter(
103 {
104 exports => $exports,
105 groups => { default => [':all'] },
106
# spent 906µs (122+784) within Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:137] which was called 2 times, avg 453µs/call: # 2 times (122µs+784µs) by Sub::Exporter::_do_import at line 380 of Sub/Exporter.pm, avg 453µs/call
installer => sub {
1072800ns my ($arg, $to_export) = @_;
10823µs217µs my $meta = $meta_lookup->($arg->{into});
# spent 17µs making 2 calls to Moose::Exporter::__ANON__[Moose/Exporter.pm:42], avg 8µs/call
109
11027µs1808µs goto &Sub::Exporter::default_installer unless $meta;
# spent 808µs making 1 call to Sub::Exporter::default_installer
111
112 # don't overwrite existing symbols with our magically flagged
113 # version of it if we would install the same sub that's already
114 # in the importer
115
1161200ns my @filtered_to_export;
1171100ns my %installed;
11816µs for (my $i = 0; $i < @{ $to_export }; $i += 2) {
119126µs my ($as, $cv) = @{ $to_export }[$i, $i + 1];
120
1211226µs12123µs next if !ref($as)
# spent 123µs making 12 calls to Class::MOP::Package::has_package_symbol, avg 10µs/call
122 && $meta->has_package_symbol('&' . $as)
123 && $meta->get_package_symbol('&' . $as) == $cv;
124
1251210µs push @filtered_to_export, $as, $cv;
1261210µs $installed{$as} = 1 unless ref $as;
127 }
128
12912µs1634µs Sub::Exporter::default_installer($arg, \@filtered_to_export);
# spent 634µs making 1 call to Sub::Exporter::default_installer
130
13117µs for my $name ( keys %{$is_reexport} ) {
132238µs239µs
# spent 24µs (10+14) within Moose::Exporter::BEGIN@132 which was called: # once (10µs+14µs) by Moose::BEGIN@18 at line 132
no strict 'refs';
# spent 24µs making 1 call to Moose::Exporter::BEGIN@132 # spent 14µs making 1 call to strict::unimport
13321.15ms240µs
# spent 25µs (10+15) within Moose::Exporter::BEGIN@133 which was called: # once (10µs+15µs) by Moose::BEGIN@18 at line 133
no warnings 'once';
# spent 25µs making 1 call to Moose::Exporter::BEGIN@133 # spent 15µs making 1 call to warnings::unimport
1342700ns next unless exists $installed{$name};
135223µs210µs _flag_as_reexport( \*{ join q{::}, $arg->{into}, $name } );
# spent 10µs making 2 calls to Moose::Exporter::_flag_as_reexport, avg 5µs/call
136 }
137 },
138 }
139230µs21.15ms );
# spent 1.15ms making 2 calls to Sub::Exporter::build_exporter, avg 575µs/call
140}
141
142
# spent 99µs (28+71) within Moose::Exporter::_follow_also which was called 2 times, avg 50µs/call: # 2 times (28µs+71µs) by Moose::Exporter::build_import_methods at line 46, avg 50µs/call
sub _follow_also {
14321µs my $class = shift;
1442600ns my $exporting_package = shift;
145
14625µs239µs _die_if_cycle_found_in_also_list_for_package($exporting_package);
# spent 39µs making 2 calls to Moose::Exporter::_die_if_cycle_found_in_also_list_for_package, avg 20µs/call
147
148234µs432µs return uniq( _follow_also_real($exporting_package) );
# spent 16µs making 2 calls to Moose::Exporter::_follow_also_real, avg 8µs/call # spent 15µs making 2 calls to List::MoreUtils::uniq, avg 8µs/call
149}
150
151
# spent 16µs (13+3) within Moose::Exporter::_follow_also_real which was called 2 times, avg 8µs/call: # 2 times (13µs+3µs) by Moose::Exporter::_follow_also at line 148, avg 8µs/call
sub _follow_also_real {
1522800ns my $exporting_package = shift;
15322µs23µs my @also = _also_list_for_package($exporting_package);
# spent 3µs making 2 calls to Moose::Exporter::_also_list_for_package, avg 2µs/call
154
15527µs return map { $_, _follow_also_real($_) } @also;
156}
157
158
# spent 12µs within Moose::Exporter::_also_list_for_package which was called 4 times, avg 3µs/call: # 2 times (9µs+0s) by Moose::Exporter::_die_if_cycle_found_in_also_list_for_package at line 180, avg 4µs/call # 2 times (3µs+0s) by Moose::Exporter::_follow_also_real at line 153, avg 2µs/call
sub _also_list_for_package {
15941µs my $package = shift;
160
16142µs if ( !exists $EXPORT_SPEC{$package} ) {
162 my $loaded = is_class_loaded($package);
163
164 die "Package in also ($package) does not seem to "
165 . "use Moose::Exporter"
166 . ( $loaded ? "" : " (is it loaded?)" );
167 }
168
16942µs my $also = $EXPORT_SPEC{$package}{also};
170
171419µs return unless defined $also;
172
173 return ref $also ? @$also : $also;
174}
175
176# this is no Tarjan algorithm, but for the list sizes expected,
177# brute force will probably be fine (and more maintainable)
178
# spent 39µs (25+14) within Moose::Exporter::_die_if_cycle_found_in_also_list_for_package which was called 2 times, avg 20µs/call: # 2 times (25µs+14µs) by Moose::Exporter::_follow_also at line 146, avg 20µs/call
sub _die_if_cycle_found_in_also_list_for_package {
1792600ns my $package = shift;
180214µs414µs _die_if_also_list_cycles_back_to_existing_stack(
# spent 9µs making 2 calls to Moose::Exporter::_also_list_for_package, avg 4µs/call # spent 6µs making 2 calls to Moose::Exporter::_die_if_also_list_cycles_back_to_existing_stack, avg 3µs/call
181 [ _also_list_for_package($package) ],
182 [$package],
183 );
184}
185
186
# spent 6µs within Moose::Exporter::_die_if_also_list_cycles_back_to_existing_stack which was called 2 times, avg 3µs/call: # 2 times (6µs+0s) by Moose::Exporter::_die_if_cycle_found_in_also_list_for_package at line 180, avg 3µs/call
sub _die_if_also_list_cycles_back_to_existing_stack {
18721µs my ( $also_list, $existing_stack ) = @_;
188
18928µs return unless @$also_list && @$existing_stack;
190
191 for my $also_member (@$also_list) {
192 for my $stack_member (@$existing_stack) {
193 next unless $also_member eq $stack_member;
194
195 die
196 "Circular reference in 'also' parameter to Moose::Exporter between "
197 . join(
198 ', ',
199 @$existing_stack
200 ) . " and $also_member";
201 }
202
203 _die_if_also_list_cycles_back_to_existing_stack(
204 [ _also_list_for_package($also_member) ],
205 [ $also_member, @$existing_stack ],
206 );
207 }
208}
209
210
# spent 10µs within Moose::Exporter::_parse_trait_aliases which was called 2 times, avg 5µs/call: # 2 times (10µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 281, avg 5µs/call
sub _parse_trait_aliases {
21121µs my $class = shift;
21222µs my ($package, $aliases) = @_;
213
2142400ns my @ret;
21522µs for my $alias (@$aliases) {
216 my $name;
217 if (ref($alias)) {
218 reftype($alias) eq 'ARRAY'
219 or Moose->throw_error(reftype($alias) . " references are not "
220 . "valid arguments to the 'trait_aliases' "
221 . "option");
222
223 ($alias, $name) = @$alias;
224 }
225 else {
226 ($name = $alias) =~ s/.*:://;
227 }
228 push @ret, subname "${package}::${name}" => sub () { $alias };
229 }
230
23128µs return @ret;
232}
233
234
# spent 436µs (283+153) within Moose::Exporter::_make_sub_exporter_params which was called 2 times, avg 218µs/call: # 2 times (283µs+153µs) by Moose::Exporter::build_import_methods at line 51, avg 218µs/call
sub _make_sub_exporter_params {
23521µs my $class = shift;
2362700ns my $packages = shift;
2372400ns my $export_recorder = shift;
2382400ns my $is_reexport = shift;
23922µs my $meta_lookup_override = shift;
240
2412200ns my %exports;
2422400ns my $current_meta_lookup;
243
24422µs for my $package ( @{$packages} ) {
24521µs my $args = $EXPORT_SPEC{$package}
246 or die "The $package package does not use Moose::Exporter\n";
247
24822µs $current_meta_lookup = $meta_lookup_override || $args->{meta_lookup};
2492400ns $meta_lookup_override = $current_meta_lookup;
250
251 my $meta_lookup = $current_meta_lookup
252312µs18µs
# spent 14µs (7+8) within Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:252] which was called: # once (7µs+8µs) by Moose::has at line 408
|| sub { Class::MOP::class_of(shift) };
# spent 8µs making 1 call to Class::MOP::class_of
253
25423µs for my $name ( @{ $args->{with_meta} } ) {
255811µs828µs my $sub = $class->_sub_from_package( $package, $name )
# spent 28µs making 8 calls to Moose::Exporter::_sub_from_package, avg 4µs/call
256 or next;
257
25883µs my $fq_name = $package . '::' . $name;
259
260820µs840µs $exports{$name} = $class->_make_wrapped_sub_with_meta(
# spent 40µs making 8 calls to Moose::Exporter::_make_wrapped_sub_with_meta, avg 5µs/call
261 $fq_name,
262 $sub,
263 $export_recorder,
264 $meta_lookup,
265 ) unless exists $exports{$name};
266 }
267
26823µs for my $name ( @{ $args->{with_caller} } ) {
269 my $sub = $class->_sub_from_package( $package, $name )
270 or next;
271
272 my $fq_name = $package . '::' . $name;
273
274 $exports{$name} = $class->_make_wrapped_sub(
275 $fq_name,
276 $sub,
277 $export_recorder,
278 ) unless exists $exports{$name};
279 }
280
28128µs210µs my @extra_exports = $class->_parse_trait_aliases(
# spent 10µs making 2 calls to Moose::Exporter::_parse_trait_aliases, avg 5µs/call
282 $package, $args->{trait_aliases},
283 );
28426µs for my $name ( @{ $args->{as_is} }, @extra_exports ) {
28523500ns my ( $sub, $coderef_name );
286
287234µs if ( ref $name ) {
2882400ns $sub = $name;
289
2902200ns my $coderef_pkg;
291211µs23µs ( $coderef_pkg, $coderef_name )
# spent 3µs making 2 calls to Class::MOP::get_code_info, avg 1µs/call
292 = Class::MOP::get_code_info($name);
293
29422µs if ( $coderef_pkg ne $package ) {
295 $is_reexport->{$coderef_name} = 1;
296 }
297 }
298 else {
2992127µs2172µs $sub = $class->_sub_from_package( $package, $name )
# spent 72µs making 21 calls to Moose::Exporter::_sub_from_package, avg 3µs/call
300 or next;
301
302215µs $coderef_name = $name;
303 }
304
3052321µs $export_recorder->{$sub} = 1;
306
3072349µs
# spent 32µs within Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:307] which was called 23 times, avg 1µs/call: # 23 times (32µs+0s) by Sub::Exporter::default_generator at line 419 of Sub/Exporter.pm, avg 1µs/call
$exports{$coderef_name} = sub { $sub }
3082352µs unless exists $exports{$coderef_name};
309 }
310 }
311
31228µs return \%exports;
313}
314
315
# spent 101µs within Moose::Exporter::_sub_from_package which was called 29 times, avg 3µs/call: # 21 times (72µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 299, avg 3µs/call # 8 times (28µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 255, avg 4µs/call
sub _sub_from_package {
316296µs my $sclass = shift;
317293µs my $package = shift;
318294µs my $name = shift;
319
320295µs my $sub = do {
32122.20ms238µs
# spent 24µs (10+14) within Moose::Exporter::BEGIN@321 which was called: # once (10µs+14µs) by Moose::BEGIN@18 at line 321
no strict 'refs';
# spent 24µs making 1 call to Moose::Exporter::BEGIN@321 # spent 14µs making 1 call to strict::unimport
3222932µs \&{ $package . '::' . $name };
323 };
324
3252973µs return $sub if defined &$sub;
326
327 Carp::cluck "Trying to export undefined sub ${package}::${name}";
328
329 return;
330}
331
33210sour $CALLER;
333
334sub _make_wrapped_sub {
335 my $self = shift;
336 my $fq_name = shift;
337 my $sub = shift;
338 my $export_recorder = shift;
339
340 # We need to set the package at import time, so that when
341 # package Foo imports has(), we capture "Foo" as the
342 # package. This lets other packages call Foo::has() and get
343 # the right package. This is done for backwards compatibility
344 # with existing production code, not because this is a good
345 # idea ;)
346 return sub {
347 my $caller = $CALLER;
348
349 my $wrapper = $self->_curry_wrapper( $sub, $fq_name, $caller );
350
351 my $sub = subname( $fq_name => $wrapper );
352
353 $export_recorder->{$sub} = 1;
354
355 return $sub;
356 };
357}
358
359
# spent 40µs within Moose::Exporter::_make_wrapped_sub_with_meta which was called 8 times, avg 5µs/call: # 8 times (40µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 260, avg 5µs/call
sub _make_wrapped_sub_with_meta {
36083µs my $self = shift;
36182µs my $fq_name = shift;
36281µs my $sub = shift;
3638900ns my $export_recorder = shift;
3648900ns my $meta_lookup = shift;
365
366
# spent 164µs (82+82) within Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:379] which was called 8 times, avg 21µs/call: # 8 times (82µs+82µs) by Sub::Exporter::default_generator at line 419 of Sub/Exporter.pm, avg 21µs/call
return sub {
36782µs my $caller = $CALLER;
368
369814µs863µs my $wrapper = $self->_late_curry_wrapper(
# spent 63µs making 8 calls to Moose::Exporter::_late_curry_wrapper, avg 8µs/call
370 $sub, $fq_name,
371 $meta_lookup => $caller
372 );
373
374838µs819µs my $sub = subname( $fq_name => $wrapper );
# spent 19µs making 8 calls to Sub::Name::subname, avg 2µs/call
375
376810µs $export_recorder->{$sub} = 1;
377
378821µs return $sub;
379840µs };
380}
381
382sub _curry_wrapper {
383 my $class = shift;
384 my $sub = shift;
385 my $fq_name = shift;
386 my @extra = @_;
387
388 my $wrapper = sub { $sub->( @extra, @_ ) };
389 if ( my $proto = prototype $sub ) {
390
391 # XXX - Perl's prototype sucks. Use & to make set_prototype
392 # ignore the fact that we're passing "private variables"
393 &Scalar::Util::set_prototype( $wrapper, $proto );
394 }
395 return $wrapper;
396}
397
398
# spent 63µs within Moose::Exporter::_late_curry_wrapper which was called 8 times, avg 8µs/call: # 8 times (63µs+0s) by Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:379] at line 369, avg 8µs/call
sub _late_curry_wrapper {
39982µs my $class = shift;
40082µs my $sub = shift;
40181µs my $fq_name = shift;
40281µs my $extra = shift;
40385µs my @ex_args = @_;
404
405 my $wrapper = sub {
406
407 # resolve curried arguments at runtime via this closure
40813µs114µs my @curry = ( $extra->(@ex_args) );
# spent 14µs making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:252]
40915µs18.96ms return $sub->( @curry, @_ );
# spent 8.96ms making 1 call to Moose::has
410833µs };
411
41282µs if ( my $proto = prototype $sub ) {
413
414 # XXX - Perl's prototype sucks. Use & to make set_prototype
415 # ignore the fact that we're passing "private variables"
416 &Scalar::Util::set_prototype( $wrapper, $proto );
417 }
418827µs return $wrapper;
419}
420
421
# spent 20µs within Moose::Exporter::_make_import_sub which was called 2 times, avg 10µs/call: # 2 times (20µs+0s) by Moose::Exporter::build_import_methods at line 65, avg 10µs/call
sub _make_import_sub {
4222400ns shift;
4232600ns my $exporting_package = shift;
4242700ns my $exporter = shift;
4252400ns my $exports_from = shift;
4262500ns my $is_reexport = shift;
4272600ns my $meta_lookup = shift;
428
429
# spent 7.50ms (122µs+7.38) within Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:519] which was called 2 times, avg 3.75ms/call: # once (60µs+5.71ms) by Foo::Moose::BEGIN@91 at line 91 of fastest.pl # once (62µs+1.67ms) by Moose::BEGIN@43 at line 43 of Moose.pm
return sub {
430
431 # I think we could use Sub::Exporter's collector feature
432 # to do this, but that would be rather gross, since that
433 # feature isn't really designed to return a value to the
434 # caller of the exporter sub.
435 #
436 # Also, this makes sure we preserve backwards compat for
437 # _get_caller, so it always sees the arguments in the
438 # expected order.
4392400ns my $traits;
44027µs254µs ( $traits, @_ ) = _strip_traits(@_);
# spent 54µs making 2 calls to Moose::Exporter::_strip_traits, avg 27µs/call
441
4422500ns my $metaclass;
44327µs223µs ( $metaclass, @_ ) = _strip_metaclass(@_);
# spent 23µs making 2 calls to Moose::Exporter::_strip_metaclass, avg 12µs/call
44421µs $metaclass
445 = Moose::Util::resolve_metaclass_alias( 'Class' => $metaclass )
446 if defined $metaclass && length $metaclass;
447
4482300ns my $meta_name;
44927µs222µs ( $meta_name, @_ ) = _strip_meta_name(@_);
# spent 22µs making 2 calls to Moose::Exporter::_strip_meta_name, avg 11µs/call
450
451 # Normally we could look at $_[0], but in some weird cases
452 # (involving goto &Moose::import), $_[0] ends as something
453 # else (like Squirrel).
45421µs my $class = $exporting_package;
455
45625µs28µs $CALLER = _get_caller(@_);
# spent 8µs making 2 calls to Moose::Exporter::_get_caller, avg 4µs/call
457
458 # this works because both pragmas set $^H (see perldoc
459 # perlvar) which affects the current compilation -
460 # i.e. the file who use'd us - which is why we don't need
461 # to do anything special to make it affect that file
462 # rather than this one (which is already compiled)
463
46424µs229µs strict->import;
# spent 29µs making 2 calls to strict::import, avg 15µs/call
46524µs219µs warnings->import;
# spent 19µs making 2 calls to warnings::import, avg 9µs/call
466
4672200ns my $did_init_meta;
468423µs25µs for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) {
# spent 5µs making 2 calls to UNIVERSAL::can, avg 2µs/call
469
470 # init_meta can apply a role, which when loaded uses
471 # Moose::Exporter, which in turn sets $CALLER, so we need
472 # to protect against that.
4731400ns local $CALLER = $CALLER;
47412µs13.98ms $c->init_meta(
# spent 3.98ms making 1 call to Moose::init_meta
475 for_class => $CALLER,
476 metaclass => $metaclass,
477 meta_name => $meta_name,
478 );
47911µs $did_init_meta = 1;
480 }
481
482 {
483 # The metaroles will use Moose::Role, which in turn uses
484 # Moose::Exporter, which in turn sets $CALLER, so we need
485 # to protect against that.
48642µs local $CALLER = $CALLER;
48726µs298µs _apply_metaroles(
# spent 98µs making 2 calls to Moose::Exporter::_apply_metaroles, avg 49µs/call
488 $CALLER,
489 [$class, @$exports_from],
490 $meta_lookup
491 );
492 }
493
49421µs if ( $did_init_meta && @{$traits} ) {
495
496 # The traits will use Moose::Role, which in turn uses
497 # Moose::Exporter, which in turn sets $CALLER, so we need
498 # to protect against that.
499 local $CALLER = $CALLER;
500 _apply_meta_traits( $CALLER, $traits, $meta_lookup );
501 }
502 elsif ( @{$traits} ) {
503 require Moose;
504 Moose->throw_error(
505 "Cannot provide traits when $class does not have an init_meta() method"
506 );
507 }
508
50922µs my ( undef, @args ) = @_;
51021µs my $extra = shift @args if ref $args[0] eq 'HASH';
511
51221µs $extra ||= {};
51321µs if ( !$extra->{into} ) {
51422µs $extra->{into_level} ||= 0;
5152900ns $extra->{into_level}++;
516 }
517
518215µs23.15ms $class->$exporter( $extra, @args );
# spent 3.15ms making 2 calls to Sub::Exporter::__ANON__[Sub/Exporter.pm:337], avg 1.57ms/call
519218µs };
520}
521
522
# spent 54µs (32+22) within Moose::Exporter::_strip_traits which was called 2 times, avg 27µs/call: # 2 times (32µs+22µs) by Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:519] at line 440, avg 27µs/call
sub _strip_traits {
523446µs222µs my $idx = first_index { ( $_ || '' ) eq '-traits' } @_;
# spent 22µs making 2 calls to List::MoreUtils::firstidx, avg 11µs/call
524
525211µs return ( [], @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
526
527 my $traits = $_[ $idx + 1 ];
528
529 splice @_, $idx, 2;
530
531 $traits = [$traits] unless ref $traits;
532
533 return ( $traits, @_ );
534}
535
536
# spent 23µs (19+4) within Moose::Exporter::_strip_metaclass which was called 2 times, avg 12µs/call: # 2 times (19µs+4µs) by Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:519] at line 443, avg 12µs/call
sub _strip_metaclass {
537416µs24µs my $idx = first_index { ( $_ || '' ) eq '-metaclass' } @_;
# spent 4µs making 2 calls to List::MoreUtils::firstidx, avg 2µs/call
538
53928µs return ( undef, @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
540
541 my $metaclass = $_[ $idx + 1 ];
542
543 splice @_, $idx, 2;
544
545 return ( $metaclass, @_ );
546}
547
548
# spent 22µs (18+4) within Moose::Exporter::_strip_meta_name which was called 2 times, avg 11µs/call: # 2 times (18µs+4µs) by Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:519] at line 449, avg 11µs/call
sub _strip_meta_name {
549415µs24µs my $idx = first_index { ( $_ || '' ) eq '-meta_name' } @_;
# spent 4µs making 2 calls to List::MoreUtils::firstidx, avg 2µs/call
550
55128µs return ( 'meta', @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
552
553 my $meta_name = $_[ $idx + 1 ];
554
555 splice @_, $idx, 2;
556
557 return ( $meta_name, @_ );
558}
559
560
# spent 98µs (28+70) within Moose::Exporter::_apply_metaroles which was called 2 times, avg 49µs/call: # 2 times (28µs+70µs) by Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:519] at line 487, avg 49µs/call
sub _apply_metaroles {
56121µs my ($class, $exports_from, $meta_lookup) = @_;
562
56324µs246µs my $metaroles = _collect_metaroles($exports_from);
# spent 46µs making 2 calls to Moose::Exporter::_collect_metaroles, avg 23µs/call
56421µs my $base_class_roles = delete $metaroles->{base_class_roles};
565
56625µs222µs my $meta = $meta_lookup->($class);
# spent 22µs making 2 calls to Moose::Exporter::__ANON__[Moose/Exporter.pm:42], avg 11µs/call
567 # for instance, Moose.pm uses Moose::Util::TypeConstraints
56825µs return unless $meta;
569
5701700ns Moose::Util::MetaRole::apply_metaroles(
571 for => $meta,
572 %$metaroles,
573 ) if keys %$metaroles;
574
57519µs11µs Moose::Util::MetaRole::apply_base_class_roles(
# spent 1µs making 1 call to UNIVERSAL::isa
576 for => $meta,
577 roles => $base_class_roles,
578 ) if $meta->isa('Class::MOP::Class')
579 && $base_class_roles && @$base_class_roles;
580}
581
582
# spent 46µs within Moose::Exporter::_collect_metaroles which was called 2 times, avg 23µs/call: # 2 times (46µs+0s) by Moose::Exporter::_apply_metaroles at line 563, avg 23µs/call
sub _collect_metaroles {
5832600ns my ($exports_from) = @_;
584
585212µs my @old_style_role_types = map { "${_}_roles" } qw(
586 metaclass
587 attribute_metaclass
588 method_metaclass
589 wrapped_method_metaclass
590 instance_metaclass
591 constructor_class
592 destructor_class
593 error_class
594 );
595
5962300ns my %class_metaroles;
5972200ns my %role_metaroles;
5982400ns my @base_class_roles;
5992200ns my %old_style_roles;
600
60122µs for my $exporter (@$exports_from) {
60222µs my $data = $EXPORT_SPEC{$exporter};
603
60422µs if (exists $data->{class_metaroles}) {
605 for my $type (keys %{ $data->{class_metaroles} }) {
606 push @{ $class_metaroles{$type} ||= [] },
607 @{ $data->{class_metaroles}{$type} };
608 }
609 }
610
61121µs if (exists $data->{role_metaroles}) {
612 for my $type (keys %{ $data->{role_metaroles} }) {
613 push @{ $role_metaroles{$type} ||= [] },
614 @{ $data->{role_metaroles}{$type} };
615 }
616 }
617
61821µs if (exists $data->{base_class_roles}) {
619 push @base_class_roles, @{ $data->{base_class_roles} };
620 }
621
62223µs for my $type (@old_style_role_types) {
623164µs if (exists $data->{$type}) {
624 push @{ $old_style_roles{$type} ||= [] },
625 @{ $data->{$type} };
626 }
627 }
628 }
629
630 return {
631215µs (keys(%class_metaroles)
632 ? (class_metaroles => \%class_metaroles)
633 : ()),
634 (keys(%role_metaroles)
635 ? (role_metaroles => \%role_metaroles)
636 : ()),
637 (@base_class_roles
638 ? (base_class_roles => \@base_class_roles)
639 : ()),
640 %old_style_roles,
641 };
642}
643
644sub _apply_meta_traits {
645 my ( $class, $traits, $meta_lookup ) = @_;
646
647 return unless @{$traits};
648
649 my $meta = $meta_lookup->($class);
650
651 my $type = $meta->isa('Moose::Meta::Role') ? 'Role'
652 : $meta->isa('Class::MOP::Class') ? 'Class'
653 : Moose->throw_error('Cannot determine metaclass type for '
654 . 'trait application. Meta isa '
655 . ref $meta);
656
657 my @resolved_traits = map {
658 ref $_
659 ? $_
660 : Moose::Util::resolve_metatrait_alias( $type => $_ )
661 } @$traits;
662
663 return unless @resolved_traits;
664
665 my %args = ( for => $class );
666
667 if ( $meta->isa('Moose::Meta::Role') ) {
668 $args{role_metaroles} = { role => \@resolved_traits };
669 }
670 else {
671 $args{class_metaroles} = { class => \@resolved_traits };
672 }
673
674 Moose::Util::MetaRole::apply_metaroles(%args);
675}
676
677
# spent 8µs within Moose::Exporter::_get_caller which was called 2 times, avg 4µs/call: # 2 times (8µs+0s) by Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:519] at line 456, avg 4µs/call
sub _get_caller {
678
679 # 1 extra level because it's called by import so there's a layer
680 # of indirection
6812800ns my $offset = 1;
682
683 return
68429µs ( ref $_[1] && defined $_[1]->{into} ) ? $_[1]->{into}
685 : ( ref $_[1] && defined $_[1]->{into_level} )
686 ? caller( $offset + $_[1]->{into_level} )
687 : caller($offset);
688}
689
690
# spent 12µs within Moose::Exporter::_make_unimport_sub which was called 2 times, avg 6µs/call: # 2 times (12µs+0s) by Moose::Exporter::build_import_methods at line 73, avg 6µs/call
sub _make_unimport_sub {
6912200ns shift;
6922700ns my $exporting_package = shift;
6932600ns my $exports = shift;
6942400ns my $export_recorder = shift;
6952400ns my $is_reexport = shift;
6962600ns my $meta_lookup = shift;
697
698 return sub {
699 my $caller = scalar caller();
700 Moose::Exporter->_remove_keywords(
701 $caller,
702 [ keys %{$exports} ],
703 $export_recorder,
704 $is_reexport,
705 );
706211µs };
707}
708
709sub _remove_keywords {
710 shift;
711 my $package = shift;
712 my $keywords = shift;
713 my $recorded_exports = shift;
714 my $is_reexport = shift;
715
716296µs238µs
# spent 24µs (9+14) within Moose::Exporter::BEGIN@716 which was called: # once (9µs+14µs) by Moose::BEGIN@18 at line 716
no strict 'refs';
# spent 24µs making 1 call to Moose::Exporter::BEGIN@716 # spent 14µs making 1 call to strict::unimport
717
718 foreach my $name ( @{$keywords} ) {
719 if ( defined &{ $package . '::' . $name } ) {
720 my $sub = \&{ $package . '::' . $name };
721
722 # make sure it is from us
723 next unless $recorded_exports->{$sub};
724
725 if ( $is_reexport->{$name} ) {
7262386µs234µs
# spent 22µs (9+13) within Moose::Exporter::BEGIN@726 which was called: # once (9µs+13µs) by Moose::BEGIN@18 at line 726
no strict 'refs';
# spent 22µs making 1 call to Moose::Exporter::BEGIN@726 # spent 13µs making 1 call to strict::unimport
727 next
728 unless _export_is_flagged(
729 \*{ join q{::} => $package, $name } );
730 }
731
732 # and if it is from us, then undef the slot
733 delete ${ $package . '::' }{$name};
734 }
735 }
736}
737
738# maintain this for now for backcompat
739# make sure to return a sub to install in the same circumstances as previously
740# but this functionality now happens at the end of ->import
741
# spent 37µs within Moose::Exporter::_make_init_meta which was called 2 times, avg 19µs/call: # 2 times (37µs+0s) by Moose::Exporter::build_import_methods at line 81, avg 19µs/call
sub _make_init_meta {
7422200ns shift;
7432700ns my $class = shift;
7442600ns my $args = shift;
7452600ns my $meta_lookup = shift;
746
7472300ns my %old_style_roles;
748213µs for my $role (
749 map {"${_}_roles"}
750 qw(
751 metaclass
752 attribute_metaclass
753 method_metaclass
754 wrapped_method_metaclass
755 instance_metaclass
756 constructor_class
757 destructor_class
758 error_class
759 )
760 ) {
761165µs $old_style_roles{$role} = $args->{$role}
762 if exists $args->{$role};
763 }
764
7652400ns my %base_class_roles;
76621µs %base_class_roles = ( roles => $args->{base_class_roles} )
767 if exists $args->{base_class_roles};
768
769 my %new_style_roles = map { $_ => $args->{$_} }
77024µs grep { exists $args->{$_} } qw( class_metaroles role_metaroles );
771
77229µs return unless %new_style_roles || %old_style_roles || %base_class_roles;
773
774 return sub {
775 shift;
776 my %opts = @_;
777 $meta_lookup->($opts{for_class});
778 };
779}
780
781
# spent 63µs (19+44) within Moose::Exporter::import which was called 2 times, avg 31µs/call: # once (11µs+26µs) by Moose::BEGIN@18 at line 18 of Moose.pm # once (7µs+19µs) by Moose::Util::TypeConstraints::BEGIN@13 at line 13 of Moose/Util/TypeConstraints.pm
sub import {
78222µs230µs strict->import;
# spent 30µs making 2 calls to strict::import, avg 15µs/call
783213µs215µs warnings->import;
# spent 15µs making 2 calls to warnings::import, avg 7µs/call
784}
785
78614µs1;
787
788# ABSTRACT: make an import() and unimport() just like Moose.pm
789
790__END__
 
# spent 10µs within Moose::Exporter::_flag_as_reexport which was called 2 times, avg 5µs/call: # 2 times (10µs+0s) by Moose::Exporter::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Exporter.pm:137] at line 135, avg 5µs/call
sub Moose::Exporter::_flag_as_reexport; # xsub