← Index
NYTProf Performance Profile   « block view • line view • sub view »
For xt/tapper-mcp-scheduler-with-db-longrun.t
  Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:42 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm
StatementsExecuted 3856 statements in 10.1ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1113.90ms73.8msMoose::Exporter::::BEGIN@13Moose::Exporter::BEGIN@13
13111.02ms7.47msMoose::Exporter::::__ANON__[:137]Moose::Exporter::__ANON__[:137]
131313876µs49.1msMoose::Exporter::::__ANON__[:492]Moose::Exporter::__ANON__[:492]
111846µs1.09msMoose::Exporter::::BEGIN@15Moose::Exporter::BEGIN@15
8811736µs1.49msMoose::Exporter::::__ANON__[:352]Moose::Exporter::__ANON__[:352]
8811535µs535µsMoose::Exporter::::_late_curry_wrapperMoose::Exporter::_late_curry_wrapper
311366µs603µsMoose::Exporter::::_make_sub_exporter_paramsMoose::Exporter::_make_sub_exporter_params
1311326µs326µsMoose::Exporter::::_collect_metarolesMoose::Exporter::_collect_metaroles
111274µs282µsMoose::Exporter::::_remove_keywordsMoose::Exporter::_remove_keywords
311218µs2.90msMoose::Exporter::::build_import_methodsMoose::Exporter::build_import_methods
1311193µs669µsMoose::Exporter::::_apply_metarolesMoose::Exporter::_apply_metaroles
1311144µs227µsMoose::Exporter::::_strip_traitsMoose::Exporter::_strip_traits
4121142µs142µsMoose::Exporter::::_sub_from_packageMoose::Exporter::_sub_from_package
9011133µs133µsMoose::Exporter::::__ANON__[:280]Moose::Exporter::__ANON__[:280]
2621108µs230µsMoose::Exporter::::__ANON__[:42]Moose::Exporter::__ANON__[:42]
1311101µs128µsMoose::Exporter::::_strip_metaclassMoose::Exporter::_strip_metaclass
1511100µs228µsMoose::Exporter::::__ANON__[:225]Moose::Exporter::__ANON__[:225]
131192µs113µsMoose::Exporter::::_strip_meta_nameMoose::Exporter::_strip_meta_name
33390µs2.99msMoose::Exporter::::setup_import_methodsMoose::Exporter::setup_import_methods
161170µs70µsMoose::Exporter::::_make_wrapped_sub_with_metaMoose::Exporter::_make_wrapped_sub_with_meta
131153µs53µsMoose::Exporter::::_get_callerMoose::Exporter::_get_caller
31150µs50µsMoose::Exporter::::_make_init_metaMoose::Exporter::_make_init_meta
31143µs71µsMoose::Exporter::::_follow_alsoMoose::Exporter::_follow_also
31143µs1.48msMoose::Exporter::::_make_exporterMoose::Exporter::_make_exporter
11136µs318µsMoose::Exporter::::__ANON__[:678]Moose::Exporter::__ANON__[:678]
221131µs31µsMoose::Exporter::::_flag_as_reexportMoose::Exporter::_flag_as_reexport (xsub)
31129µs29µsMoose::Exporter::::_make_import_subMoose::Exporter::_make_import_sub
33329µs74µsMoose::Exporter::::importMoose::Exporter::import
31123µs23µsMoose::Exporter::::_make_unimport_subMoose::Exporter::_make_unimport_sub
31118µs18µsMoose::Exporter::::_parse_trait_aliasesMoose::Exporter::_parse_trait_aliases
11117µs207µsMoose::Exporter::::BEGIN@17Moose::Exporter::BEGIN@17
31114µs14µsMoose::Exporter::::_follow_also_realMoose::Exporter::_follow_also_real
11114µs31µsMoose::Exporter::::BEGIN@133Moose::Exporter::BEGIN@133
11113µs37µsMoose::Exporter::::BEGIN@688Moose::Exporter::BEGIN@688
11111µs58µsMoose::Exporter::::BEGIN@14Moose::Exporter::BEGIN@14
1119µs9µsMoose::Exporter::::BEGIN@2Moose::Exporter::BEGIN@2
1118µs23µsMoose::Exporter::::BEGIN@132Moose::Exporter::BEGIN@132
1118µs21µsMoose::Exporter::::BEGIN@10Moose::Exporter::BEGIN@10
2117µs7µsMoose::Exporter::::_export_is_flaggedMoose::Exporter::_export_is_flagged (xsub)
1117µs32µsMoose::Exporter::::BEGIN@12Moose::Exporter::BEGIN@12
1117µs17µsMoose::Exporter::::BEGIN@294Moose::Exporter::BEGIN@294
1117µs29µsMoose::Exporter::::BEGIN@16Moose::Exporter::BEGIN@16
1117µs11µsMoose::Exporter::::BEGIN@9Moose::Exporter::BEGIN@9
1117µs27µsMoose::Exporter::::BEGIN@18Moose::Exporter::BEGIN@18
1116µs13µsMoose::Exporter::::BEGIN@698Moose::Exporter::BEGIN@698
0000s0sMoose::Exporter::::__ANON__[:201]Moose::Exporter::__ANON__[:201]
0000s0sMoose::Exporter::::__ANON__[:329]Moose::Exporter::__ANON__[:329]
0000s0sMoose::Exporter::::__ANON__[:361]Moose::Exporter::__ANON__[:361]
0000s0sMoose::Exporter::::__ANON__[:383]Moose::Exporter::__ANON__[:383]
0000s0sMoose::Exporter::::__ANON__[:496]Moose::Exporter::__ANON__[:496]
0000s0sMoose::Exporter::::__ANON__[:510]Moose::Exporter::__ANON__[:510]
0000s0sMoose::Exporter::::__ANON__[:522]Moose::Exporter::__ANON__[:522]
0000s0sMoose::Exporter::::__ANON__[:750]Moose::Exporter::__ANON__[:750]
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
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 9µs within Moose::Exporter::BEGIN@2 which was called: # once (9µs+0s) by Moose::BEGIN@19 at line 4
BEGIN {
314µs $Moose::Exporter::AUTHORITY = 'cpan:STEVAN';
4122µs19µs}
# spent 9µs making 1 call to Moose::Exporter::BEGIN@2
5{
621µs $Moose::Exporter::VERSION = '2.0602';
7}
8
9317µs216µs
# spent 11µs (7+4) within Moose::Exporter::BEGIN@9 which was called: # once (7µs+4µs) by Moose::BEGIN@19 at line 9
use strict;
# spent 11µs making 1 call to Moose::Exporter::BEGIN@9 # spent 4µs making 1 call to strict::import
10325µs235µs
# spent 21µs (8+13) within Moose::Exporter::BEGIN@10 which was called: # once (8µs+13µs) by Moose::BEGIN@19 at line 10
use warnings;
# spent 21µs making 1 call to Moose::Exporter::BEGIN@10 # spent 14µs making 1 call to warnings::import
11
12317µs256µs
# spent 32µs (7+24) within Moose::Exporter::BEGIN@12 which was called: # once (7µs+24µs) by Moose::BEGIN@19 at line 12
use Class::Load qw(is_class_loaded);
# spent 32µs making 1 call to Moose::Exporter::BEGIN@12 # spent 24µs making 1 call to Exporter::import
133126µs173.8ms
# spent 73.8ms (3.90+69.9) within Moose::Exporter::BEGIN@13 which was called: # once (3.90ms+69.9ms) by Moose::BEGIN@19 at line 13
use Class::MOP;
# spent 73.8ms making 1 call to Moose::Exporter::BEGIN@13
14323µs2105µs
# spent 58µs (11+47) within Moose::Exporter::BEGIN@14 which was called: # once (11µs+47µs) by Moose::BEGIN@19 at line 14
use List::MoreUtils qw( first_index uniq );
# spent 58µs making 1 call to Moose::Exporter::BEGIN@14 # spent 47µs making 1 call to Exporter::import
153193µs11.09ms
# spent 1.09ms (846µs+242µs) within Moose::Exporter::BEGIN@15 which was called: # once (846µs+242µs) by Moose::BEGIN@19 at line 15
use Moose::Util::MetaRole;
# spent 1.09ms making 1 call to Moose::Exporter::BEGIN@15
16321µs250µs
# spent 29µs (7+22) within Moose::Exporter::BEGIN@16 which was called: # once (7µs+22µs) by Moose::BEGIN@19 at line 16
use Scalar::Util qw(reftype);
# spent 29µs making 1 call to Moose::Exporter::BEGIN@16 # spent 22µs making 1 call to Exporter::import
17358µs3398µs
# spent 207µs (17+191) within Moose::Exporter::BEGIN@17 which was called: # once (17µs+191µs) by Moose::BEGIN@19 at line 17
use Sub::Exporter 0.980;
# spent 207µs making 1 call to Moose::Exporter::BEGIN@17 # spent 165µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] # spent 26µs making 1 call to UNIVERSAL::VERSION
183345µs247µs
# spent 27µs (7+20) within Moose::Exporter::BEGIN@18 which was called: # once (7µs+20µs) by Moose::BEGIN@19 at line 18
use Sub::Name qw(subname);
# spent 27µs making 1 call to Moose::Exporter::BEGIN@18 # spent 20µs making 1 call to Exporter::import
19
201200nsmy %EXPORT_SPEC;
21
22
# spent 2.99ms (90µs+2.90) within Moose::Exporter::setup_import_methods which was called 3 times, avg 997µs/call: # once (56µs+1.07ms) by Moose::Meta::Attribute::BEGIN@24 at line 44 of Moose/Util/TypeConstraints.pm # once (19µs+924µs) by Tapper::MCP::Scheduler::Controller::BEGIN@6 at line 131 of Moose.pm # once (14µs+908µs) by Any::Moose::_install_module at line 91 of Moose/Role.pm
sub setup_import_methods {
23992µs my ( $class, %args ) = @_;
24
25 $args{exporting_package} ||= caller();
26
2732.90ms $class->build_import_methods(
# spent 2.90ms making 3 calls to Moose::Exporter::build_import_methods, avg 967µs/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.90ms (218µs+2.68) within Moose::Exporter::build_import_methods which was called 3 times, avg 967µs/call: # 3 times (218µs+2.68ms) by Moose::Exporter::setup_import_methods at line 27, avg 967µs/call
sub build_import_methods {
3848143µs my ( $class, %args ) = @_;
39
40 my $exporting_package = $args{exporting_package} ||= caller();
41
4226103µs26122µs
# spent 230µs (108+122) within Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:42] which was called 26 times, avg 9µs/call: # 13 times (66µs+69µs) by Moose::Exporter::_apply_metaroles at line 539, avg 10µs/call # 13 times (42µs+53µs) by Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:137] at line 108, avg 7µs/call
my $meta_lookup = $args{meta_lookup} || sub { Class::MOP::class_of(shift) };
# spent 122µs making 26 calls to Class::MOP::class_of, avg 5µs/call
43
44 $EXPORT_SPEC{$exporting_package} = \%args;
45
46371µs my @exports_from = $class->_follow_also($exporting_package);
# spent 71µs making 3 calls to Moose::Exporter::_follow_also, avg 24µs/call
47
48 my $export_recorder = {};
49 my $is_reexport = {};
50
513603µs my $exports = $class->_make_sub_exporter_params(
# spent 603µs making 3 calls to Moose::Exporter::_make_sub_exporter_params, avg 201µ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
5831.48ms my $exporter = $class->_make_exporter(
# spent 1.48ms making 3 calls to Moose::Exporter::_make_exporter, avg 493µs/call
59 $exports,
60 $is_reexport,
61 $meta_lookup,
62 );
63
64 my %methods;
65329µs $methods{import} = $class->_make_import_sub(
# spent 29µs making 3 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
73323µs $methods{unimport} = $class->_make_unimport_sub(
# spent 23µs making 3 calls to Moose::Exporter::_make_unimport_sub, avg 8µs/call
74 $exporting_package,
75 $exports,
76 $export_recorder,
77 $is_reexport,
78 $meta_lookup,
79 );
80
81350µs $methods{init_meta} = $class->_make_init_meta(
# spent 50µs making 3 calls to Moose::Exporter::_make_init_meta, avg 17µs/call
82 $exporting_package,
83 \%args,
84 $meta_lookup,
85 );
86
873142µs my $package = Class::MOP::Package->initialize($exporting_package);
# spent 142µs making 3 calls to Class::MOP::Package::initialize, avg 47µs/call
88 for my $to_install ( @{ $args{install} || [] } ) {
892442µs my $symbol = '&' . $to_install;
90 next
916188µs unless $methods{$to_install}
# spent 188µs making 6 calls to Class::MOP::Package::has_package_symbol, avg 31µs/call
92 && !$package->has_package_symbol($symbol);
93698µs $package->add_package_symbol( $symbol, $methods{$to_install} );
# spent 98µs making 6 calls to Class::MOP::Package::add_package_symbol, avg 16µs/call
94 }
95
96 return ( $methods{import}, $methods{unimport}, $methods{init_meta} );
97}
98
99
# spent 1.48ms (43µs+1.44) within Moose::Exporter::_make_exporter which was called 3 times, avg 493µs/call: # 3 times (43µs+1.44ms) by Moose::Exporter::build_import_methods at line 58, avg 493µs/call
sub _make_exporter {
100646µ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 7.47ms (1.02+6.45) within Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:137] which was called 13 times, avg 575µs/call: # 13 times (1.02ms+6.45ms) by Sub::Exporter::_do_import at line 799 of Sub/Exporter.pm, avg 575µs/call
installer => sub {
107105251µs my ($arg, $to_export) = @_;
1081395µs my $meta = $meta_lookup->($arg->{into});
# spent 95µs making 13 calls to Moose::Exporter::__ANON__[Moose/Exporter.pm:42], avg 7µs/call
109
11021.32ms goto &Sub::Exporter::default_installer unless $meta;
# spent 1.32ms making 2 calls to Sub::Exporter::default_installer, avg 662µs/call
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
116 my @filtered_to_export;
117 my %installed;
118560500µs for (my $i = 0; $i < @{ $to_export }; $i += 2) {
119 my ($as, $cv) = @{ $to_export }[$i, $i + 1];
120
1211401.15ms next if !ref($as)
# spent 1.15ms making 140 calls to Class::MOP::Package::has_package_symbol, avg 8µs/call
122 && $meta->has_package_symbol('&' . $as)
123 && $meta->get_package_symbol('&' . $as) == $cv;
124
125 push @filtered_to_export, $as, $cv;
126 $installed{$as} = 1 unless ref $as;
127 }
128
129115.18ms Sub::Exporter::default_installer($arg, \@filtered_to_export);
# spent 5.18ms making 11 calls to Sub::Exporter::default_installer, avg 471µs/call
130
131 for my $name ( keys %{$is_reexport} ) {
132319µs238µs
# spent 23µs (8+15) within Moose::Exporter::BEGIN@132 which was called: # once (8µs+15µs) by Moose::BEGIN@19 at line 132
no strict 'refs';
# spent 23µs making 1 call to Moose::Exporter::BEGIN@132 # spent 15µs making 1 call to strict::unimport
1333680µs248µs
# spent 31µs (14+17) within Moose::Exporter::BEGIN@133 which was called: # once (14µs+17µs) by Moose::BEGIN@19 at line 133
no warnings 'once';
# spent 31µs making 1 call to Moose::Exporter::BEGIN@133 # spent 17µs making 1 call to warnings::unimport
13444142µs next unless exists $installed{$name};
1352231µs _flag_as_reexport( \*{ join q{::}, $arg->{into}, $name } );
# spent 31µs making 22 calls to Moose::Exporter::_flag_as_reexport, avg 1µs/call
136 }
137 },
138 }
13931.44ms );
# spent 1.44ms making 3 calls to Sub::Exporter::build_exporter, avg 479µs/call
140}
141
142{
14321µs my $seen = {};
144
145
# spent 71µs (43+28) within Moose::Exporter::_follow_also which was called 3 times, avg 24µs/call: # 3 times (43µs+28µs) by Moose::Exporter::build_import_methods at line 46, avg 24µs/call
sub _follow_also {
1461251µs my $class = shift;
147 my $exporting_package = shift;
148
149 local %$seen = ( $exporting_package => 1 );
150
151628µs return uniq( _follow_also_real($exporting_package) );
# spent 14µs making 3 calls to Moose::Exporter::_follow_also_real, avg 5µs/call # spent 13µs making 3 calls to List::MoreUtils::uniq, avg 4µs/call
152 }
153
154
# spent 14µs within Moose::Exporter::_follow_also_real which was called 3 times, avg 5µs/call: # 3 times (14µs+0s) by Moose::Exporter::_follow_also at line 151, avg 5µs/call
sub _follow_also_real {
1551223µs my $exporting_package = shift;
156
157 if ( !exists $EXPORT_SPEC{$exporting_package} ) {
158 my $loaded = is_class_loaded($exporting_package);
159
160 die "Package in also ($exporting_package) does not seem to "
161 . "use Moose::Exporter"
162 . ( $loaded ? "" : " (is it loaded?)" );
163 }
164
165 my $also = $EXPORT_SPEC{$exporting_package}{also};
166
167 return unless defined $also;
168
169 my @also = ref $also ? @{$also} : $also;
170
171 for my $package (@also) {
172 die
173 "Circular reference in 'also' parameter to Moose::Exporter between $exporting_package and $package"
174 if $seen->{$package};
175
176 $seen->{$package} = 1;
177 }
178
179 return map { $_, _follow_also_real($_) } @also;
180 }
181}
182
183
# spent 18µs within Moose::Exporter::_parse_trait_aliases which was called 3 times, avg 6µs/call: # 3 times (18µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 254, avg 6µs/call
sub _parse_trait_aliases {
1841522µs my $class = shift;
185 my ($package, $aliases) = @_;
186
187 my @ret;
188 for my $alias (@$aliases) {
189 my $name;
190 if (ref($alias)) {
191 reftype($alias) eq 'ARRAY'
192 or Moose->throw_error(reftype($alias) . " references are not "
193 . "valid arguments to the 'trait_aliases' "
194 . "option");
195
196 ($alias, $name) = @$alias;
197 }
198 else {
199 ($name = $alias) =~ s/.*:://;
200 }
201 push @ret, subname "${package}::${name}" => sub () { $alias };
202 }
203
204 return @ret;
205}
206
207
# spent 603µs (366+237) within Moose::Exporter::_make_sub_exporter_params which was called 3 times, avg 201µs/call: # 3 times (366µs+237µs) by Moose::Exporter::build_import_methods at line 51, avg 201µs/call
sub _make_sub_exporter_params {
2082727µs my $class = shift;
209 my $packages = shift;
210 my $export_recorder = shift;
211 my $is_reexport = shift;
212 my $meta_lookup_override = shift;
213
214 my %exports;
215 my $current_meta_lookup;
216
217 for my $package ( @{$packages} ) {
2182441µs my $args = $EXPORT_SPEC{$package}
219 or die "The $package package does not use Moose::Exporter\n";
220
221 $current_meta_lookup = $meta_lookup_override || $args->{meta_lookup};
222 $meta_lookup_override = $current_meta_lookup;
223
224 my $meta_lookup = $current_meta_lookup
2251594µs15128µs
# spent 228µs (100+128) within Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:225] which was called 15 times, avg 15µs/call: # 15 times (100µs+128µs) by Moose::Role::has or Moose::Role::requires or Moose::extends or Moose::has or Moose::with at line 381, avg 15µs/call
|| sub { Class::MOP::class_of(shift) };
# spent 128µs making 15 calls to Class::MOP::class_of, avg 9µs/call
226
227 for my $name ( @{ $args->{with_meta} } ) {
2284868µs1654µs my $sub = $class->_sub_from_package( $package, $name )
# spent 54µs making 16 calls to Moose::Exporter::_sub_from_package, avg 3µs/call
229 or next;
230
231 my $fq_name = $package . '::' . $name;
232
2331670µs $exports{$name} = $class->_make_wrapped_sub_with_meta(
# spent 70µs making 16 calls to Moose::Exporter::_make_wrapped_sub_with_meta, avg 4µs/call
234 $fq_name,
235 $sub,
236 $export_recorder,
237 $meta_lookup,
238 ) unless exists $exports{$name};
239 }
240
241 for my $name ( @{ $args->{with_caller} } ) {
242 my $sub = $class->_sub_from_package( $package, $name )
243 or next;
244
245 my $fq_name = $package . '::' . $name;
246
247 $exports{$name} = $class->_make_wrapped_sub(
248 $fq_name,
249 $sub,
250 $export_recorder,
251 ) unless exists $exports{$name};
252 }
253
254318µs my @extra_exports = $class->_parse_trait_aliases(
# spent 18µs making 3 calls to Moose::Exporter::_parse_trait_aliases, avg 6µs/call
255 $package, $args->{trait_aliases},
256 );
257 for my $name ( @{ $args->{as_is} }, @extra_exports ) {
258116116µs my ( $sub, $coderef_name );
259
2606669µs if ( ref $name ) {
261 $sub = $name;
262
263 my $coderef_pkg;
26447µs ( $coderef_pkg, $coderef_name )
# spent 7µs making 4 calls to Class::MOP::get_code_info, avg 2µs/call
265 = Class::MOP::get_code_info($name);
266
267 if ( $coderef_pkg ne $package ) {
268 $is_reexport->{$coderef_name} = 1;
269 }
270 }
271 else {
2722588µs $sub = $class->_sub_from_package( $package, $name )
# spent 88µs making 25 calls to Moose::Exporter::_sub_from_package, avg 4µs/call
273 or next;
274
275 $coderef_name = $name;
276 }
277
278 $export_recorder->{$sub} = 1;
279
28090191µs
# spent 133µs within Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:280] which was called 90 times, avg 1µs/call: # 90 times (133µs+0s) by Sub::Exporter::default_generator at line 856 of Sub/Exporter.pm, avg 1µs/call
$exports{$coderef_name} = sub { $sub }
281 unless exists $exports{$coderef_name};
282 }
283 }
284
285 return \%exports;
286}
287
288
# spent 142µs within Moose::Exporter::_sub_from_package which was called 41 times, avg 3µs/call: # 25 times (88µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 272, avg 4µs/call # 16 times (54µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 228, avg 3µs/call
sub _sub_from_package {
289205131µs my $sclass = shift;
290 my $package = shift;
291 my $name = shift;
292
2934151µs my $sub = do {
29431.86ms227µs
# spent 17µs (7+10) within Moose::Exporter::BEGIN@294 which was called: # once (7µs+10µs) by Moose::BEGIN@19 at line 294
no strict 'refs';
# spent 17µs making 1 call to Moose::Exporter::BEGIN@294 # spent 10µs making 1 call to strict::unimport
295 \&{ $package . '::' . $name };
296 };
297
298 return $sub if defined &$sub;
299
300 Carp::cluck "Trying to export undefined sub ${package}::${name}";
301
302 return;
303}
304
3051100nsour $CALLER;
306
307sub _make_wrapped_sub {
308 my $self = shift;
309 my $fq_name = shift;
310 my $sub = shift;
311 my $export_recorder = shift;
312
313 # We need to set the package at import time, so that when
314 # package Foo imports has(), we capture "Foo" as the
315 # package. This lets other packages call Foo::has() and get
316 # the right package. This is done for backwards compatibility
317 # with existing production code, not because this is a good
318 # idea ;)
319 return sub {
320 my $caller = $CALLER;
321
322 my $wrapper = $self->_curry_wrapper( $sub, $fq_name, $caller );
323
324 my $sub = subname( $fq_name => $wrapper );
325
326 $export_recorder->{$sub} = 1;
327
328 return $sub;
329 };
330}
331
332
# spent 70µs within Moose::Exporter::_make_wrapped_sub_with_meta which was called 16 times, avg 4µs/call: # 16 times (70µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 233, avg 4µs/call
sub _make_wrapped_sub_with_meta {
3339684µs my $self = shift;
334 my $fq_name = shift;
335 my $sub = shift;
336 my $export_recorder = shift;
337 my $meta_lookup = shift;
338
339
# spent 1.49ms (736µs+751µs) within Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:352] which was called 88 times, avg 17µs/call: # 88 times (736µs+751µs) by Sub::Exporter::default_generator at line 856 of Sub/Exporter.pm, avg 17µs/call
return sub {
340440902µs my $caller = $CALLER;
341
34288535µs my $wrapper = $self->_late_curry_wrapper(
# spent 535µs making 88 calls to Moose::Exporter::_late_curry_wrapper, avg 6µs/call
343 $sub, $fq_name,
344 $meta_lookup => $caller
345 );
346
34788216µs my $sub = subname( $fq_name => $wrapper );
# spent 216µs making 88 calls to Sub::Name::subname, avg 2µs/call
348
349 $export_recorder->{$sub} = 1;
350
351 return $sub;
352 };
353}
354
355sub _curry_wrapper {
356 my $class = shift;
357 my $sub = shift;
358 my $fq_name = shift;
359 my @extra = @_;
360
361 my $wrapper = sub { $sub->( @extra, @_ ) };
362 if ( my $proto = prototype $sub ) {
363
364 # XXX - Perl's prototype sucks. Use & to make set_prototype
365 # ignore the fact that we're passing "private variables"
366 &Scalar::Util::set_prototype( $wrapper, $proto );
367 }
368 return $wrapper;
369}
370
371
# spent 535µs within Moose::Exporter::_late_curry_wrapper which was called 88 times, avg 6µs/call: # 88 times (535µs+0s) by Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:352] at line 342, avg 6µs/call
sub _late_curry_wrapper {
372704637µs my $class = shift;
373 my $sub = shift;
374 my $fq_name = shift;
375 my $extra = shift;
376 my @ex_args = @_;
377
378 my $wrapper = sub {
379
380 # resolve curried arguments at runtime via this closure
38130154µs15228µs my @curry = ( $extra->(@ex_args) );
# spent 228µs making 15 calls to Moose::Exporter::__ANON__[Moose/Exporter.pm:225], avg 15µs/call
38215129ms return $sub->( @curry, @_ );
# spent 107ms making 3 calls to Moose::with, avg 35.8ms/call # spent 14.3ms making 6 calls to Moose::has, avg 2.39ms/call # spent 7.27ms making 2 calls to Moose::extends, avg 3.64ms/call, recursion: max depth 1, sum of overlapping time 797µs # spent 669µs making 2 calls to Moose::Role::has, avg 334µs/call # spent 252µs making 2 calls to Moose::Role::requires, avg 126µs/call
383 };
384
385 if ( my $proto = prototype $sub ) {
386
387 # XXX - Perl's prototype sucks. Use & to make set_prototype
388 # ignore the fact that we're passing "private variables"
389 &Scalar::Util::set_prototype( $wrapper, $proto );
390 }
391 return $wrapper;
392}
393
394
# spent 29µs within Moose::Exporter::_make_import_sub which was called 3 times, avg 10µs/call: # 3 times (29µs+0s) by Moose::Exporter::build_import_methods at line 65, avg 10µs/call
sub _make_import_sub {
3952132µs shift;
396 my $exporting_package = shift;
397 my $exporter = shift;
398 my $exports_from = shift;
399 my $is_reexport = shift;
400 my $meta_lookup = shift;
401
402
# spent 49.1ms (876µs+48.3) within Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:492] which was called 13 times, avg 3.78ms/call: # once (120µs+6.47ms) by Tapper::MCP::Scheduler::PrioQueue::BEGIN@6 at line 6 of lib/Tapper/MCP/Scheduler/PrioQueue.pm # once (69µs+4.82ms) by Tapper::MCP::Scheduler::Controller::BEGIN@6 at line 6 of lib/Tapper/MCP/Scheduler/Controller.pm # once (66µs+4.71ms) by Tapper::MCP::Scheduler::Algorithm::BEGIN@6 at line 6 of lib/Tapper/MCP/Scheduler/Algorithm.pm # once (66µs+4.49ms) by Tapper::MCP::BEGIN@8 at line 8 of lib/Tapper/MCP.pm # once (66µs+4.46ms) by Tapper::Producer::Temare::BEGIN@11 at line 11 of Tapper/Producer/Temare.pm # once (63µs+4.45ms) by Tapper::MCP::Net::BEGIN@9 at line 9 of lib/Tapper/MCP/Net.pm # once (57µs+4.09ms) by Tapper::Base::BEGIN@10 at line 10 of Tapper/Base.pm # once (63µs+3.26ms) by Any::Moose::_install_module at line 2 of (eval 240)[Any/Moose.pm:152] # once (65µs+2.97ms) by MooseX::Traits::BEGIN@2 at line 2 of MooseX/Traits.pm # once (61µs+2.89ms) by Tapper::MCP::Net::TAP::BEGIN@7 at line 7 of lib/Tapper/MCP/Net/TAP.pm # once (65µs+2.82ms) by Tapper::MCP::Scheduler::Algorithm::WFQ::BEGIN@5 at line 5 of lib/Tapper/MCP/Scheduler/Algorithm/WFQ.pm # once (65µs+1.47ms) by Moose::BEGIN@44 at line 44 of Moose.pm # once (51µs+1.36ms) by Moose::Role::BEGIN@22 at line 22 of Moose/Role.pm
return sub {
403
404 # I think we could use Sub::Exporter's collector feature
405 # to do this, but that would be rather gross, since that
406 # feature isn't really designed to return a value to the
407 # caller of the exporter sub.
408 #
409 # Also, this makes sure we preserve backwards compat for
410 # _get_caller, so it always sees the arguments in the
411 # expected order.
412260524µs my $traits;
41313227µs ( $traits, @_ ) = _strip_traits(@_);
# spent 227µs making 13 calls to Moose::Exporter::_strip_traits, avg 17µs/call
414
415 my $metaclass;
41613128µs ( $metaclass, @_ ) = _strip_metaclass(@_);
# spent 128µs making 13 calls to Moose::Exporter::_strip_metaclass, avg 10µs/call
417 $metaclass
418 = Moose::Util::resolve_metaclass_alias( 'Class' => $metaclass )
419 if defined $metaclass && length $metaclass;
420
421 my $meta_name;
42213113µs ( $meta_name, @_ ) = _strip_meta_name(@_);
# spent 113µs making 13 calls to Moose::Exporter::_strip_meta_name, avg 9µs/call
423
424 # Normally we could look at $_[0], but in some weird cases
425 # (involving goto &Moose::import), $_[0] ends as something
426 # else (like Squirrel).
427 my $class = $exporting_package;
428
4291353µs $CALLER = _get_caller(@_);
# spent 53µs making 13 calls to Moose::Exporter::_get_caller, avg 4µs/call
430
431 # this works because both pragmas set $^H (see perldoc
432 # perlvar) which affects the current compilation -
433 # i.e. the file who use'd us - which is why we don't need
434 # to do anything special to make it affect that file
435 # rather than this one (which is already compiled)
436
4371348µs strict->import;
# spent 48µs making 13 calls to strict::import, avg 4µs/call
43813198µs warnings->import;
# spent 198µs making 13 calls to warnings::import, avg 15µs/call
439
440 my $did_init_meta;
44113119µs1341µs for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) {
# spent 41µs making 13 calls to UNIVERSAL::can, avg 3µs/call
442
443 # init_meta can apply a role, which when loaded uses
444 # Moose::Exporter, which in turn sets $CALLER, so we need
445 # to protect against that.
4463390µs local $CALLER = $CALLER;
4471129.7ms $c->init_meta(
# spent 23.8ms making 7 calls to Moose::init_meta, avg 3.40ms/call # spent 5.88ms making 4 calls to Moose::Role::init_meta, avg 1.47ms/call
448 for_class => $CALLER,
449 metaclass => $metaclass,
450 meta_name => $meta_name,
451 );
452 $did_init_meta = 1;
453 }
454
455 {
456 # The metaroles will use Moose::Role, which in turn uses
457 # Moose::Exporter, which in turn sets $CALLER, so we need
458 # to protect against that.
4592658µs local $CALLER = $CALLER;
46013669µs _apply_metaroles(
# spent 669µs making 13 calls to Moose::Exporter::_apply_metaroles, avg 51µs/call
461 $CALLER,
462 [$class, @$exports_from],
463 $meta_lookup
464 );
465 }
466
467 if ( $did_init_meta && @{$traits} ) {
468
469 # The traits will use Moose::Role, which in turn uses
470 # Moose::Exporter, which in turn sets $CALLER, so we need
471 # to protect against that.
472 local $CALLER = $CALLER;
473 _apply_meta_traits( $CALLER, $traits, $meta_lookup );
474 }
475 elsif ( @{$traits} ) {
476 require Moose;
477 Moose->throw_error(
478 "Cannot provide traits when $class does not have an init_meta() method"
479 );
480 }
481
482 my ( undef, @args ) = @_;
483 my $extra = shift @args if ref $args[0] eq 'HASH';
484
485 $extra ||= {};
4862621µs if ( !$extra->{into} ) {
487 $extra->{into_level} ||= 0;
488 $extra->{into_level}++;
489 }
490
4911317.1ms $class->$exporter( $extra, @args );
# spent 17.1ms making 13 calls to Sub::Exporter::__ANON__[Sub/Exporter.pm:756], avg 1.32ms/call
492 };
493}
494
495
# spent 227µs (144+83) within Moose::Exporter::_strip_traits which was called 13 times, avg 17µs/call: # 13 times (144µs+83µs) by Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:492] at line 413, avg 17µs/call
sub _strip_traits {
49639244µs1383µs my $idx = first_index { ( $_ || '' ) eq '-traits' } @_;
# spent 83µs making 13 calls to List::MoreUtils::firstidx, avg 6µs/call
497
498 return ( [], @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
499
500 my $traits = $_[ $idx + 1 ];
501
502 splice @_, $idx, 2;
503
504 $traits = [$traits] unless ref $traits;
505
506 return ( $traits, @_ );
507}
508
509
# spent 128µs (101+27) within Moose::Exporter::_strip_metaclass which was called 13 times, avg 10µs/call: # 13 times (101µs+27µs) by Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:492] at line 416, avg 10µs/call
sub _strip_metaclass {
51039145µs1327µs my $idx = first_index { ( $_ || '' ) eq '-metaclass' } @_;
# spent 27µs making 13 calls to List::MoreUtils::firstidx, avg 2µs/call
511
512 return ( undef, @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
513
514 my $metaclass = $_[ $idx + 1 ];
515
516 splice @_, $idx, 2;
517
518 return ( $metaclass, @_ );
519}
520
521
# spent 113µs (92+21) within Moose::Exporter::_strip_meta_name which was called 13 times, avg 9µs/call: # 13 times (92µs+21µs) by Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:492] at line 422, avg 9µs/call
sub _strip_meta_name {
52239129µs1321µs my $idx = first_index { ( $_ || '' ) eq '-meta_name' } @_;
# spent 21µs making 13 calls to List::MoreUtils::firstidx, avg 2µs/call
523
524 return ( 'meta', @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
525
526 my $meta_name = $_[ $idx + 1 ];
527
528 splice @_, $idx, 2;
529
530 return ( $meta_name, @_ );
531}
532
533
# spent 669µs (193+475) within Moose::Exporter::_apply_metaroles which was called 13 times, avg 51µs/call: # 13 times (193µs+475µs) by Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:492] at line 460, avg 51µs/call
sub _apply_metaroles {
53487191µs my ($class, $exports_from, $meta_lookup) = @_;
535
53613326µs my $metaroles = _collect_metaroles($exports_from);
# spent 326µs making 13 calls to Moose::Exporter::_collect_metaroles, avg 25µs/call
537 my $base_class_roles = delete $metaroles->{base_class_roles};
538
53913135µs my $meta = $meta_lookup->($class);
# spent 135µs making 13 calls to Moose::Exporter::__ANON__[Moose/Exporter.pm:42], avg 10µs/call
540 # for instance, Moose.pm uses Moose::Util::TypeConstraints
541 return unless $meta;
542
543 Moose::Util::MetaRole::apply_metaroles(
544 for => $meta,
545 %$metaroles,
546 ) if keys %$metaroles;
547
5481114µs Moose::Util::MetaRole::apply_base_class_roles(
# spent 14µs making 11 calls to UNIVERSAL::isa, avg 1µs/call
549 for => $meta,
550 roles => $base_class_roles,
551 ) if $meta->isa('Class::MOP::Class')
552 && $base_class_roles && @$base_class_roles;
553}
554
555
# spent 326µs within Moose::Exporter::_collect_metaroles which was called 13 times, avg 25µs/call: # 13 times (326µs+0s) by Moose::Exporter::_apply_metaroles at line 536, avg 25µs/call
sub _collect_metaroles {
556104227µs my ($exports_from) = @_;
557
558 my @old_style_role_types = map { "${_}_roles" } qw(
559 metaclass
560 attribute_metaclass
561 method_metaclass
562 wrapped_method_metaclass
563 instance_metaclass
564 constructor_class
565 destructor_class
566 error_class
567 );
568
569 my %class_metaroles;
570 my %role_metaroles;
571 my @base_class_roles;
572 my %old_style_roles;
573
574 for my $exporter (@$exports_from) {
5756565µs my $data = $EXPORT_SPEC{$exporter};
576
577 if (exists $data->{class_metaroles}) {
578 for my $type (keys %{ $data->{class_metaroles} }) {
579 push @{ $class_metaroles{$type} ||= [] },
580 @{ $data->{class_metaroles}{$type} };
581 }
582 }
583
584 if (exists $data->{role_metaroles}) {
585 for my $type (keys %{ $data->{role_metaroles} }) {
586 push @{ $role_metaroles{$type} ||= [] },
587 @{ $data->{role_metaroles}{$type} };
588 }
589 }
590
591 if (exists $data->{base_class_roles}) {
592 push @base_class_roles, @{ $data->{base_class_roles} };
593 }
594
595 for my $type (@old_style_role_types) {
59610450µs if (exists $data->{$type}) {
597 push @{ $old_style_roles{$type} ||= [] },
598 @{ $data->{$type} };
599 }
600 }
601 }
602
603 return {
604 (keys(%class_metaroles)
605 ? (class_metaroles => \%class_metaroles)
606 : ()),
607 (keys(%role_metaroles)
608 ? (role_metaroles => \%role_metaroles)
609 : ()),
610 (@base_class_roles
611 ? (base_class_roles => \@base_class_roles)
612 : ()),
613 %old_style_roles,
614 };
615}
616
617sub _apply_meta_traits {
618 my ( $class, $traits, $meta_lookup ) = @_;
619
620 return unless @{$traits};
621
622 my $meta = $meta_lookup->($class);
623
624 my $type = ( split /::/, ref $meta )[-1]
625 or Moose->throw_error(
626 'Cannot determine metaclass type for trait application . Meta isa '
627 . ref $meta );
628
629 my @resolved_traits = map {
630 ref $_
631 ? $_
632 : Moose::Util::resolve_metatrait_alias( $type => $_ )
633 } @$traits;
634
635 return unless @resolved_traits;
636
637 my %args = ( for => $class );
638
639 if ( $meta->isa('Moose::Meta::Role') ) {
640 $args{role_metaroles} = { role => \@resolved_traits };
641 }
642 else {
643 $args{class_metaroles} = { class => \@resolved_traits };
644 }
645
646 Moose::Util::MetaRole::apply_metaroles(%args);
647}
648
649
# spent 53µs within Moose::Exporter::_get_caller which was called 13 times, avg 4µs/call: # 13 times (53µs+0s) by Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:492] at line 429, avg 4µs/call
sub _get_caller {
650
651 # 1 extra level because it's called by import so there's a layer
652 # of indirection
6532673µs my $offset = 1;
654
655 return
656 ( ref $_[1] && defined $_[1]->{into} ) ? $_[1]->{into}
657 : ( ref $_[1] && defined $_[1]->{into_level} )
658 ? caller( $offset + $_[1]->{into_level} )
659 : caller($offset);
660}
661
662
# spent 23µs within Moose::Exporter::_make_unimport_sub which was called 3 times, avg 8µs/call: # 3 times (23µs+0s) by Moose::Exporter::build_import_methods at line 73, avg 8µs/call
sub _make_unimport_sub {
6632126µs shift;
664 my $exporting_package = shift;
665 my $exports = shift;
666 my $export_recorder = shift;
667 my $is_reexport = shift;
668 my $meta_lookup = shift;
669
670
# spent 318µs (36+282) within Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:678] which was called: # once (36µs+282µs) by MooseX::Traits::BEGIN@86 at line 86 of MooseX/Traits.pm
return sub {
671233µs my $caller = scalar caller();
672 Moose::Exporter->_remove_keywords(
673 $caller,
6741282µs [ keys %{$exports} ],
# spent 282µs making 1 call to Moose::Exporter::_remove_keywords
675 $export_recorder,
676 $is_reexport,
677 );
678 };
679}
680
681
# spent 282µs (274+7) within Moose::Exporter::_remove_keywords which was called: # once (274µs+7µs) by Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:678] at line 674
sub _remove_keywords {
682621µs shift;
683 my $package = shift;
684 my $keywords = shift;
685 my $recorded_exports = shift;
686 my $is_reexport = shift;
687
688351µs261µs
# spent 37µs (13+24) within Moose::Exporter::BEGIN@688 which was called: # once (13µs+24µs) by Moose::BEGIN@19 at line 688
no strict 'refs';
# spent 37µs making 1 call to Moose::Exporter::BEGIN@688 # spent 24µs making 1 call to strict::unimport
689
690 foreach my $name ( @{$keywords} ) {
69170229µs if ( defined &{ $package . '::' . $name } ) {
692 my $sub = \&{ $package . '::' . $name };
693
694 # make sure it is from us
695 next unless $recorded_exports->{$sub};
696
697239µs if ( $is_reexport->{$name} ) {
6983293µs221µs
# spent 13µs (6+8) within Moose::Exporter::BEGIN@698 which was called: # once (6µs+8µs) by Moose::BEGIN@19 at line 698
no strict 'refs';
# spent 13µs making 1 call to Moose::Exporter::BEGIN@698 # spent 8µs making 1 call to strict::unimport
699 next
700 unless _export_is_flagged(
70127µs \*{ join q{::} => $package, $name } );
# spent 7µs making 2 calls to Moose::Exporter::_export_is_flagged, avg 4µs/call
702 }
703
704 # and if it is from us, then undef the slot
705 delete ${ $package . '::' }{$name};
706 }
707 }
708}
709
710# maintain this for now for backcompat
711# make sure to return a sub to install in the same circumstances as previously
712# but this functionality now happens at the end of ->import
713
# spent 50µs within Moose::Exporter::_make_init_meta which was called 3 times, avg 17µs/call: # 3 times (50µs+0s) by Moose::Exporter::build_import_methods at line 81, avg 17µs/call
sub _make_init_meta {
7143040µs shift;
715 my $class = shift;
716 my $args = shift;
717 my $meta_lookup = shift;
718
719 my %old_style_roles;
720 for my $role (
721 map {"${_}_roles"}
722 qw(
723 metaclass
724 attribute_metaclass
725 method_metaclass
726 wrapped_method_metaclass
727 instance_metaclass
728 constructor_class
729 destructor_class
730 error_class
731 )
732 ) {
7332412µs $old_style_roles{$role} = $args->{$role}
734 if exists $args->{$role};
735 }
736
737 my %base_class_roles;
738 %base_class_roles = ( roles => $args->{base_class_roles} )
739 if exists $args->{base_class_roles};
740
741 my %new_style_roles = map { $_ => $args->{$_} }
742 grep { exists $args->{$_} } qw( class_metaroles role_metaroles );
743
744 return unless %new_style_roles || %old_style_roles || %base_class_roles;
745
746 return sub {
747 shift;
748 my %opts = @_;
749 $meta_lookup->($opts{for_class});
750 };
751}
752
753
# spent 74µs (29+45) within Moose::Exporter::import which was called 3 times, avg 25µs/call: # once (11µs+23µs) by Moose::BEGIN@19 at line 19 of Moose.pm # once (9µs+12µs) by Moose::Role::BEGIN@20 at line 20 of Moose/Role.pm # once (9µs+10µs) by Moose::Util::TypeConstraints::BEGIN@13 at line 13 of Moose/Util/TypeConstraints.pm
sub import {
754619µs36µs strict->import;
# spent 6µs making 3 calls to strict::import, avg 2µs/call
755339µs warnings->import;
# spent 39µs making 3 calls to warnings::import, avg 13µs/call
756}
757
75815µs1;
759
760# ABSTRACT: make an import() and unimport() just like Moose.pm
761
- -
764=pod
765
766=head1 NAME
767
768Moose::Exporter - make an import() and unimport() just like Moose.pm
769
770=head1 VERSION
771
772version 2.0602
773
774=head1 SYNOPSIS
775
776 package MyApp::Moose;
777
778 use Moose ();
779 use Moose::Exporter;
780
781 Moose::Exporter->setup_import_methods(
782 with_meta => [ 'has_rw', 'sugar2' ],
783 as_is => [ 'sugar3', \&Some::Random::thing ],
784 also => 'Moose',
785 );
786
787 sub has_rw {
788 my ( $meta, $name, %options ) = @_;
789 $meta->add_attribute(
790 $name,
791 is => 'rw',
792 %options,
793 );
794 }
795
796 # then later ...
797 package MyApp::User;
798
799 use MyApp::Moose;
800
801 has 'name';
802 has_rw 'size';
803 thing;
804
805 no MyApp::Moose;
806
807=head1 DESCRIPTION
808
809This module encapsulates the exporting of sugar functions in a
810C<Moose.pm>-like manner. It does this by building custom C<import> and
811C<unimport> methods for your module, based on a spec you provide.
812
813It also lets you "stack" Moose-alike modules so you can export Moose's sugar
814as well as your own, along with sugar from any random C<MooseX> module, as
815long as they all use C<Moose::Exporter>. This feature exists to let you bundle
816a set of MooseX modules into a policy module that developers can use directly
817instead of using Moose itself.
818
819To simplify writing exporter modules, C<Moose::Exporter> also imports
820C<strict> and C<warnings> into your exporter module, as well as into
821modules that use it.
822
823=head1 METHODS
824
825This module provides two public methods:
826
827=over 4
828
829=item B<< Moose::Exporter->setup_import_methods(...) >>
830
831When you call this method, C<Moose::Exporter> builds custom C<import> and
832C<unimport> methods for your module. The C<import> method
833will export the functions you specify, and can also re-export functions
834exported by some other module (like C<Moose.pm>). If you pass any parameters
835for L<Moose::Util::MetaRole>, the C<import> method will also call
836C<Moose::Util::MetaRole::apply_metaroles> and
837C<Moose::Util::MetaRole::apply_base_class_roles> as needed, after making
838sure the metaclass is initialized.
839
840The C<unimport> method cleans the caller's namespace of all the exported
841functions. This includes any functions you re-export from other
842packages. However, if the consumer of your package also imports those
843functions from the original package, they will I<not> be cleaned.
844
845Note that if any of these methods already exist, they will not be
846overridden, you will have to use C<build_import_methods> to get the
847coderef that would be installed.
848
849This method accepts the following parameters:
850
851=over 8
852
853=item * with_meta => [ ... ]
854
855This list of function I<names only> will be wrapped and then exported. The
856wrapper will pass the metaclass object for the caller as its first argument.
857
858Many sugar functions will need to use this metaclass object to do something to
859the calling package.
860
861=item * as_is => [ ... ]
862
863This list of function names or sub references will be exported as-is. You can
864identify a subroutine by reference, which is handy to re-export some other
865module's functions directly by reference (C<\&Some::Package::function>).
866
867If you do export some other package's function, this function will never be
868removed by the C<unimport> method. The reason for this is we cannot know if
869the caller I<also> explicitly imported the sub themselves, and therefore wants
870to keep it.
871
872=item * trait_aliases => [ ... ]
873
874This is a list of package names which should have shortened aliases exported,
875similar to the functionality of L<aliased>. Each element in the list can be
876either a package name, in which case the export will be named as the last
877namespace component of the package, or an arrayref, whose first element is the
878package to alias to, and second element is the alias to export.
879
880=item * also => $name or \@names
881
882This is a list of modules which contain functions that the caller
883wants to export. These modules must also use C<Moose::Exporter>. The
884most common use case will be to export the functions from C<Moose.pm>.
885Functions specified by C<with_meta> or C<as_is> take precedence over
886functions exported by modules specified by C<also>, so that a module
887can selectively override functions exported by another module.
888
889C<Moose::Exporter> also makes sure all these functions get removed
890when C<unimport> is called.
891
892=item * meta_lookup => sub { ... }
893
894This is a function which will be called to provide the metaclass
895to be operated upon by the exporter. This is an advanced feature
896intended for use by package generator modules in the vein of
897L<MooseX::Role::Parameterized> in order to simplify reusing sugar
898from other modules that use C<Moose::Exporter>. This function is
899used, for example, to select the metaclass to bind to functions
900that are exported using the C<with_meta> option.
901
902This function will receive one parameter: the class name into which
903the sugar is being exported. The default implementation is:
904
905 sub { Class::MOP::class_of(shift) }
906
907Accordingly, this function is expected to return a metaclass.
908
909=back
910
911You can also provide parameters for C<Moose::Util::MetaRole::apply_metaroles>
912and C<Moose::Util::MetaRole::base_class_roles>. Specifically, valid parameters
913are "class_metaroles", "role_metaroles", and "base_class_roles".
914
915=item B<< Moose::Exporter->build_import_methods(...) >>
916
917Returns two code refs, one for C<import> and one for C<unimport>.
918
919Accepts the additional C<install> option, which accepts an arrayref of method
920names to install into your exporting package. The valid options are C<import>
921and C<unimport>. Calling C<setup_import_methods> is equivalent
922to calling C<build_import_methods> with C<< install => [qw(import unimport)] >>
923except that it doesn't also return the methods.
924
925The C<import> method is built using L<Sub::Exporter>. This means that it can
926take a hashref of the form C<< { into => $package } >> to specify the package
927it operates on.
928
929Used by C<setup_import_methods>.
930
931=back
932
933=head1 IMPORTING AND init_meta
934
935If you want to set an alternative base object class or metaclass class, see
936above for details on how this module can call L<Moose::Util::MetaRole> for
937you.
938
939If you want to do something that is not supported by this module, simply
940define an C<init_meta> method in your class. The C<import> method that
941C<Moose::Exporter> generates for you will call this method (if it exists). It
942will always pass the caller to this method via the C<for_class> parameter.
943
944Most of the time, your C<init_meta> method will probably just call C<<
945Moose->init_meta >> to do the real work:
946
947 sub init_meta {
948 shift; # our class name
949 return Moose->init_meta( @_, metaclass => 'My::Metaclass' );
950 }
951
952=head1 METACLASS TRAITS
953
954The C<import> method generated by C<Moose::Exporter> will allow the
955user of your module to specify metaclass traits in a C<-traits>
956parameter passed as part of the import:
957
958 use Moose -traits => 'My::Meta::Trait';
959
960 use Moose -traits => [ 'My::Meta::Trait', 'My::Other::Trait' ];
961
962These traits will be applied to the caller's metaclass
963instance. Providing traits for an exporting class that does not create
964a metaclass for the caller is an error.
965
966=head1 BUGS
967
968See L<Moose/BUGS> for details on reporting bugs.
969
970=head1 AUTHOR
971
972Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
973
974=head1 COPYRIGHT AND LICENSE
975
976This software is copyright (c) 2012 by Infinity Interactive, Inc..
977
978This is free software; you can redistribute it and/or modify it under
979the same terms as the Perl 5 programming language system itself.
980
981=cut
982
983
984__END__
 
# spent 7µs within Moose::Exporter::_export_is_flagged which was called 2 times, avg 4µs/call: # 2 times (7µs+0s) by Moose::Exporter::_remove_keywords at line 701, avg 4µs/call
sub Moose::Exporter::_export_is_flagged; # xsub
# spent 31µs within Moose::Exporter::_flag_as_reexport which was called 22 times, avg 1µs/call: # 22 times (31µs+0s) by Moose::Exporter::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Exporter.pm:137] at line 135, avg 1µs/call
sub Moose::Exporter::_flag_as_reexport; # xsub