| File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm |
| Statements Executed | 827 |
| Statement Execution Time | 6.59ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 8.56ms | 9.28ms | Moose::Exporter::BEGIN@12 |
| 1 | 1 | 1 | 4.99ms | 156ms | Moose::Exporter::BEGIN@11 |
| 1 | 1 | 1 | 2.25ms | 2.45ms | Moose::Exporter::BEGIN@13 |
| 2 | 1 | 1 | 217µs | 343µs | Moose::Exporter::_make_sub_exporter_params |
| 2 | 1 | 1 | 138µs | 1.60ms | Moose::Exporter::build_import_methods |
| 1 | 1 | 1 | 132µs | 139µs | Moose::Exporter::_remove_keywords |
| 2 | 2 | 2 | 129µs | 4.15ms | Moose::Exporter::__ANON__[:389] |
| 27 | 2 | 1 | 84µs | 84µs | Moose::Exporter::_sub_from_package |
| 8 | 1 | 1 | 82µs | 146µs | Moose::Exporter::__ANON__[:263] |
| 8 | 1 | 1 | 50µs | 50µs | Moose::Exporter::_late_curry_wrapper |
| 8 | 1 | 1 | 39µs | 39µs | Moose::Exporter::_make_wrapped_sub_with_meta |
| 2 | 1 | 1 | 36µs | 36µs | Moose::Exporter::_make_init_meta |
| 21 | 1 | 1 | 35µs | 35µs | Moose::Exporter::__ANON__[:193] |
| 2 | 1 | 1 | 31µs | 56µs | Moose::Exporter::_strip_traits |
| 2 | 1 | 1 | 30µs | 67µs | Moose::Exporter::_follow_also |
| 2 | 2 | 2 | 29µs | 1.63ms | Moose::Exporter::setup_import_methods |
| 2 | 1 | 1 | 20µs | 20µs | Moose::Exporter::_make_import_sub |
| 2 | 1 | 1 | 18µs | 21µs | Moose::Exporter::_strip_metaclass |
| 1 | 1 | 1 | 18µs | 157µs | Moose::Exporter::__ANON__[:478] |
| 4 | 1 | 1 | 17µs | 47µs | Moose::Exporter::__ANON__[:255] |
| 2 | 2 | 2 | 17µs | 41µs | Moose::Exporter::import |
| 1 | 1 | 1 | 16µs | 206µs | Moose::Exporter::BEGIN@14 |
| 2 | 1 | 1 | 14µs | 14µs | Moose::Exporter::_make_unimport_sub |
| 1 | 1 | 1 | 13µs | 16µs | Moose::Exporter::BEGIN@3 |
| 2 | 1 | 1 | 12µs | 12µs | Moose::Exporter::_follow_also_real |
| 2 | 1 | 2 | 10µs | 10µs | Moose::Exporter::_flag_as_reexport (xsub) |
| 2 | 1 | 1 | 10µs | 10µs | Moose::Exporter::_get_caller |
| 1 | 1 | 1 | 9µs | 26µs | Moose::Exporter::BEGIN@386 |
| 1 | 1 | 1 | 9µs | 26µs | Moose::Exporter::BEGIN@206 |
| 1 | 1 | 1 | 8µs | 33µs | Moose::Exporter::BEGIN@15 |
| 1 | 1 | 1 | 7µs | 18µs | Moose::Exporter::BEGIN@488 |
| 2 | 1 | 2 | 7µs | 7µs | Moose::Exporter::_export_is_flagged (xsub) |
| 1 | 1 | 1 | 7µs | 18µs | Moose::Exporter::BEGIN@385 |
| 1 | 1 | 1 | 6µs | 16µs | Moose::Exporter::BEGIN@4 |
| 1 | 1 | 1 | 6µs | 16µs | Moose::Exporter::BEGIN@498 |
| 1 | 1 | 1 | 6µs | 6µs | Moose::Exporter::BEGIN@17 |
| 0 | 0 | 0 | 0s | 0s | Moose::Exporter::__ANON__[:241] |
| 0 | 0 | 0 | 0s | 0s | Moose::Exporter::__ANON__[:272] |
| 0 | 0 | 0 | 0s | 0s | Moose::Exporter::__ANON__[:294] |
| 0 | 0 | 0 | 0s | 0s | Moose::Exporter::__ANON__[:393] |
| 0 | 0 | 0 | 0s | 0s | Moose::Exporter::__ANON__[:407] |
| 0 | 0 | 0 | 0s | 0s | Moose::Exporter::__ANON__[:562] |
| 0 | 0 | 0 | 0s | 0s | Moose::Exporter::_apply_meta_traits |
| 0 | 0 | 0 | 0s | 0s | Moose::Exporter::_curry_wrapper |
| 0 | 0 | 0 | 0s | 0s | Moose::Exporter::_make_wrapped_sub |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Exporter; | ||||
| 2 | |||||
| 3 | 3 | 20µs | 2 | 19µs | # spent 16µs (13+3) within Moose::Exporter::BEGIN@3 which was called
# once (13µs+3µs) by Moose::BEGIN@14 at line 3 # spent 16µs making 1 call to Moose::Exporter::BEGIN@3
# spent 3µs making 1 call to strict::import |
| 4 | 3 | 52µs | 2 | 26µs | # spent 16µs (6+10) within Moose::Exporter::BEGIN@4 which was called
# once (6µs+10µs) by Moose::BEGIN@14 at line 4 # spent 16µs making 1 call to Moose::Exporter::BEGIN@4
# spent 10µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 1 | 3µs | our $VERSION = '0.98'; | ||
| 7 | 1 | 500ns | our $XS_VERSION = $VERSION; | ||
| 8 | 1 | 53µs | $VERSION = eval $VERSION; | ||
| 9 | 1 | 2µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 10 | |||||
| 11 | 3 | 144µs | 1 | 156ms | # spent 156ms (4.99+151) within Moose::Exporter::BEGIN@11 which was called
# once (4.99ms+151ms) by Moose::BEGIN@14 at line 11 # spent 156ms making 1 call to Moose::Exporter::BEGIN@11 |
| 12 | 3 | 139µs | 2 | 9.38ms | # spent 9.28ms (8.56+724µs) within Moose::Exporter::BEGIN@12 which was called
# once (8.56ms+724µs) by Moose::BEGIN@14 at line 12 # spent 9.28ms making 1 call to Moose::Exporter::BEGIN@12
# spent 106µs making 1 call to Exporter::import |
| 13 | 3 | 1.67ms | 1 | 2.45ms | # spent 2.45ms (2.25+202µs) within Moose::Exporter::BEGIN@13 which was called
# once (2.25ms+202µs) by Moose::BEGIN@14 at line 13 # spent 2.45ms making 1 call to Moose::Exporter::BEGIN@13 |
| 14 | 3 | 55µs | 3 | 396µs | # spent 206µs (16+190) within Moose::Exporter::BEGIN@14 which was called
# once (16µs+190µs) by Moose::BEGIN@14 at line 14 # spent 206µs making 1 call to Moose::Exporter::BEGIN@14
# spent 173µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
# spent 17µs making 1 call to UNIVERSAL::VERSION |
| 15 | 3 | 21µs | 2 | 58µs | # spent 33µs (8+25) within Moose::Exporter::BEGIN@15 which was called
# once (8µs+25µs) by Moose::BEGIN@14 at line 15 # spent 33µs making 1 call to Moose::Exporter::BEGIN@15
# spent 25µs making 1 call to Exporter::import |
| 16 | |||||
| 17 | 3 | 553µs | 1 | 6µs | # spent 6µs within Moose::Exporter::BEGIN@17 which was called
# once (6µs+0s) by Moose::BEGIN@14 at line 17 # spent 6µs making 1 call to Moose::Exporter::BEGIN@17 |
| 18 | |||||
| 19 | 1 | 101µs | 1 | 93µs | XSLoader::load( 'Moose', $XS_VERSION ); # spent 93µs making 1 call to XSLoader::load |
| 20 | |||||
| 21 | 1 | 200ns | my %EXPORT_SPEC; | ||
| 22 | |||||
| 23 | # spent 1.63ms (29µs+1.60) within Moose::Exporter::setup_import_methods which was called 2 times, avg 816µs/call:
# once (15µs+863µs) by Moose::Meta::Attribute::BEGIN@18 at line 41 of Moose/Util/TypeConstraints.pm
# once (14µs+740µs) by SimpleDB::Client::BEGIN@46 at line 121 of Moose.pm | ||||
| 24 | 2 | 6µs | my ( $class, %args ) = @_; | ||
| 25 | |||||
| 26 | 2 | 4µs | my $exporting_package = $args{exporting_package} ||= caller(); | ||
| 27 | |||||
| 28 | 2 | 17µs | 2 | 1.60ms | $class->build_import_methods( # spent 1.60ms making 2 calls to Moose::Exporter::build_import_methods, avg 802µs/call |
| 29 | %args, | ||||
| 30 | install => [qw(import unimport init_meta)] | ||||
| 31 | ); | ||||
| 32 | } | ||||
| 33 | |||||
| 34 | # spent 1.60ms (138µs+1.47) within Moose::Exporter::build_import_methods which was called 2 times, avg 802µs/call:
# 2 times (138µs+1.47ms) by Moose::Exporter::setup_import_methods at line 28, avg 802µs/call | ||||
| 35 | 2 | 4µs | my ( $class, %args ) = @_; | ||
| 36 | |||||
| 37 | 2 | 2µs | my $exporting_package = $args{exporting_package} ||= caller(); | ||
| 38 | |||||
| 39 | 2 | 3µs | $EXPORT_SPEC{$exporting_package} = \%args; | ||
| 40 | |||||
| 41 | 2 | 7µs | 2 | 67µs | my @exports_from = $class->_follow_also($exporting_package); # spent 67µs making 2 calls to Moose::Exporter::_follow_also, avg 33µs/call |
| 42 | |||||
| 43 | 2 | 1µs | my $export_recorder = {}; | ||
| 44 | 2 | 900ns | my $is_reexport = {}; | ||
| 45 | |||||
| 46 | 2 | 12µs | 2 | 343µs | my $exports = $class->_make_sub_exporter_params( # spent 343µs making 2 calls to Moose::Exporter::_make_sub_exporter_params, avg 171µs/call |
| 47 | [ @exports_from, $exporting_package ], | ||||
| 48 | $export_recorder, | ||||
| 49 | $is_reexport, | ||||
| 50 | ); | ||||
| 51 | |||||
| 52 | 2 | 11µs | 2 | 794µs | my $exporter = Sub::Exporter::build_exporter( # spent 794µs making 2 calls to Sub::Exporter::build_exporter, avg 397µs/call |
| 53 | { | ||||
| 54 | exports => $exports, | ||||
| 55 | groups => { default => [':all'] } | ||||
| 56 | } | ||||
| 57 | ); | ||||
| 58 | |||||
| 59 | 2 | 400ns | my %methods; | ||
| 60 | 2 | 9µs | 2 | 20µs | $methods{import} = $class->_make_import_sub( # spent 20µs making 2 calls to Moose::Exporter::_make_import_sub, avg 10µs/call |
| 61 | $exporting_package, | ||||
| 62 | $exporter, | ||||
| 63 | \@exports_from, | ||||
| 64 | $is_reexport | ||||
| 65 | ); | ||||
| 66 | |||||
| 67 | 2 | 7µs | 2 | 14µs | $methods{unimport} = $class->_make_unimport_sub( # spent 14µs making 2 calls to Moose::Exporter::_make_unimport_sub, avg 7µs/call |
| 68 | $exporting_package, | ||||
| 69 | $exports, | ||||
| 70 | $export_recorder, | ||||
| 71 | $is_reexport | ||||
| 72 | ); | ||||
| 73 | |||||
| 74 | 2 | 8µs | 2 | 36µs | $methods{init_meta} = $class->_make_init_meta( # spent 36µs making 2 calls to Moose::Exporter::_make_init_meta, avg 18µs/call |
| 75 | $exporting_package, | ||||
| 76 | \%args | ||||
| 77 | ); | ||||
| 78 | |||||
| 79 | 2 | 7µs | 2 | 84µs | my $package = Class::MOP::Package->initialize($exporting_package); # spent 84µs making 2 calls to Class::MOP::Package::initialize, avg 42µs/call |
| 80 | 2 | 5µs | for my $to_install ( @{ $args{install} || [] } ) { | ||
| 81 | 6 | 3µs | my $symbol = '&' . $to_install; | ||
| 82 | next | ||||
| 83 | 6 | 10µs | 4 | 71µs | unless $methods{$to_install} # spent 71µs making 4 calls to Class::MOP::Package::has_package_symbol, avg 18µs/call |
| 84 | && !$package->has_package_symbol($symbol); | ||||
| 85 | 4 | 6µs | 4 | 37µs | $package->add_package_symbol( $symbol, $methods{$to_install} ); # spent 37µs making 4 calls to Class::MOP::Package::add_package_symbol, avg 9µs/call |
| 86 | } | ||||
| 87 | |||||
| 88 | 2 | 9µs | return ( $methods{import}, $methods{unimport}, $methods{init_meta} ); | ||
| 89 | } | ||||
| 90 | |||||
| 91 | { | ||||
| 92 | 2 | 900ns | my $seen = {}; | ||
| 93 | |||||
| 94 | # spent 67µs (30+36) within Moose::Exporter::_follow_also which was called 2 times, avg 33µs/call:
# 2 times (30µs+36µs) by Moose::Exporter::build_import_methods at line 41, avg 33µs/call | ||||
| 95 | 2 | 2µs | my $class = shift; | ||
| 96 | 2 | 1µs | my $exporting_package = shift; | ||
| 97 | |||||
| 98 | 2 | 4µs | local %$seen = ( $exporting_package => 1 ); | ||
| 99 | |||||
| 100 | 2 | 42µs | 4 | 36µs | return uniq( _follow_also_real($exporting_package) ); # spent 24µs making 2 calls to List::MoreUtils::uniq, avg 12µs/call
# spent 12µs making 2 calls to Moose::Exporter::_follow_also_real, avg 6µs/call |
| 101 | } | ||||
| 102 | |||||
| 103 | # spent 12µs within Moose::Exporter::_follow_also_real which was called 2 times, avg 6µs/call:
# 2 times (12µs+0s) by Moose::Exporter::_follow_also at line 100, avg 6µs/call | ||||
| 104 | 2 | 2µs | my $exporting_package = shift; | ||
| 105 | |||||
| 106 | 2 | 2µs | 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 | 2 | 3µs | my $also = $EXPORT_SPEC{$exporting_package}{also}; | ||
| 115 | |||||
| 116 | 2 | 12µs | 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; | ||||
| 129 | } | ||||
| 130 | } | ||||
| 131 | |||||
| 132 | # spent 343µs (217+126) within Moose::Exporter::_make_sub_exporter_params which was called 2 times, avg 171µs/call:
# 2 times (217µs+126µs) by Moose::Exporter::build_import_methods at line 46, avg 171µs/call | ||||
| 133 | 2 | 2µs | my $class = shift; | ||
| 134 | 2 | 800ns | my $packages = shift; | ||
| 135 | 2 | 800ns | my $export_recorder = shift; | ||
| 136 | 2 | 500ns | my $is_reexport = shift; | ||
| 137 | |||||
| 138 | 2 | 800ns | my %exports; | ||
| 139 | |||||
| 140 | 2 | 3µs | for my $package ( @{$packages} ) { | ||
| 141 | 2 | 2µs | my $args = $EXPORT_SPEC{$package} | ||
| 142 | or die "The $package package does not use Moose::Exporter\n"; | ||||
| 143 | |||||
| 144 | 2 | 3µs | for my $name ( @{ $args->{with_meta} } ) { | ||
| 145 | 8 | 9µs | 8 | 26µs | my $sub = $class->_sub_from_package( $package, $name ) # spent 26µs making 8 calls to Moose::Exporter::_sub_from_package, avg 3µs/call |
| 146 | or next; | ||||
| 147 | |||||
| 148 | 8 | 2µs | my $fq_name = $package . '::' . $name; | ||
| 149 | |||||
| 150 | 8 | 15µs | 8 | 39µs | $exports{$name} = $class->_make_wrapped_sub_with_meta( # spent 39µs making 8 calls to Moose::Exporter::_make_wrapped_sub_with_meta, avg 5µs/call |
| 151 | $fq_name, | ||||
| 152 | $sub, | ||||
| 153 | $export_recorder, | ||||
| 154 | ); | ||||
| 155 | } | ||||
| 156 | |||||
| 157 | 2 | 4µs | for my $name ( @{ $args->{with_caller} } ) { | ||
| 158 | my $sub = $class->_sub_from_package( $package, $name ) | ||||
| 159 | or next; | ||||
| 160 | |||||
| 161 | my $fq_name = $package . '::' . $name; | ||||
| 162 | |||||
| 163 | $exports{$name} = $class->_make_wrapped_sub( | ||||
| 164 | $fq_name, | ||||
| 165 | $sub, | ||||
| 166 | $export_recorder, | ||||
| 167 | ); | ||||
| 168 | } | ||||
| 169 | |||||
| 170 | 2 | 4µs | for my $name ( @{ $args->{as_is} } ) { | ||
| 171 | 21 | 3µs | my ( $sub, $coderef_name ); | ||
| 172 | |||||
| 173 | 21 | 4µs | if ( ref $name ) { | ||
| 174 | 2 | 200ns | $sub = $name; | ||
| 175 | |||||
| 176 | 2 | 200ns | my $coderef_pkg; | ||
| 177 | 2 | 13µs | 2 | 2µs | ( $coderef_pkg, $coderef_name ) # spent 2µs making 2 calls to Class::MOP::get_code_info, avg 1µs/call |
| 178 | = Class::MOP::get_code_info($name); | ||||
| 179 | |||||
| 180 | 2 | 2µs | if ( $coderef_pkg ne $package ) { | ||
| 181 | $is_reexport->{$coderef_name} = 1; | ||||
| 182 | } | ||||
| 183 | } | ||||
| 184 | else { | ||||
| 185 | 19 | 21µs | 19 | 59µs | $sub = $class->_sub_from_package( $package, $name ) # spent 59µs making 19 calls to Moose::Exporter::_sub_from_package, avg 3µs/call |
| 186 | or next; | ||||
| 187 | |||||
| 188 | 19 | 3µs | $coderef_name = $name; | ||
| 189 | } | ||||
| 190 | |||||
| 191 | 21 | 17µs | $export_recorder->{$sub} = 1; | ||
| 192 | |||||
| 193 | 42 | 78µs | # spent 35µs within Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:193] which was called 21 times, avg 2µs/call:
# 21 times (35µs+0s) by Sub::Exporter::default_generator at line 856 of Sub/Exporter.pm, avg 2µs/call | ||
| 194 | } | ||||
| 195 | } | ||||
| 196 | |||||
| 197 | 2 | 7µs | return \%exports; | ||
| 198 | } | ||||
| 199 | |||||
| 200 | sub _sub_from_package { | ||||
| 201 | 27 | 6µs | my $sclass = shift; | ||
| 202 | 27 | 4µs | my $package = shift; | ||
| 203 | 27 | 4µs | my $name = shift; | ||
| 204 | |||||
| 205 | 27 | 4µs | my $sub = do { | ||
| 206 | 3 | 554µs | 2 | 44µs | # spent 26µs (9+18) within Moose::Exporter::BEGIN@206 which was called
# once (9µs+18µs) by Moose::BEGIN@14 at line 206 # spent 26µs making 1 call to Moose::Exporter::BEGIN@206
# spent 18µs making 1 call to strict::unimport |
| 207 | 27 | 26µs | \&{ $package . '::' . $name }; | ||
| 208 | }; | ||||
| 209 | |||||
| 210 | 27 | 48µs | return $sub if defined &$sub; | ||
| 211 | |||||
| 212 | Carp::cluck "Trying to export undefined sub ${package}::${name}"; | ||||
| 213 | |||||
| 214 | return; | ||||
| 215 | } | ||||
| 216 | |||||
| 217 | 1 | 100ns | our $CALLER; | ||
| 218 | |||||
| 219 | sub _make_wrapped_sub { | ||||
| 220 | 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 | return sub { | ||||
| 232 | my $caller = $CALLER; | ||||
| 233 | |||||
| 234 | my $wrapper = $self->_curry_wrapper( $sub, $fq_name, $caller ); | ||||
| 235 | |||||
| 236 | my $sub = subname( $fq_name => $wrapper ); | ||||
| 237 | |||||
| 238 | $export_recorder->{$sub} = 1; | ||||
| 239 | |||||
| 240 | return $sub; | ||||
| 241 | }; | ||||
| 242 | } | ||||
| 243 | |||||
| 244 | # spent 39µs within Moose::Exporter::_make_wrapped_sub_with_meta which was called 8 times, avg 5µs/call:
# 8 times (39µs+0s) by Moose::Exporter::_make_sub_exporter_params at line 150, avg 5µs/call | ||||
| 245 | 8 | 3µs | my $self = shift; | ||
| 246 | 8 | 2µs | my $fq_name = shift; | ||
| 247 | 8 | 900ns | my $sub = shift; | ||
| 248 | 8 | 1µs | my $export_recorder = shift; | ||
| 249 | |||||
| 250 | # spent 146µs (82+63) within Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:263] which was called 8 times, avg 18µs/call:
# 8 times (82µs+63µs) by Sub::Exporter::default_generator at line 856 of Sub/Exporter.pm, avg 18µs/call | ||||
| 251 | 8 | 3µs | my $caller = $CALLER; | ||
| 252 | |||||
| 253 | my $wrapper = $self->_late_curry_wrapper( | ||||
| 254 | $sub, $fq_name, | ||||
| 255 | 12 | 44µs | 12 | 79µs | # spent 47µs (17+30) within Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:255] which was called 4 times, avg 12µs/call:
# 4 times (17µs+30µs) by Moose::has at line 292, avg 12µs/call # spent 50µs making 8 calls to Moose::Exporter::_late_curry_wrapper, avg 6µs/call
# spent 30µs making 4 calls to Class::MOP::class_of, avg 7µs/call |
| 256 | ); | ||||
| 257 | |||||
| 258 | 8 | 29µs | 8 | 14µs | my $sub = subname( $fq_name => $wrapper ); # spent 14µs making 8 calls to Sub::Name::subname, avg 2µs/call |
| 259 | |||||
| 260 | 8 | 9µs | $export_recorder->{$sub} = 1; | ||
| 261 | |||||
| 262 | 8 | 16µs | return $sub; | ||
| 263 | 8 | 38µs | }; | ||
| 264 | } | ||||
| 265 | |||||
| 266 | sub _curry_wrapper { | ||||
| 267 | 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 ) { | ||||
| 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 50µs within Moose::Exporter::_late_curry_wrapper which was called 8 times, avg 6µs/call:
# 8 times (50µs+0s) by Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:263] at line 255, avg 6µs/call | ||||
| 283 | 8 | 2µs | my $class = shift; | ||
| 284 | 8 | 2µs | my $sub = shift; | ||
| 285 | 8 | 2µs | my $fq_name = shift; | ||
| 286 | 8 | 900ns | my $extra = shift; | ||
| 287 | 8 | 4µs | my @ex_args = @_; | ||
| 288 | |||||
| 289 | my $wrapper = sub { | ||||
| 290 | |||||
| 291 | # resolve curried arguments at runtime via this closure | ||||
| 292 | 4 | 9µs | 4 | 47µs | my @curry = ( $extra->(@ex_args) ); # spent 47µs making 4 calls to Moose::Exporter::__ANON__[Moose/Exporter.pm:255], avg 12µs/call |
| 293 | 4 | 18µs | 4 | 5.08ms | return $sub->( @curry, @_ ); # spent 5.08ms making 4 calls to Moose::has, avg 1.27ms/call |
| 294 | 8 | 21µs | }; | ||
| 295 | |||||
| 296 | 8 | 3µs | 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 | 8 | 19µs | return $wrapper; | ||
| 303 | } | ||||
| 304 | |||||
| 305 | # spent 20µs within Moose::Exporter::_make_import_sub which was called 2 times, avg 10µs/call:
# 2 times (20µs+0s) by Moose::Exporter::build_import_methods at line 60, avg 10µs/call | ||||
| 306 | 2 | 1µs | shift; | ||
| 307 | 2 | 2µs | my $exporting_package = shift; | ||
| 308 | 2 | 1µs | my $exporter = shift; | ||
| 309 | 2 | 600ns | my $exports_from = shift; | ||
| 310 | 2 | 700ns | my $is_reexport = shift; | ||
| 311 | |||||
| 312 | # spent 4.15ms (129µs+4.02) within Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:389] which was called 2 times, avg 2.07ms/call:
# once (78µs+2.77ms) by SimpleDB::Client::BEGIN@46 at line 46 of ../lib/SimpleDB/Client.pm
# once (51µs+1.25ms) by Moose::BEGIN@34 at line 34 of Moose.pm | ||||
| 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. | ||||
| 322 | 2 | 800ns | my $traits; | ||
| 323 | 2 | 9µs | 2 | 56µs | ( $traits, @_ ) = _strip_traits(@_); # spent 56µs making 2 calls to Moose::Exporter::_strip_traits, avg 28µs/call |
| 324 | |||||
| 325 | 2 | 700ns | my $metaclass; | ||
| 326 | 2 | 7µs | 2 | 21µs | ( $metaclass, @_ ) = _strip_metaclass(@_); # spent 21µs making 2 calls to Moose::Exporter::_strip_metaclass, avg 11µs/call |
| 327 | 2 | 1µs | $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 | 2 | 2µs | my $class = $exporting_package; | ||
| 335 | |||||
| 336 | 2 | 5µs | 2 | 10µs | $CALLER = _get_caller(@_); # spent 10µs making 2 calls to Moose::Exporter::_get_caller, avg 5µ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 | 2 | 5µs | 2 | 8µs | strict->import; # spent 8µs making 2 calls to strict::import, avg 4µs/call |
| 345 | 2 | 4µs | 2 | 27µs | warnings->import; # spent 27µs making 2 calls to warnings::import, avg 13µs/call |
| 346 | |||||
| 347 | 2 | 600ns | my $did_init_meta; | ||
| 348 | 4 | 27µs | 2 | 6µs | for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) { # spent 6µs making 2 calls to UNIVERSAL::can, avg 3µ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 | 1 | 800ns | local $CALLER = $CALLER; | ||
| 354 | 1 | 2µs | 1 | 1.52ms | $c->init_meta( for_class => $CALLER, metaclass => $metaclass ); # spent 1.52ms making 1 call to Moose::init_meta |
| 355 | 1 | 1µs | $did_init_meta = 1; | ||
| 356 | } | ||||
| 357 | |||||
| 358 | 2 | 2µs | 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 | 2 | 2µs | my ( undef, @args ) = @_; | ||
| 374 | 2 | 1µs | my $extra = shift @args if ref $args[0] eq 'HASH'; | ||
| 375 | |||||
| 376 | 2 | 1µs | $extra ||= {}; | ||
| 377 | 2 | 2µs | if ( !$extra->{into} ) { | ||
| 378 | 2 | 2µs | $extra->{into_level} ||= 0; | ||
| 379 | 2 | 700ns | $extra->{into_level}++; | ||
| 380 | } | ||||
| 381 | |||||
| 382 | 2 | 10µs | 2 | 2.36ms | $class->$exporter( $extra, @args ); # spent 2.36ms making 2 calls to Sub::Exporter::__ANON__[Sub/Exporter.pm:756], avg 1.18ms/call |
| 383 | |||||
| 384 | 2 | 16µs | for my $name ( keys %{$is_reexport} ) { | ||
| 385 | 3 | 125µs | 2 | 29µs | # spent 18µs (7+11) within Moose::Exporter::BEGIN@385 which was called
# once (7µs+11µs) by Moose::BEGIN@14 at line 385 # spent 18µs making 1 call to Moose::Exporter::BEGIN@385
# spent 11µs making 1 call to strict::unimport |
| 386 | 3 | 428µs | 2 | 42µs | # spent 26µs (9+17) within Moose::Exporter::BEGIN@386 which was called
# once (9µs+17µs) by Moose::BEGIN@14 at line 386 # spent 26µs making 1 call to Moose::Exporter::BEGIN@386
# spent 16µs making 1 call to warnings::unimport |
| 387 | 2 | 23µs | 2 | 10µs | _flag_as_reexport( \*{ join q{::}, $CALLER, $name } ); # spent 10µs making 2 calls to Moose::Exporter::_flag_as_reexport, avg 5µs/call |
| 388 | } | ||||
| 389 | 2 | 15µs | }; | ||
| 390 | } | ||||
| 391 | |||||
| 392 | # spent 56µs (31+25) within Moose::Exporter::_strip_traits which was called 2 times, avg 28µs/call:
# 2 times (31µs+25µs) by Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:389] at line 323, avg 28µs/call | ||||
| 393 | 4 | 46µs | 2 | 25µs | my $idx = first_index { $_ eq '-traits' } @_; # spent 25µs making 2 calls to List::MoreUtils::firstidx, avg 12µs/call |
| 394 | |||||
| 395 | 2 | 11µs | 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 21µs (18+3) within Moose::Exporter::_strip_metaclass which was called 2 times, avg 11µs/call:
# 2 times (18µs+3µs) by Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:389] at line 326, avg 11µs/call | ||||
| 407 | 4 | 14µs | 2 | 3µs | my $idx = first_index { $_ eq '-metaclass' } @_; # spent 3µs making 2 calls to List::MoreUtils::firstidx, avg 1µs/call |
| 408 | |||||
| 409 | 2 | 7µs | return ( undef, @_ ) unless $idx >= 0 && $#_ >= $idx + 1; | ||
| 410 | |||||
| 411 | my $metaclass = $_[ $idx + 1 ]; | ||||
| 412 | |||||
| 413 | splice @_, $idx, 2; | ||||
| 414 | |||||
| 415 | return ( $metaclass, @_ ); | ||||
| 416 | } | ||||
| 417 | |||||
| 418 | sub _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 10µs within Moose::Exporter::_get_caller which was called 2 times, avg 5µs/call:
# 2 times (10µs+0s) by Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:389] at line 336, avg 5µs/call | ||||
| 451 | |||||
| 452 | # 1 extra level because it's called by import so there's a layer | ||||
| 453 | # of indirection | ||||
| 454 | 2 | 800ns | my $offset = 1; | ||
| 455 | |||||
| 456 | return | ||||
| 457 | 2 | 11µs | ( 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 14µs within Moose::Exporter::_make_unimport_sub which was called 2 times, avg 7µs/call:
# 2 times (14µs+0s) by Moose::Exporter::build_import_methods at line 67, avg 7µs/call | ||||
| 464 | 2 | 700ns | shift; | ||
| 465 | 2 | 1µs | my $exporting_package = shift; | ||
| 466 | 2 | 700ns | my $exports = shift; | ||
| 467 | 2 | 500ns | my $export_recorder = shift; | ||
| 468 | 2 | 900ns | my $is_reexport = shift; | ||
| 469 | |||||
| 470 | # spent 157µs (18+139) within Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:478] which was called
# once (18µs+139µs) by SimpleDB::Client::BEGIN@331 at line 331 of ../lib/SimpleDB/Client.pm | ||||
| 471 | 1 | 2µs | my $caller = scalar caller(); | ||
| 472 | Moose::Exporter->_remove_keywords( | ||||
| 473 | $caller, | ||||
| 474 | 1 | 14µs | 1 | 139µs | [ keys %{$exports} ], # spent 139µs making 1 call to Moose::Exporter::_remove_keywords |
| 475 | $export_recorder, | ||||
| 476 | $is_reexport, | ||||
| 477 | ); | ||||
| 478 | 2 | 10µs | }; | ||
| 479 | } | ||||
| 480 | |||||
| 481 | # spent 139µs (132+7) within Moose::Exporter::_remove_keywords which was called
# once (132µs+7µs) by Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:478] at line 474 | ||||
| 482 | 1 | 600ns | shift; | ||
| 483 | 1 | 800ns | my $package = shift; | ||
| 484 | 1 | 700ns | my $keywords = shift; | ||
| 485 | 1 | 600ns | my $recorded_exports = shift; | ||
| 486 | 1 | 400ns | my $is_reexport = shift; | ||
| 487 | |||||
| 488 | 3 | 59µs | 2 | 29µs | # spent 18µs (7+11) within Moose::Exporter::BEGIN@488 which was called
# once (7µs+11µs) by Moose::BEGIN@14 at line 488 # spent 18µs making 1 call to Moose::Exporter::BEGIN@488
# spent 11µs making 1 call to strict::unimport |
| 489 | |||||
| 490 | 1 | 7µs | foreach my $name ( @{$keywords} ) { | ||
| 491 | 12 | 19µs | if ( defined &{ $package . '::' . $name } ) { | ||
| 492 | 12 | 12µs | my $sub = \&{ $package . '::' . $name }; | ||
| 493 | |||||
| 494 | # make sure it is from us | ||||
| 495 | 12 | 10µs | next unless $recorded_exports->{$sub}; | ||
| 496 | |||||
| 497 | 12 | 3µs | if ( $is_reexport->{$name} ) { | ||
| 498 | 3 | 1.44ms | 2 | 25µs | # spent 16µs (6+9) within Moose::Exporter::BEGIN@498 which was called
# once (6µs+9µs) by Moose::BEGIN@14 at line 498 # spent 16µs making 1 call to Moose::Exporter::BEGIN@498
# spent 9µs making 1 call to strict::unimport |
| 499 | next | ||||
| 500 | unless _export_is_flagged( | ||||
| 501 | 2 | 21µs | 2 | 7µs | \*{ join q{::} => $package, $name } ); # spent 7µs making 2 calls to Moose::Exporter::_export_is_flagged, avg 4µs/call |
| 502 | } | ||||
| 503 | |||||
| 504 | # and if it is from us, then undef the slot | ||||
| 505 | 12 | 60µs | delete ${ $package . '::' }{$name}; | ||
| 506 | } | ||||
| 507 | } | ||||
| 508 | } | ||||
| 509 | |||||
| 510 | # spent 36µs within Moose::Exporter::_make_init_meta which was called 2 times, avg 18µs/call:
# 2 times (36µs+0s) by Moose::Exporter::build_import_methods at line 74, avg 18µs/call | ||||
| 511 | 2 | 800ns | shift; | ||
| 512 | 2 | 1µs | my $class = shift; | ||
| 513 | 2 | 1µs | my $args = shift; | ||
| 514 | |||||
| 515 | 2 | 400ns | my %old_style_roles; | ||
| 516 | 2 | 11µs | 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 | 16 | 4µs | $old_style_roles{$role} = $args->{$role} | ||
| 530 | if exists $args->{$role}; | ||||
| 531 | } | ||||
| 532 | |||||
| 533 | 2 | 500ns | my %base_class_roles; | ||
| 534 | 2 | 1µs | %base_class_roles = ( roles => $args->{base_class_roles} ) | ||
| 535 | if exists $args->{base_class_roles}; | ||||
| 536 | |||||
| 537 | my %new_style_roles = map { $_ => $args->{$_} } | ||||
| 538 | 2 | 4µs | grep { exists $args->{$_} } qw( class_metaroles role_metaroles ); | ||
| 539 | |||||
| 540 | 2 | 8µs | 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 41µs (17+24) within Moose::Exporter::import which was called 2 times, avg 21µs/call:
# once (8µs+14µs) by Moose::BEGIN@14 at line 14 of Moose.pm
# once (8µs+10µs) by Moose::Util::TypeConstraints::BEGIN@7 at line 7 of Moose/Util/TypeConstraints.pm | ||||
| 566 | 2 | 2µs | 2 | 4µs | strict->import; # spent 4µs making 2 calls to strict::import, avg 2µs/call |
| 567 | 2 | 7µs | 2 | 20µs | warnings->import; # spent 20µs making 2 calls to warnings::import, avg 10µs/call |
| 568 | } | ||||
| 569 | |||||
| 570 | 1 | 10µs | 1; | ||
| 571 | |||||
| 572 | __END__ | ||||
| 573 | |||||
| 574 | =head1 NAME | ||||
| 575 | |||||
| 576 | Moose::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 | |||||
| 613 | This module encapsulates the exporting of sugar functions in a | ||||
| 614 | C<Moose.pm>-like manner. It does this by building custom C<import>, | ||||
| 615 | C<unimport>, and C<init_meta> methods for your module, based on a spec you | ||||
| 616 | provide. | ||||
| 617 | |||||
| 618 | It also lets you "stack" Moose-alike modules so you can export Moose's sugar | ||||
| 619 | as well as your own, along with sugar from any random C<MooseX> module, as | ||||
| 620 | long as they all use C<Moose::Exporter>. This feature exists to let you bundle | ||||
| 621 | a set of MooseX modules into a policy module that developers can use directly | ||||
| 622 | instead of using Moose itself. | ||||
| 623 | |||||
| 624 | To simplify writing exporter modules, C<Moose::Exporter> also imports | ||||
| 625 | C<strict> and C<warnings> into your exporter module, as well as into | ||||
| 626 | modules that use it. | ||||
| 627 | |||||
| 628 | =head1 METHODS | ||||
| 629 | |||||
| 630 | This module provides two public methods: | ||||
| 631 | |||||
| 632 | =over 4 | ||||
| 633 | |||||
| 634 | =item B<< Moose::Exporter->setup_import_methods(...) >> | ||||
| 635 | |||||
| 636 | When you call this method, C<Moose::Exporter> builds custom C<import>, | ||||
| 637 | C<unimport>, and C<init_meta> methods for your module. The C<import> method | ||||
| 638 | will export the functions you specify, and can also re-export functions | ||||
| 639 | exported by some other module (like C<Moose.pm>). | ||||
| 640 | |||||
| 641 | The C<unimport> method cleans the caller's namespace of all the exported | ||||
| 642 | functions. This includes any functions you re-export from other | ||||
| 643 | packages. However, if the consumer of your package also imports those | ||||
| 644 | functions from the original package, they will I<not> be cleaned. | ||||
| 645 | |||||
| 646 | If you pass any parameters for L<Moose::Util::MetaRole>, this method will | ||||
| 647 | generate an C<init_meta> for you as well (see below for details). This | ||||
| 648 | C<init_meta> will call C<Moose::Util::MetaRole::apply_metaclass_roles> and | ||||
| 649 | C<Moose::Util::MetaRole::apply_base_class_roles> as needed. | ||||
| 650 | |||||
| 651 | Note that if any of these methods already exist, they will not be | ||||
| 652 | overridden, you will have to use C<build_import_methods> to get the | ||||
| 653 | coderef that would be installed. | ||||
| 654 | |||||
| 655 | This method accepts the following parameters: | ||||
| 656 | |||||
| 657 | =over 8 | ||||
| 658 | |||||
| 659 | =item * with_meta => [ ... ] | ||||
| 660 | |||||
| 661 | This list of function I<names only> will be wrapped and then exported. The | ||||
| 662 | wrapper will pass the metaclass object for the caller as its first argument. | ||||
| 663 | |||||
| 664 | Many sugar functions will need to use this metaclass object to do something to | ||||
| 665 | the calling package. | ||||
| 666 | |||||
| 667 | =item * as_is => [ ... ] | ||||
| 668 | |||||
| 669 | This list of function names or sub references will be exported as-is. You can | ||||
| 670 | identify a subroutine by reference, which is handy to re-export some other | ||||
| 671 | module's functions directly by reference (C<\&Some::Package::function>). | ||||
| 672 | |||||
| 673 | If you do export some other package's function, this function will never be | ||||
| 674 | removed by the C<unimport> method. The reason for this is we cannot know if | ||||
| 675 | the caller I<also> explicitly imported the sub themselves, and therefore wants | ||||
| 676 | to keep it. | ||||
| 677 | |||||
| 678 | =item * also => $name or \@names | ||||
| 679 | |||||
| 680 | This is a list of modules which contain functions that the caller | ||||
| 681 | wants to export. These modules must also use C<Moose::Exporter>. The | ||||
| 682 | most common use case will be to export the functions from C<Moose.pm>. | ||||
| 683 | Functions specified by C<with_meta> or C<as_is> take precedence over | ||||
| 684 | functions exported by modules specified by C<also>, so that a module | ||||
| 685 | can selectively override functions exported by another module. | ||||
| 686 | |||||
| 687 | C<Moose::Exporter> also makes sure all these functions get removed | ||||
| 688 | when C<unimport> is called. | ||||
| 689 | |||||
| 690 | =back | ||||
| 691 | |||||
| 692 | You can also provide parameters for C<Moose::Util::MetaRole::apply_metaroles> | ||||
| 693 | and C<Moose::Util::MetaRole::base_class_roles>. Specifically, valid parameters | ||||
| 694 | are "class_metaroles", "role_metaroles", and "base_object_roles". | ||||
| 695 | |||||
| 696 | =item B<< Moose::Exporter->build_import_methods(...) >> | ||||
| 697 | |||||
| 698 | Returns two or three code refs, one for C<import>, one for | ||||
| 699 | C<unimport>, and optionally one for C<init_meta>, if the appropriate | ||||
| 700 | options are passed in. | ||||
| 701 | |||||
| 702 | Accepts the additional C<install> option, which accepts an arrayref of method | ||||
| 703 | names to install into your exporting package. The valid options are C<import>, | ||||
| 704 | C<unimport>, and C<init_meta>. Calling C<setup_import_methods> is equivalent | ||||
| 705 | to calling C<build_import_methods> with C<< install => [qw(import unimport | ||||
| 706 | init_meta)] >> except that it doesn't also return the methods. | ||||
| 707 | |||||
| 708 | Used by C<setup_import_methods>. | ||||
| 709 | |||||
| 710 | =back | ||||
| 711 | |||||
| 712 | =head1 IMPORTING AND init_meta | ||||
| 713 | |||||
| 714 | If you want to set an alternative base object class or metaclass class, see | ||||
| 715 | above for details on how this module can call L<Moose::Util::MetaRole> for | ||||
| 716 | you. | ||||
| 717 | |||||
| 718 | If you want to do something that is not supported by this module, simply | ||||
| 719 | define an C<init_meta> method in your class. The C<import> method that | ||||
| 720 | C<Moose::Exporter> generates for you will call this method (if it exists). It | ||||
| 721 | will always pass the caller to this method via the C<for_class> parameter. | ||||
| 722 | |||||
| 723 | Most of the time, your C<init_meta> method will probably just call C<< | ||||
| 724 | Moose->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 | |||||
| 731 | Keep in mind that C<build_import_methods> will return an C<init_meta> | ||||
| 732 | method for you, which you can also call from within your custom | ||||
| 733 | C<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 | |||||
| 762 | The C<import> method generated by C<Moose::Exporter> will allow the | ||||
| 763 | user of your module to specify metaclass traits in a C<-traits> | ||||
| 764 | parameter 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 | |||||
| 770 | These traits will be applied to the caller's metaclass | ||||
| 771 | instance. Providing traits for an exporting class that does not create | ||||
| 772 | a metaclass for the caller is an error. | ||||
| 773 | |||||
| 774 | =head1 BUGS | ||||
| 775 | |||||
| 776 | See L<Moose/BUGS> for details on reporting bugs. | ||||
| 777 | |||||
| 778 | =head1 AUTHOR | ||||
| 779 | |||||
| 780 | Dave Rolsky E<lt>autarch@urth.orgE<gt> | ||||
| 781 | |||||
| 782 | This is largely a reworking of code in Moose.pm originally written by | ||||
| 783 | Stevan Little and others. | ||||
| 784 | |||||
| 785 | =head1 COPYRIGHT AND LICENSE | ||||
| 786 | |||||
| 787 | Copyright 2009 by Infinity Interactive, Inc. | ||||
| 788 | |||||
| 789 | L<http://www.iinteractive.com> | ||||
| 790 | |||||
| 791 | This library is free software; you can redistribute it and/or modify | ||||
| 792 | it under the same terms as Perl itself. | ||||
| 793 | |||||
| 794 | =cut | ||||
# 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 501 of Moose/Exporter.pm, avg 4µs/call | |||||
# spent 10µs within Moose::Exporter::_flag_as_reexport which was called 2 times, avg 5µs/call:
# 2 times (10µs+0s) by Moose::Exporter::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Exporter.pm:389] at line 387 of Moose/Exporter.pm, avg 5µs/call |