← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/bin/epoll_server.pl
  Run on Wed Jan 5 05:34:33 2011
Reported on Wed Jan 5 05:36:02 2011

File /usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm
Statements Executed 12228
Statement Execution Time 122ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
4881127.0ms54.4msMoose::Exporter::::__ANON__[:263]Moose::Exporter::__ANON__[:263]
11125.1ms391msMoose::Exporter::::BEGIN@11Moose::Exporter::BEGIN@11
4881119.8ms19.8msMoose::Exporter::::_late_curry_wrapperMoose::Exporter::_late_curry_wrapper
68686116.0ms1.02sMoose::Exporter::::__ANON__[:389]Moose::Exporter::__ANON__[:389]
13115.06ms5.19msMoose::Exporter::::_remove_keywordsMoose::Exporter::_remove_keywords
7113.81ms6.31msMoose::Exporter::::_make_sub_exporter_paramsMoose::Exporter::_make_sub_exporter_params
183113.12ms8.23msMoose::Exporter::::__ANON__[:255]Moose::Exporter::__ANON__[:255]
1112.77ms3.96msMoose::Exporter::::BEGIN@13Moose::Exporter::BEGIN@13
68112.76ms4.25msMoose::Exporter::::_strip_traitsMoose::Exporter::_strip_traits
383112.45ms2.45msMoose::Exporter::::__ANON__[:193]Moose::Exporter::__ANON__[:193]
1111.76ms4.46msMoose::Exporter::::BEGIN@12Moose::Exporter::BEGIN@12
68111.71ms2.39msMoose::Exporter::::_strip_metaclassMoose::Exporter::_strip_metaclass
73311.68ms1.68msMoose::Exporter::::_sub_from_packageMoose::Exporter::_sub_from_package
7111.59ms24.2msMoose::Exporter::::build_import_methodsMoose::Exporter::build_import_methods
68111.07ms1.07msMoose::Exporter::::_get_callerMoose::Exporter::_get_caller
12212785µs785µsMoose::Exporter::::_flag_as_reexportMoose::Exporter::_flag_as_reexport (xsub)
131313600µs5.79msMoose::Exporter::::__ANON__[:478]Moose::Exporter::__ANON__[:478]
3211539µs539µsMoose::Exporter::::_make_wrapped_sub_with_metaMoose::Exporter::_make_wrapped_sub_with_meta
711490µs490µsMoose::Exporter::::_make_init_metaMoose::Exporter::_make_init_meta
777340µs1000µsMoose::Exporter::::importMoose::Exporter::import
711292µs292µsMoose::Exporter::::_make_import_subMoose::Exporter::_make_import_sub
711247µs567µsMoose::Exporter::::_follow_alsoMoose::Exporter::_follow_also
777240µs24.5msMoose::Exporter::::setup_import_methodsMoose::Exporter::setup_import_methods
1011232µs232µsMoose::Exporter::::_make_wrapped_subMoose::Exporter::_make_wrapped_sub
921177µs177µsMoose::Exporter::::_follow_also_realMoose::Exporter::_follow_also_real
1011172µs357µsMoose::Exporter::::__ANON__[:241]Moose::Exporter::__ANON__[:241]
711141µs141µsMoose::Exporter::::_make_unimport_subMoose::Exporter::_make_unimport_sub
2612134µs134µsMoose::Exporter::::_export_is_flaggedMoose::Exporter::_export_is_flagged (xsub)
1011119µs127µsMoose::Exporter::::_curry_wrapperMoose::Exporter::_curry_wrapper
11154µs714µsMoose::Exporter::::BEGIN@14Moose::Exporter::BEGIN@14
11151µs64µsMoose::Exporter::::BEGIN@3Moose::Exporter::BEGIN@3
11135µs87µsMoose::Exporter::::BEGIN@385Moose::Exporter::BEGIN@385
11134µs90µsMoose::Exporter::::BEGIN@386Moose::Exporter::BEGIN@386
11131µs82µsMoose::Exporter::::BEGIN@488Moose::Exporter::BEGIN@488
11131µs83µsMoose::Exporter::::BEGIN@206Moose::Exporter::BEGIN@206
11130µs188µsMoose::Exporter::::BEGIN@15Moose::Exporter::BEGIN@15
11130µs87µsMoose::Exporter::::BEGIN@4Moose::Exporter::BEGIN@4
11128µs72µsMoose::Exporter::::BEGIN@498Moose::Exporter::BEGIN@498
11119µs19µsMoose::Exporter::::BEGIN@17Moose::Exporter::BEGIN@17
0000s0sMoose::Exporter::::__ANON__[:272]Moose::Exporter::__ANON__[:272]
0000s0sMoose::Exporter::::__ANON__[:294]Moose::Exporter::__ANON__[:294]
0000s0sMoose::Exporter::::__ANON__[:393]Moose::Exporter::__ANON__[:393]
0000s0sMoose::Exporter::::__ANON__[:407]Moose::Exporter::__ANON__[:407]
0000s0sMoose::Exporter::::__ANON__[:562]Moose::Exporter::__ANON__[:562]
0000s0sMoose::Exporter::::_apply_meta_traitsMoose::Exporter::_apply_meta_traits
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
3383µs277µs
# spent 64µs (51+13) within Moose::Exporter::BEGIN@3 which was called # once (51µs+13µs) by Moose::BEGIN@14 at line 3
use strict;
# spent 64µs making 1 call to Moose::Exporter::BEGIN@3 # spent 13µs making 1 call to strict::import
43176µs2145µs
# spent 87µs (30+57) within Moose::Exporter::BEGIN@4 which was called # once (30µs+57µs) by Moose::BEGIN@14 at line 4
use warnings;
# spent 87µs making 1 call to Moose::Exporter::BEGIN@4 # spent 58µs making 1 call to warnings::import
5
613µsour $VERSION = '1.01';
712µsour $XS_VERSION = $VERSION;
8154µs$VERSION = eval $VERSION;
913µsour $AUTHORITY = 'cpan:STEVAN';
10
113769µs1391ms
# spent 391ms (25.1+366) within Moose::Exporter::BEGIN@11 which was called # once (25.1ms+366ms) by Moose::BEGIN@14 at line 11
use Class::MOP;
# spent 391ms making 1 call to Moose::Exporter::BEGIN@11
123506µs24.97ms
# spent 4.46ms (1.76+2.70) within Moose::Exporter::BEGIN@12 which was called # once (1.76ms+2.70ms) by Moose::BEGIN@14 at line 12
use List::MoreUtils qw( first_index uniq );
# spent 4.46ms making 1 call to Moose::Exporter::BEGIN@12 # spent 510µs making 1 call to Exporter::import
133349µs13.96ms
# spent 3.96ms (2.77+1.19) within Moose::Exporter::BEGIN@13 which was called # once (2.77ms+1.19ms) by Moose::BEGIN@14 at line 13
use Moose::Util::MetaRole;
# spent 3.96ms making 1 call to Moose::Exporter::BEGIN@13
143177µs31.38ms
# spent 714µs (54+661) within Moose::Exporter::BEGIN@14 which was called # once (54µs+661µs) by Moose::BEGIN@14 at line 14
use Sub::Exporter 0.980;
# spent 714µs making 1 call to Moose::Exporter::BEGIN@14 # spent 617µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] # spent 44µs making 1 call to UNIVERSAL::VERSION
15384µs2346µs
# spent 188µs (30+158) within Moose::Exporter::BEGIN@15 which was called # once (30µs+158µs) by Moose::BEGIN@14 at line 15
use Sub::Name qw(subname);
# spent 188µs making 1 call to Moose::Exporter::BEGIN@15 # spent 158µs making 1 call to Exporter::import
16
1732.89ms119µs
# spent 19µs within Moose::Exporter::BEGIN@17 which was called # once (19µs+0s) by Moose::BEGIN@14 at line 17
use XSLoader;
# spent 19µs making 1 call to Moose::Exporter::BEGIN@17
18
191321µs1303µsXSLoader::load( 'Moose', $XS_VERSION );
# spent 303µs making 1 call to XSLoader::load
20
2111µsmy %EXPORT_SPEC;
22
23
# spent 24.5ms (240µs+24.2) within Moose::Exporter::setup_import_methods which was called 7 times, avg 3.49ms/call: # once (47µs+6.09ms) by Moose::Meta::Attribute::BEGIN@18 at line 41 of Moose/Util/TypeConstraints.pm # once (38µs+4.60ms) by MooseX::MethodAttributes::Role::Meta::Role::BEGIN@13 at line 16 of MooseX/MethodAttributes/Role.pm # once (41µs+4.30ms) by Catalyst::Engine::HTTP::BEGIN@3 at line 121 of Moose.pm # once (32µs+2.92ms) by MooseX::Types::BEGIN@15 at line 68 of MooseX/Types/CheckedUtilExports.pm # once (21µs+2.26ms) by Catalyst::Exception::Basic::BEGIN@3 at line 18 of MooseX/Role/WithOverloading.pm # once (23µs+2.19ms) by MooseX::Emulate::Class::Accessor::Fast::BEGIN@3 at line 91 of Moose/Role.pm # once (38µs+1.86ms) by MooseX::MethodAttributes::Role::Meta::Role::BEGIN@12 at line 16 of MooseX/MethodAttributes.pm
sub setup_import_methods {
2421245µs my ( $class, %args ) = @_;
25
26 my $exporting_package = $args{exporting_package} ||= caller();
27
28 $class->build_import_methods(
# spent 24.2ms making 7 calls to Moose::Exporter::build_import_methods, avg 3.46ms/call
29 %args,
30 install => [qw(import unimport init_meta)]
31 );
32}
33
34
# spent 24.2ms (1.59+22.6) within Moose::Exporter::build_import_methods which was called 7 times, avg 3.46ms/call: # 7 times (1.59ms+22.6ms) by Moose::Exporter::setup_import_methods at line 28, avg 3.46ms/call
sub build_import_methods {
351611.21ms my ( $class, %args ) = @_;
36
37 my $exporting_package = $args{exporting_package} ||= caller();
38
39 $EXPORT_SPEC{$exporting_package} = \%args;
40
41 my @exports_from = $class->_follow_also($exporting_package);
# spent 567µs making 7 calls to Moose::Exporter::_follow_also, avg 81µs/call
42
43 my $export_recorder = {};
44 my $is_reexport = {};
45
46 my $exports = $class->_make_sub_exporter_params(
# spent 6.31ms making 7 calls to Moose::Exporter::_make_sub_exporter_params, avg 902µs/call
47 [ @exports_from, $exporting_package ],
48 $export_recorder,
49 $is_reexport,
50 );
51
52 my $exporter = Sub::Exporter::build_exporter(
# spent 12.4ms making 7 calls to Sub::Exporter::build_exporter, avg 1.77ms/call
53 {
54 exports => $exports,
55 groups => { default => [':all'] }
56 }
57 );
58
59 my %methods;
60 $methods{import} = $class->_make_import_sub(
# spent 292µs making 7 calls to Moose::Exporter::_make_import_sub, avg 42µs/call
61 $exporting_package,
62 $exporter,
63 \@exports_from,
64 $is_reexport
65 );
66
67 $methods{unimport} = $class->_make_unimport_sub(
# spent 141µs making 7 calls to Moose::Exporter::_make_unimport_sub, avg 20µs/call
68 $exporting_package,
69 $exports,
70 $export_recorder,
71 $is_reexport
72 );
73
74 $methods{init_meta} = $class->_make_init_meta(
# spent 490µs making 7 calls to Moose::Exporter::_make_init_meta, avg 70µs/call
75 $exporting_package,
76 \%args
77 );
78
79 my $package = Class::MOP::Package->initialize($exporting_package);
# spent 906µs making 7 calls to Class::MOP::Package::initialize, avg 129µs/call
80 for my $to_install ( @{ $args{install} || [] } ) {
81 my $symbol = '&' . $to_install;
82 next
83 unless $methods{$to_install}
# spent 923µs making 14 calls to Class::MOP::Package::has_package_symbol, avg 66µs/call
84 && !$package->has_package_symbol($symbol);
85 $package->add_package_symbol( $symbol, $methods{$to_install} );
# spent 597µs making 14 calls to Class::MOP::Package::add_package_symbol, avg 43µs/call
86 }
87
88 return ( $methods{import}, $methods{unimport}, $methods{init_meta} );
89}
90
91{
9226µs my $seen = {};
93
94
# spent 567µs (247+320) within Moose::Exporter::_follow_also which was called 7 times, avg 81µs/call: # 7 times (247µs+320µs) by Moose::Exporter::build_import_methods at line 41, avg 81µs/call
sub _follow_also {
9528366µs my $class = shift;
96 my $exporting_package = shift;
97
98 local %$seen = ( $exporting_package => 1 );
99
100 return uniq( _follow_also_real($exporting_package) );
# spent 177µs making 7 calls to Moose::Exporter::_follow_also_real, avg 25µs/call # spent 142µs making 7 calls to List::MoreUtils::uniq, avg 20µs/call
101 }
102
103
# spent 177µs (177+-0ns) within Moose::Exporter::_follow_also_real which was called 9 times, avg 20µs/call: # 7 times (153µs+24µs) by Moose::Exporter::_follow_also at line 100, avg 25µs/call # 2 times (24µs+-24µs) by Moose::Exporter::_follow_also_real at line 128, avg 0s/call
sub _follow_also_real {
10448219µs my $exporting_package = shift;
105
106 if ( !exists $EXPORT_SPEC{$exporting_package} ) {
107 my $loaded = Class::MOP::is_class_loaded($exporting_package);
108
109 die "Package in also ($exporting_package) does not seem to "
110 . "use Moose::Exporter"
111 . ( $loaded ? "" : " (is it loaded?)" );
112 }
113
114 my $also = $EXPORT_SPEC{$exporting_package}{also};
115
116 return unless defined $also;
117
118 my @also = ref $also ? @{$also} : $also;
119
120 for my $package (@also) {
121 die
122 "Circular reference in 'also' parameter to Moose::Exporter between $exporting_package and $package"
123 if $seen->{$package};
124
125 $seen->{$package} = 1;
126 }
127
128 return @also, map { _follow_also_real($_) } @also;
# spent 24µs making 2 calls to Moose::Exporter::_follow_also_real, avg 12µs/call, recursion: max depth 1, time 24µs
129 }
130}
131
132
# spent 6.31ms (3.81+2.50) within Moose::Exporter::_make_sub_exporter_params which was called 7 times, avg 902µs/call: # 7 times (3.81ms+2.50ms) by Moose::Exporter::build_import_methods at line 46, avg 902µs/call
sub _make_sub_exporter_params {
1334613.45ms my $class = shift;
134 my $packages = shift;
135 my $export_recorder = shift;
136 my $is_reexport = shift;
137
138 my %exports;
139
140 for my $package ( @{$packages} ) {
141 my $args = $EXPORT_SPEC{$package}
142 or die "The $package package does not use Moose::Exporter\n";
143
144 for my $name ( @{ $args->{with_meta} } ) {
145 my $sub = $class->_sub_from_package( $package, $name )
# spent 507µs making 32 calls to Moose::Exporter::_sub_from_package, avg 16µs/call
146 or next;
147
148 my $fq_name = $package . '::' . $name;
149
150 $exports{$name} = $class->_make_wrapped_sub_with_meta(
# spent 539µs making 32 calls to Moose::Exporter::_make_wrapped_sub_with_meta, avg 17µs/call
151 $fq_name,
152 $sub,
153 $export_recorder,
154 );
155 }
156
157 for my $name ( @{ $args->{with_caller} } ) {
158 my $sub = $class->_sub_from_package( $package, $name )
# spent 163µs making 10 calls to Moose::Exporter::_sub_from_package, avg 16µs/call
159 or next;
160
161 my $fq_name = $package . '::' . $name;
162
163 $exports{$name} = $class->_make_wrapped_sub(
# spent 232µs making 10 calls to Moose::Exporter::_make_wrapped_sub, avg 23µs/call
164 $fq_name,
165 $sub,
166 $export_recorder,
167 );
168 }
169
170 for my $name ( @{ $args->{as_is} } ) {
171 my ( $sub, $coderef_name );
172
173 if ( ref $name ) {
174 $sub = $name;
175
176 my $coderef_pkg;
177 ( $coderef_pkg, $coderef_name )
# spent 45µs making 8 calls to Class::MOP::get_code_info, avg 6µs/call
178 = Class::MOP::get_code_info($name);
179
180 if ( $coderef_pkg ne $package ) {
181 $is_reexport->{$coderef_name} = 1;
182 }
183 }
184 else {
185 $sub = $class->_sub_from_package( $package, $name )
# spent 1.01ms making 31 calls to Moose::Exporter::_sub_from_package, avg 33µs/call
186 or next;
187
188 $coderef_name = $name;
189 }
190
191 $export_recorder->{$sub} = 1;
192
1933833.51ms
# spent 2.45ms within Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:193] which was called 383 times, avg 6µs/call: # 383 times (2.45ms+0s) by Sub::Exporter::default_generator at line 856 of Sub/Exporter.pm, avg 6µs/call
$exports{$coderef_name} = sub {$sub};
194 }
195 }
196
197 return \%exports;
198}
199
200
# spent 1.68ms within Moose::Exporter::_sub_from_package which was called 73 times, avg 23µs/call: # 32 times (507µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 145, avg 16µs/call # 31 times (1.01ms+0s) by Moose::Exporter::_make_sub_exporter_params at line 185, avg 33µs/call # 10 times (163µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 158, avg 16µs/call
sub _sub_from_package {
2014382.15ms my $sclass = shift;
202 my $package = shift;
203 my $name = shift;
204
205 my $sub = do {
20633.67ms2134µs
# spent 83µs (31+51) within Moose::Exporter::BEGIN@206 which was called # once (31µs+51µs) by Moose::BEGIN@14 at line 206
no strict 'refs';
# spent 83µs making 1 call to Moose::Exporter::BEGIN@206 # spent 52µs making 1 call to strict::unimport
207 \&{ $package . '::' . $name };
208 };
209
210 return $sub if defined &$sub;
211
212 Carp::cluck "Trying to export undefined sub ${package}::${name}";
213
214 return;
215}
216
21711µsour $CALLER;
218
219
# spent 232µs within Moose::Exporter::_make_wrapped_sub which was called 10 times, avg 23µs/call: # 10 times (232µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 163, avg 23µs/call
sub _make_wrapped_sub {
22050262µs my $self = shift;
221 my $fq_name = shift;
222 my $sub = shift;
223 my $export_recorder = shift;
224
225 # We need to set the package at import time, so that when
226 # package Foo imports has(), we capture "Foo" as the
227 # package. This lets other packages call Foo::has() and get
228 # the right package. This is done for backwards compatibility
229 # with existing production code, not because this is a good
230 # idea ;)
231
# spent 357µs (172+185) within Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:241] which was called 10 times, avg 36µs/call: # 10 times (172µs+185µs) by Sub::Exporter::default_generator at line 856 of Sub/Exporter.pm, avg 36µs/call
return sub {
23250218µs my $caller = $CALLER;
233
234 my $wrapper = $self->_curry_wrapper( $sub, $fq_name, $caller );
# spent 127µs making 10 calls to Moose::Exporter::_curry_wrapper, avg 13µs/call
235
236 my $sub = subname( $fq_name => $wrapper );
# spent 58µs making 10 calls to Sub::Name::subname, avg 6µs/call
237
238 $export_recorder->{$sub} = 1;
239
240 return $sub;
241 };
242}
243
244
# spent 539µs within Moose::Exporter::_make_wrapped_sub_with_meta which was called 32 times, avg 17µs/call: # 32 times (539µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 150, avg 17µs/call
sub _make_wrapped_sub_with_meta {
245160646µs my $self = shift;
246 my $fq_name = shift;
247 my $sub = shift;
248 my $export_recorder = shift;
249
250
# spent 54.4ms (27.0+27.5) within Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:263] which was called 488 times, avg 112µs/call: # 488 times (27.0ms+27.5ms) by Sub::Exporter::default_generator at line 856 of Sub/Exporter.pm, avg 112µs/call
return sub {
251244032.4ms my $caller = $CALLER;
252
253 my $wrapper = $self->_late_curry_wrapper(
254 $sub, $fq_name,
2551833.22ms67124.9ms
# spent 8.23ms (3.12+5.11) within Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:255] which was called 183 times, avg 45µs/call: # 183 times (3.12ms+5.11ms) by Moose::Role::after or Moose::Role::around or Moose::Role::before or Moose::Role::has or Moose::Role::override or Moose::Role::requires or Moose::Role::with or Moose::after or Moose::around or Moose::before or Moose::extends or Moose::has or Moose::with at line 292, avg 45µs/call
sub { Class::MOP::class_of(shift) } => $caller
# spent 19.8ms making 488 calls to Moose::Exporter::_late_curry_wrapper, avg 41µs/call # spent 5.11ms making 183 calls to Class::MOP::class_of, avg 28µs/call
256 );
257
258 my $sub = subname( $fq_name => $wrapper );
# spent 7.64ms making 488 calls to Sub::Name::subname, avg 16µs/call
259
260 $export_recorder->{$sub} = 1;
261
262 return $sub;
263 };
264}
265
266
# spent 127µs (119+8) within Moose::Exporter::_curry_wrapper which was called 10 times, avg 13µs/call: # 10 times (119µs+8µs) by Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:241] at line 234, avg 13µs/call
sub _curry_wrapper {
26770152µs my $class = shift;
268 my $sub = shift;
269 my $fq_name = shift;
270 my @extra = @_;
271
272 my $wrapper = sub { $sub->( @extra, @_ ) };
273 if ( my $proto = prototype $sub ) {
# spent 8µs making 1 call to Scalar::Util::set_prototype
274
275 # XXX - Perl's prototype sucks. Use & to make set_prototype
276 # ignore the fact that we're passing "private variables"
277 &Scalar::Util::set_prototype( $wrapper, $proto );
278 }
279 return $wrapper;
280}
281
282
# spent 19.8ms within Moose::Exporter::_late_curry_wrapper which was called 488 times, avg 41µs/call: # 488 times (19.8ms+0s) by Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:263] at line 255, avg 41µs/call
sub _late_curry_wrapper {
283390422.8ms my $class = shift;
284 my $sub = shift;
285 my $fq_name = shift;
286 my $extra = shift;
287 my @ex_args = @_;
288
289 my $wrapper = sub {
290
291 # resolve curried arguments at runtime via this closure
2923665.97ms1838.23ms my @curry = ( $extra->(@ex_args) );
# spent 8.23ms making 183 calls to Moose::Exporter::__ANON__[Moose/Exporter.pm:255], avg 45µs/call
293 return $sub->( @curry, @_ );
# spent 1.22s making 17 calls to Moose::with, avg 71.6ms/call # spent 867ms making 14 calls to Moose::extends, avg 61.9ms/call, recursion: max depth 2, time 202ms # spent 590ms making 92 calls to Moose::has, avg 6.41ms/call # spent 760ms making 11 calls to Moose::Role::with, avg 69.1ms/call, recursion: max depth 1, time 197ms # spent 18.1ms making 12 calls to Moose::around, avg 1.50ms/call # spent 6.00ms making 4 calls to Moose::before, avg 1.50ms/call # spent 4.24ms making 8 calls to Moose::Role::has, avg 530µs/call # spent 3.18ms making 13 calls to Moose::Role::around, avg 245µs/call # spent 2.21ms making 3 calls to Moose::Role::requires, avg 735µs/call # spent 1.22ms making 1 call to Moose::after # spent 585µs making 4 calls to Moose::Role::before, avg 146µs/call # spent 543µs making 2 calls to Moose::Role::override, avg 271µs/call # spent 314µs making 2 calls to Moose::Role::after, avg 157µs/call
294 };
295
296 if ( my $proto = prototype $sub ) {
297
298 # XXX - Perl's prototype sucks. Use & to make set_prototype
299 # ignore the fact that we're passing "private variables"
300 &Scalar::Util::set_prototype( $wrapper, $proto );
301 }
302 return $wrapper;
303}
304
305
# spent 292µs within Moose::Exporter::_make_import_sub which was called 7 times, avg 42µs/call: # 7 times (292µs+0s) by Moose::Exporter::build_import_methods at line 60, avg 42µs/call
sub _make_import_sub {
30642315µs shift;
307 my $exporting_package = shift;
308 my $exporter = shift;
309 my $exports_from = shift;
310 my $is_reexport = shift;
311
312
# spent 1.02s (16.0ms+1.00) within Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:389] which was called 68 times, avg 15.0ms/call: # once (166µs+171ms) by Catalyst::Controller::BEGIN@10 at line 10 of Catalyst/Controller.pm # once (186µs+134ms) by Catalyst::Exception::Basic::BEGIN@3 at line 3 of Catalyst/Exception/Basic.pm # once (283µs+21.0ms) by Catalyst::Exception::Interface::BEGIN@3 at line 3 of Catalyst/Exception/Interface.pm # once (279µs+17.2ms) by Catalyst::Exception::Detach::BEGIN@3 at line 3 of Catalyst/Exception/Detach.pm # once (242µs+16.6ms) by Catalyst::Engine::HTTP::BEGIN@3 at line 3 of Catalyst/Engine/HTTP.pm # once (216µs+16.4ms) by MooseX::MethodAttributes::Inheritable::BEGIN@9 at line 9 of MooseX/MethodAttributes/Inheritable.pm # once (281µs+16.2ms) by Catalyst::Controller::BEGIN@3 at line 3 of Catalyst/Controller.pm # once (359µs+15.8ms) by MooseX::Types::BEGIN@2 at line 2 of MooseX/Types.pm # once (273µs+15.6ms) by Catalyst::View::BEGIN@3 at line 3 of Catalyst/View.pm # once (215µs+14.6ms) by Catalyst::Component::BEGIN@3 at line 3 of Catalyst/Component.pm # once (538µs+14.2ms) by Catalyst::Plugin::Session::BEGIN@5 at line 5 of Catalyst/Plugin/Session.pm # once (271µs+14.4ms) by Catalyst::BEGIN@3 at line 3 of Catalyst.pm # once (434µs+14.2ms) by Catalyst::Action::BEGIN@22 at line 22 of Catalyst/Action.pm # once (448µs+14.2ms) by Catalyst::Exception::Base::BEGIN@47 at line 47 of Catalyst/Exception.pm # once (278µs+14.2ms) by Catalyst::Engine::BEGIN@3 at line 3 of Catalyst/Engine.pm # once (398µs+14.1ms) by Catalyst::DispatchType::Index::BEGIN@3 at line 3 of Catalyst/DispatchType/Index.pm # once (346µs+14.1ms) by Catalyst::Plugin::Session::State::Cookie::BEGIN@2 at line 2 of Catalyst/Plugin/Session/State/Cookie.pm # once (225µs+14.1ms) by Catalyst::Response::BEGIN@3 at line 3 of Catalyst/Response.pm # once (680µs+13.6ms) by Data::Visitor::BEGIN@4 at line 4 of Data/Visitor.pm # once (230µs+14.0ms) by Catalyst::Model::BEGIN@3 at line 3 of Catalyst/Model.pm # once (282µs+14.0ms) by Catalyst::DispatchType::Default::BEGIN@3 at line 3 of Catalyst/DispatchType/Default.pm # once (390µs+13.8ms) by Data::Visitor::Callback::BEGIN@4 at line 4 of Data/Visitor/Callback.pm # once (214µs+13.8ms) by Catalyst::ActionContainer::BEGIN@18 at line 18 of Catalyst/ActionContainer.pm # once (334µs+13.7ms) by Catalyst::Exception::BEGIN@58 at line 58 of Catalyst/Exception.pm # once (281µs+13.8ms) by Catalyst::Dispatcher::BEGIN@3 at line 3 of Catalyst/Dispatcher.pm # once (207µs+13.5ms) by Catalyst::DispatchType::BEGIN@3 at line 3 of Catalyst/DispatchType.pm # once (262µs+13.5ms) by Catalyst::Stats::BEGIN@3 at line 3 of Catalyst/Stats.pm # once (261µs+13.0ms) by Catalyst::Request::Upload::BEGIN@3 at line 3 of Catalyst/Request/Upload.pm # once (221µs+11.5ms) by Catalyst::ClassData::BEGIN@3 at line 3 of Catalyst/ClassData.pm # once (227µs+11.3ms) by MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute::BEGIN@2 at line 2 of MooseX/Emulate/Class/Accessor/Fast/Meta/Role/Attribute.pm # once (221µs+11.2ms) by MooseX::MethodAttributes::Role::Meta::Method::MaybeWrapped::BEGIN@5 at line 5 of MooseX/MethodAttributes/Role/Meta/Method/MaybeWrapped.pm # once (221µs+11.0ms) by MooseX::Role::WithOverloading::Meta::Role::Application::Composite::ToClass::BEGIN@5 at line 5 of MooseX/Role/WithOverloading/Meta/Role/Application/Composite/ToClass.pm # once (278µs+10.9ms) by MooseX::MethodAttributes::Role::Meta::Method::Wrapped::BEGIN@5 at line 5 of MooseX/MethodAttributes/Role/Meta/Method/Wrapped.pm # once (401µs+10.7ms) by MooseX::MethodAttributes::Role::Meta::Class::BEGIN@5 at line 5 of MooseX/MethodAttributes/Role/Meta/Class.pm # once (232µs+10.5ms) by MooseX::MethodAttributes::Role::AttrContainer::Inheritable::BEGIN@6 at line 6 of MooseX/MethodAttributes/Role/AttrContainer/Inheritable.pm # once (216µs+10.5ms) by MooseX::Role::WithOverloading::Meta::Role::Application::Composite::BEGIN@5 at line 5 of MooseX/Role/WithOverloading/Meta/Role/Application/Composite.pm # once (223µs+10.2ms) by MooseX::Role::WithOverloading::Meta::Role::Application::ToRole::BEGIN@5 at line 5 of MooseX/Role/WithOverloading/Meta/Role/Application/ToRole.pm # once (222µs+10.1ms) by MooseX::MethodAttributes::Role::Meta::Role::BEGIN@10 at line 10 of MooseX/MethodAttributes/Role/Meta/Role.pm # once (120µs+10.2ms) by MooseX::Emulate::Class::Accessor::Fast::BEGIN@3 at line 3 of MooseX/Emulate/Class/Accessor/Fast.pm # once (219µs+10.1ms) by MooseX::MethodAttributes::Role::Meta::Map::BEGIN@5 at line 5 of MooseX/MethodAttributes/Role/Meta/Map.pm # once (226µs+9.85ms) by Catalyst::Plugin::Static::Simple::BEGIN@3 at line 3 of Catalyst/Plugin/Static/Simple.pm # once (272µs+9.80ms) by MooseX::MethodAttributes::Role::AttrContainer::BEGIN@5 at line 5 of MooseX/MethodAttributes/Role/AttrContainer.pm # once (224µs+9.80ms) by MooseX::Role::WithOverloading::Meta::Role::Application::ToInstance::BEGIN@5 at line 5 of MooseX/Role/WithOverloading/Meta/Role/Application/ToInstance.pm # once (286µs+9.64ms) by MooseX::Role::WithOverloading::Meta::Role::Application::Composite::ToInstance::BEGIN@5 at line 5 of MooseX/Role/WithOverloading/Meta/Role/Application/Composite/ToInstance.pm # once (240µs+9.68ms) by MooseX::MethodAttributes::Role::Meta::Role::Application::BEGIN@5 at line 5 of MooseX/MethodAttributes/Role/Meta/Role/Application.pm # once (273µs+9.61ms) by MooseX::Role::WithOverloading::Meta::Role::Application::ToClass::BEGIN@5 at line 5 of MooseX/Role/WithOverloading/Meta/Role/Application/ToClass.pm # once (224µs+9.59ms) by MooseX::Role::WithOverloading::Meta::Role::Application::FixOverloadedRefs::BEGIN@4 at line 4 of MooseX/Role/WithOverloading/Meta/Role/Application/FixOverloadedRefs.pm # once (189µs+9.04ms) by Catalyst::Log::BEGIN@3 at line 3 of Catalyst/Log.pm # once (121µs+8.16ms) by MooseX::Emulate::Class::Accessor::Fast::Meta::Accessor::BEGIN@3 at line 3 of MooseX/Emulate/Class/Accessor/Fast/Meta/Accessor.pm # once (291µs+7.80ms) by Moose::BEGIN@34 at line 34 of Moose.pm # once (163µs+7.45ms) by MooseX::Types::BEGIN@10 at line 10 of MooseX/Types.pm # once (176µs+7.12ms) by MooseX::Role::WithOverloading::Meta::Role::Composite::BEGIN@5 at line 5 of MooseX/Role/WithOverloading/Meta/Role/Composite.pm # once (130µs+6.92ms) by Catalyst::Engine::CGI::BEGIN@3 at line 3 of Catalyst/Engine/CGI.pm # once (115µs+6.64ms) by Catalyst::Exception::Go::BEGIN@3 at line 3 of Catalyst/Exception/Go.pm # once (117µs+6.56ms) by MooseX::Types::Base::BEGIN@3 at line 3 of MooseX/Types/Base.pm # once (150µs+6.31ms) by MooseX::MethodAttributes::Role::Meta::Method::BEGIN@5 at line 5 of MooseX/MethodAttributes/Role/Meta/Method.pm # once (122µs+6.30ms) by Catalyst::Request::BEGIN@11 at line 11 of Catalyst/Request.pm # once (108µs+6.13ms) by Catalyst::DispatchType::Path::BEGIN@3 at line 3 of Catalyst/DispatchType/Path.pm # once (121µs+5.68ms) by MooseX::Role::WithOverloading::Meta::Role::Application::Composite::ToRole::BEGIN@5 at line 5 of MooseX/Role/WithOverloading/Meta/Role/Application/Composite/ToRole.pm # once (170µs+5.53ms) by Catalyst::DispatchType::Regex::BEGIN@3 at line 3 of Catalyst/DispatchType/Regex.pm # once (223µs+5.19ms) by Catalyst::Component::ApplicationAttribute::BEGIN@3 at line 3 of Catalyst/Component/ApplicationAttribute.pm # once (111µs+4.43ms) by MooseX::Role::WithOverloading::Meta::Role::BEGIN@6 at line 6 of MooseX/Role/WithOverloading/Meta/Role.pm # once (154µs+4.30ms) by Catalyst::Dispatcher::BEGIN@693 at line 693 of Catalyst/Dispatcher.pm # once (139µs+4.04ms) by MooseX::Role::WithOverloading::Meta::Role::Application::BEGIN@5 at line 5 of MooseX/Role/WithOverloading/Meta/Role/Application.pm # once (81µs+3.56ms) by Moose::Role::BEGIN@19 at line 19 of Moose/Role.pm # once (76µs+3.30ms) by MooseX::Types::import at line 362 of MooseX/Types.pm # once (78µs+3.27ms) by MooseX::Types::Base::BEGIN@14 at line 14 of MooseX/Types/Base.pm # once (73µs+3.15ms) by MooseX::Types::import at line 365 of MooseX/Types.pm
return sub {
313
314 # I think we could use Sub::Exporter's collector feature
315 # to do this, but that would be rather gross, since that
316 # feature isn't really designed to return a value to the
317 # caller of the exporter sub.
318 #
319 # Also, this makes sure we preserve backwards compat for
320 # _get_caller, so it always sees the arguments in the
321 # expected order.
322174016.3ms my $traits;
323 ( $traits, @_ ) = _strip_traits(@_);
# spent 4.25ms making 68 calls to Moose::Exporter::_strip_traits, avg 63µs/call
324
325 my $metaclass;
326 ( $metaclass, @_ ) = _strip_metaclass(@_);
# spent 2.39ms making 68 calls to Moose::Exporter::_strip_metaclass, avg 35µs/call
327 $metaclass
328 = Moose::Util::resolve_metaclass_alias( 'Class' => $metaclass )
329 if defined $metaclass && length $metaclass;
330
331 # Normally we could look at $_[0], but in some weird cases
332 # (involving goto &Moose::import), $_[0] ends as something
333 # else (like Squirrel).
334 my $class = $exporting_package;
335
336 $CALLER = _get_caller(@_);
# spent 1.07ms making 68 calls to Moose::Exporter::_get_caller, avg 16µs/call
337
338 # this works because both pragmas set $^H (see perldoc
339 # perlvar) which affects the current compilation -
340 # i.e. the file who use'd us - which is why we don't need
341 # to do anything special to make it affect that file
342 # rather than this one (which is already compiled)
343
344 strict->import;
# spent 1.04ms making 68 calls to strict::import, avg 15µs/call
345 warnings->import;
# spent 3.90ms making 68 calls to warnings::import, avg 57µs/call
346
347 my $did_init_meta;
348 for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) {
# spent 639µs making 70 calls to UNIVERSAL::can, avg 9µs/call
349
350 # init_meta can apply a role, which when loaded uses
351 # Moose::Exporter, which in turn sets $CALLER, so we need
352 # to protect against that.
353 local $CALLER = $CALLER;
354157µs66567ms $c->init_meta( for_class => $CALLER, metaclass => $metaclass );
# spent 209ms making 34 calls to Moose::init_meta, avg 6.14ms/call # spent 170ms making 1 call to MooseX::MethodAttributes::init_meta # spent 142ms making 2 calls to MooseX::Role::WithOverloading::init_meta, avg 71.1ms/call # spent 45.6ms making 27 calls to Moose::Role::init_meta, avg 1.69ms/call # spent 186µs making 2 calls to Moose::Meta::Role::DESTROY, avg 93µs/call
355 $did_init_meta = 1;
356 }
357
358 if ( $did_init_meta && @{$traits} ) {
359
360 # The traits will use Moose::Role, which in turn uses
361 # Moose::Exporter, which in turn sets $CALLER, so we need
362 # to protect against that.
363 local $CALLER = $CALLER;
364 _apply_meta_traits( $CALLER, $traits );
365 }
366 elsif ( @{$traits} ) {
367 require Moose;
368 Moose->throw_error(
369 "Cannot provide traits when $class does not have an init_meta() method"
370 );
371 }
372
373 my ( undef, @args ) = @_;
374 my $extra = shift @args if ref $args[0] eq 'HASH';
375
376 $extra ||= {};
377 if ( !$extra->{into} ) {
378 $extra->{into_level} ||= 0;
379 $extra->{into_level}++;
380 }
381
382 $class->$exporter( $extra, @args );
# spent 424ms making 68 calls to Sub::Exporter::__ANON__[Sub/Exporter.pm:756], avg 6.24ms/call
383
384 for my $name ( keys %{$is_reexport} ) {
385399µs2139µs
# spent 87µs (35+52) within Moose::Exporter::BEGIN@385 which was called # once (35µs+52µs) by Moose::BEGIN@14 at line 385
no strict 'refs';
# spent 87µs making 1 call to Moose::Exporter::BEGIN@385 # spent 52µs making 1 call to strict::unimport
38632.70ms2147µs
# spent 90µs (34+57) within Moose::Exporter::BEGIN@386 which was called # once (34µs+57µs) by Moose::BEGIN@14 at line 386
no warnings 'once';
# spent 90µs making 1 call to Moose::Exporter::BEGIN@386 # spent 57µs making 1 call to warnings::unimport
387 _flag_as_reexport( \*{ join q{::}, $CALLER, $name } );
# spent 785µs making 122 calls to Moose::Exporter::_flag_as_reexport, avg 6µs/call
388 }
389 };
390}
391
392
# spent 4.25ms (2.76+1.49) within Moose::Exporter::_strip_traits which was called 68 times, avg 63µs/call: # 68 times (2.76ms+1.49ms) by Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:389] at line 323, avg 63µs/call
sub _strip_traits {
3932064.56ms681.49ms my $idx = first_index { $_ eq '-traits' } @_;
# spent 1.49ms making 68 calls to List::MoreUtils::firstidx, avg 22µs/call
394
395 return ( [], @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
396
397 my $traits = $_[ $idx + 1 ];
398
399 splice @_, $idx, 2;
400
401 $traits = [$traits] unless ref $traits;
402
403 return ( $traits, @_ );
404}
405
406
# spent 2.39ms (1.71+677µs) within Moose::Exporter::_strip_metaclass which was called 68 times, avg 35µs/call: # 68 times (1.71ms+677µs) by Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:389] at line 326, avg 35µs/call
sub _strip_metaclass {
4072062.52ms68677µs my $idx = first_index { $_ eq '-metaclass' } @_;
# spent 677µs making 68 calls to List::MoreUtils::firstidx, avg 10µs/call
408
409 return ( undef, @_ ) unless $idx >= 0 && $#_ >= $idx + 1;
410
411 my $metaclass = $_[ $idx + 1 ];
412
413 splice @_, $idx, 2;
414
415 return ( $metaclass, @_ );
416}
417
418sub _apply_meta_traits {
419 my ( $class, $traits ) = @_;
420
421 return unless @{$traits};
422
423 my $meta = Class::MOP::class_of($class);
424
425 my $type = ( split /::/, ref $meta )[-1]
426 or Moose->throw_error(
427 'Cannot determine metaclass type for trait application . Meta isa '
428 . ref $meta );
429
430 my @resolved_traits = map {
431 ref $_
432 ? $_
433 : Moose::Util::resolve_metatrait_alias( $type => $_ )
434 } @$traits;
435
436 return unless @resolved_traits;
437
438 my %args = ( for => $class );
439
440 if ( $meta->isa('Moose::Meta::Role') ) {
441 $args{role_metaroles} = { role => \@resolved_traits };
442 }
443 else {
444 $args{class_metaroles} = { class => \@resolved_traits };
445 }
446
447 Moose::Util::MetaRole::apply_metaroles(%args);
448}
449
450
# spent 1.07ms within Moose::Exporter::_get_caller which was called 68 times, avg 16µs/call: # 68 times (1.07ms+0s) by Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:389] at line 336, avg 16µs/call
sub _get_caller {
451
452 # 1 extra level because it's called by import so there's a layer
453 # of indirection
4541361.14ms my $offset = 1;
455
456 return
457 ( ref $_[1] && defined $_[1]->{into} ) ? $_[1]->{into}
458 : ( ref $_[1] && defined $_[1]->{into_level} )
459 ? caller( $offset + $_[1]->{into_level} )
460 : caller($offset);
461}
462
463
# spent 141µs within Moose::Exporter::_make_unimport_sub which was called 7 times, avg 20µs/call: # 7 times (141µs+0s) by Moose::Exporter::build_import_methods at line 67, avg 20µs/call
sub _make_unimport_sub {
46442198µs shift;
465 my $exporting_package = shift;
466 my $exports = shift;
467 my $export_recorder = shift;
468 my $is_reexport = shift;
469
470
# spent 5.79ms (600µs+5.19) within Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:478] which was called 13 times, avg 446µs/call: # once (103µs+662µs) by Catalyst::Response::BEGIN@38 at line 38 of Catalyst/Response.pm # once (152µs+488µs) by Catalyst::ActionContainer::BEGIN@30 at line 30 of Catalyst/ActionContainer.pm # once (39µs+596µs) by Catalyst::Request::Upload::BEGIN@45 at line 45 of Catalyst/Request/Upload.pm # once (32µs+504µs) by Catalyst::DispatchType::Default::BEGIN@6 at line 6 of Catalyst/DispatchType/Default.pm # once (37µs+461µs) by Catalyst::Engine::CGI::BEGIN@291 at line 291 of Catalyst/Engine/CGI.pm # once (38µs+457µs) by Catalyst::View::BEGIN@60 at line 60 of Catalyst/View.pm # once (33µs+438µs) by Catalyst::Model::BEGIN@6 at line 6 of Catalyst/Model.pm # once (33µs+434µs) by Catalyst::DispatchType::BEGIN@5 at line 5 of Catalyst/DispatchType.pm # once (18µs+283µs) by Catalyst::DispatchType::Path::BEGIN@17 at line 17 of Catalyst/DispatchType/Path.pm # once (37µs+240µs) by MooseX::Emulate::Class::Accessor::Fast::Meta::Accessor::BEGIN@48 at line 48 of MooseX/Emulate/Class/Accessor/Fast/Meta/Accessor.pm # once (35µs+217µs) by Catalyst::Log::BEGIN@126 at line 126 of Catalyst/Log.pm # once (20µs+211µs) by Catalyst::DispatchType::Regex::BEGIN@17 at line 17 of Catalyst/DispatchType/Regex.pm # once (24µs+199µs) by Catalyst::BEGIN@3195 at line 3195 of Catalyst.pm
return sub {
47126610µs my $caller = scalar caller();
472 Moose::Exporter->_remove_keywords(
473 $caller,
474 [ keys %{$exports} ],
# spent 5.19ms making 13 calls to Moose::Exporter::_remove_keywords, avg 399µs/call
475 $export_recorder,
476 $is_reexport,
477 );
478 };
479}
480
481
# spent 5.19ms (5.06+134µs) within Moose::Exporter::_remove_keywords which was called 13 times, avg 399µs/call: # 13 times (5.06ms+134µs) by Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:478] at line 474, avg 399µs/call
sub _remove_keywords {
4828845.26ms shift;
483 my $package = shift;
484 my $keywords = shift;
485 my $recorded_exports = shift;
486 my $is_reexport = shift;
487
4883292µs2133µs
# spent 82µs (31+51) within Moose::Exporter::BEGIN@488 which was called # once (31µs+51µs) by Moose::BEGIN@14 at line 488
no strict 'refs';
# spent 82µs making 1 call to Moose::Exporter::BEGIN@488 # spent 51µs making 1 call to strict::unimport
489
490 foreach my $name ( @{$keywords} ) {
491 if ( defined &{ $package . '::' . $name } ) {
492 my $sub = \&{ $package . '::' . $name };
493
494 # make sure it is from us
495 next unless $recorded_exports->{$sub};
496
497 if ( $is_reexport->{$name} ) {
49831.11ms2115µs
# spent 72µs (28+43) within Moose::Exporter::BEGIN@498 which was called # once (28µs+43µs) by Moose::BEGIN@14 at line 498
no strict 'refs';
# spent 72µs making 1 call to Moose::Exporter::BEGIN@498 # spent 44µs making 1 call to strict::unimport
499 next
500 unless _export_is_flagged(
501 \*{ join q{::} => $package, $name } );
# spent 134µs making 26 calls to Moose::Exporter::_export_is_flagged, avg 5µs/call
502 }
503
504 # and if it is from us, then undef the slot
505 delete ${ $package . '::' }{$name};
506 }
507 }
508}
509
510
# spent 490µs within Moose::Exporter::_make_init_meta which was called 7 times, avg 70µs/call: # 7 times (490µs+0s) by Moose::Exporter::build_import_methods at line 74, avg 70µs/call
sub _make_init_meta {
511119511µs shift;
512 my $class = shift;
513 my $args = shift;
514
515 my %old_style_roles;
516 for my $role (
517 map {"${_}_roles"}
518 qw(
519 metaclass
520 attribute_metaclass
521 method_metaclass
522 wrapped_method_metaclass
523 instance_metaclass
524 constructor_class
525 destructor_class
526 error_class
527 )
528 ) {
529 $old_style_roles{$role} = $args->{$role}
530 if exists $args->{$role};
531 }
532
533 my %base_class_roles;
534 %base_class_roles = ( roles => $args->{base_class_roles} )
535 if exists $args->{base_class_roles};
536
537 my %new_style_roles = map { $_ => $args->{$_} }
538 grep { exists $args->{$_} } qw( class_metaroles role_metaroles );
539
540 return unless %new_style_roles || %old_style_roles || %base_class_roles;
541
542 return sub {
543 shift;
544 my %options = @_;
545
546 return unless Class::MOP::class_of( $options{for_class} );
547
548 Moose::Util::MetaRole::apply_metaroles(
549 for => $options{for_class},
550 %new_style_roles,
551 %old_style_roles,
552 );
553
554 Moose::Util::MetaRole::apply_base_class_roles(
555 for_class => $options{for_class},
556 %base_class_roles,
557 )
558 if Class::MOP::class_of( $options{for_class} )
559 ->isa('Moose::Meta::Class');
560
561 return Class::MOP::class_of( $options{for_class} );
562 };
563}
564
565
# spent 1000µs (340+660) within Moose::Exporter::import which was called 7 times, avg 143µs/call: # once (88µs+229µs) by MooseX::Role::WithOverloading::BEGIN@7 at line 7 of MooseX/Role/WithOverloading.pm # once (123µs+62µs) by MooseX::MethodAttributes::Role::BEGIN@9 at line 9 of MooseX/MethodAttributes/Role.pm # once (30µs+138µs) by MooseX::MethodAttributes::BEGIN@9 at line 9 of MooseX/MethodAttributes.pm # once (33µs+76µs) by Moose::Util::TypeConstraints::BEGIN@7 at line 7 of Moose/Util/TypeConstraints.pm # once (34µs+64µs) by Moose::BEGIN@14 at line 14 of Moose.pm # once (16µs+58µs) by MooseX::Types::CheckedUtilExports::BEGIN@14 at line 14 of MooseX/Types/CheckedUtilExports.pm # once (16µs+32µs) by Moose::Role::BEGIN@17 at line 17 of Moose/Role.pm
sub import {
56614155µs762µs strict->import;
# spent 62µs making 7 calls to strict::import, avg 9µs/call
567 warnings->import;
# spent 598µs making 7 calls to warnings::import, avg 85µs/call
568}
569
570120µs1;
571
572__END__
573
574=head1 NAME
575
576Moose::Exporter - make an import() and unimport() just like Moose.pm
577
578=head1 SYNOPSIS
579
580 package MyApp::Moose;
581
582 use Moose ();
583 use Moose::Exporter;
584
585 Moose::Exporter->setup_import_methods(
586 with_meta => [ 'has_rw', 'sugar2' ],
587 as_is => [ 'sugar3', \&Some::Random::thing ],
588 also => 'Moose',
589 );
590
591 sub has_rw {
592 my ( $meta, $name, %options ) = @_;
593 $meta->add_attribute(
594 $name,
595 is => 'rw',
596 %options,
597 );
598 }
599
600 # then later ...
601 package MyApp::User;
602
603 use MyApp::Moose;
604
605 has 'name';
606 has_rw 'size';
607 thing;
608
609 no MyApp::Moose;
610
611=head1 DESCRIPTION
612
613This module encapsulates the exporting of sugar functions in a
614C<Moose.pm>-like manner. It does this by building custom C<import>,
615C<unimport>, and C<init_meta> methods for your module, based on a spec you
616provide.
617
618It also lets you "stack" Moose-alike modules so you can export Moose's sugar
619as well as your own, along with sugar from any random C<MooseX> module, as
620long as they all use C<Moose::Exporter>. This feature exists to let you bundle
621a set of MooseX modules into a policy module that developers can use directly
622instead of using Moose itself.
623
624To simplify writing exporter modules, C<Moose::Exporter> also imports
625C<strict> and C<warnings> into your exporter module, as well as into
626modules that use it.
627
628=head1 METHODS
629
630This module provides two public methods:
631
632=over 4
633
634=item B<< Moose::Exporter->setup_import_methods(...) >>
635
636When you call this method, C<Moose::Exporter> builds custom C<import>,
637C<unimport>, and C<init_meta> methods for your module. The C<import> method
638will export the functions you specify, and can also re-export functions
639exported by some other module (like C<Moose.pm>).
640
641The C<unimport> method cleans the caller's namespace of all the exported
642functions. This includes any functions you re-export from other
643packages. However, if the consumer of your package also imports those
644functions from the original package, they will I<not> be cleaned.
645
646If you pass any parameters for L<Moose::Util::MetaRole>, this method will
647generate an C<init_meta> for you as well (see below for details). This
648C<init_meta> will call C<Moose::Util::MetaRole::apply_metaclass_roles> and
649C<Moose::Util::MetaRole::apply_base_class_roles> as needed.
650
651Note that if any of these methods already exist, they will not be
652overridden, you will have to use C<build_import_methods> to get the
653coderef that would be installed.
654
655This method accepts the following parameters:
656
657=over 8
658
659=item * with_meta => [ ... ]
660
661This list of function I<names only> will be wrapped and then exported. The
662wrapper will pass the metaclass object for the caller as its first argument.
663
664Many sugar functions will need to use this metaclass object to do something to
665the calling package.
666
667=item * as_is => [ ... ]
668
669This list of function names or sub references will be exported as-is. You can
670identify a subroutine by reference, which is handy to re-export some other
671module's functions directly by reference (C<\&Some::Package::function>).
672
673If you do export some other package's function, this function will never be
674removed by the C<unimport> method. The reason for this is we cannot know if
675the caller I<also> explicitly imported the sub themselves, and therefore wants
676to keep it.
677
678=item * also => $name or \@names
679
680This is a list of modules which contain functions that the caller
681wants to export. These modules must also use C<Moose::Exporter>. The
682most common use case will be to export the functions from C<Moose.pm>.
683Functions specified by C<with_meta> or C<as_is> take precedence over
684functions exported by modules specified by C<also>, so that a module
685can selectively override functions exported by another module.
686
687C<Moose::Exporter> also makes sure all these functions get removed
688when C<unimport> is called.
689
690=back
691
692You can also provide parameters for C<Moose::Util::MetaRole::apply_metaroles>
693and C<Moose::Util::MetaRole::base_class_roles>. Specifically, valid parameters
694are "class_metaroles", "role_metaroles", and "base_object_roles".
695
696=item B<< Moose::Exporter->build_import_methods(...) >>
697
698Returns two or three code refs, one for C<import>, one for
699C<unimport>, and optionally one for C<init_meta>, if the appropriate
700options are passed in.
701
702Accepts the additional C<install> option, which accepts an arrayref of method
703names to install into your exporting package. The valid options are C<import>,
704C<unimport>, and C<init_meta>. Calling C<setup_import_methods> is equivalent
705to calling C<build_import_methods> with C<< install => [qw(import unimport
706init_meta)] >> except that it doesn't also return the methods.
707
708Used by C<setup_import_methods>.
709
710=back
711
712=head1 IMPORTING AND init_meta
713
714If you want to set an alternative base object class or metaclass class, see
715above for details on how this module can call L<Moose::Util::MetaRole> for
716you.
717
718If you want to do something that is not supported by this module, simply
719define an C<init_meta> method in your class. The C<import> method that
720C<Moose::Exporter> generates for you will call this method (if it exists). It
721will always pass the caller to this method via the C<for_class> parameter.
722
723Most of the time, your C<init_meta> method will probably just call C<<
724Moose->init_meta >> to do the real work:
725
726 sub init_meta {
727 shift; # our class name
728 return Moose->init_meta( @_, metaclass => 'My::Metaclass' );
729 }
730
731Keep in mind that C<build_import_methods> will return an C<init_meta>
732method for you, which you can also call from within your custom
733C<init_meta>:
734
735 my ( $import, $unimport, $init_meta ) =
736 Moose::Exporter->build_import_methods( ... );
737
738 sub import {
739 my $class = shift;
740
741 ...
742
743 $class->$import(...);
744
745 ...
746 }
747
748 sub unimport { goto &$unimport }
749
750 sub init_meta {
751 my $class = shift;
752
753 ...
754
755 $class->$init_meta(...);
756
757 ...
758 }
759
760=head1 METACLASS TRAITS
761
762The C<import> method generated by C<Moose::Exporter> will allow the
763user of your module to specify metaclass traits in a C<-traits>
764parameter passed as part of the import:
765
766 use Moose -traits => 'My::Meta::Trait';
767
768 use Moose -traits => [ 'My::Meta::Trait', 'My::Other::Trait' ];
769
770These traits will be applied to the caller's metaclass
771instance. Providing traits for an exporting class that does not create
772a metaclass for the caller is an error.
773
774=head1 BUGS
775
776See L<Moose/BUGS> for details on reporting bugs.
777
778=head1 AUTHOR
779
780Dave Rolsky E<lt>autarch@urth.orgE<gt>
781
782This is largely a reworking of code in Moose.pm originally written by
783Stevan Little and others.
784
785=head1 COPYRIGHT AND LICENSE
786
787Copyright 2009 by Infinity Interactive, Inc.
788
789L<http://www.iinteractive.com>
790
791This library is free software; you can redistribute it and/or modify
792it under the same terms as Perl itself.
793
794=cut
# spent 134µs within Moose::Exporter::_export_is_flagged which was called 26 times, avg 5µs/call: # 26 times (134µs+0s) by Moose::Exporter::_remove_keywords at line 501 of Moose/Exporter.pm, avg 5µs/call
sub Moose::Exporter::_export_is_flagged; # xsub
# spent 785µs within Moose::Exporter::_flag_as_reexport which was called 122 times, avg 6µs/call: # 122 times (785µs+0s) by Moose::Exporter::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Exporter.pm:389] at line 387 of Moose/Exporter.pm, avg 6µs/call
sub Moose::Exporter::_flag_as_reexport; # xsub