my $is_reexport = {};
my $exports = $class->_make_sub_exporter_params(
- [ @exports_from, $exporting_package ],
+ [ $exporting_package, @exports_from ],
$export_recorder,
$is_reexport,
- $meta_lookup,
+ $args{meta_lookup}, # so that we don't pass through the default
);
my $exporter = $class->_make_exporter(
local %$seen = ( $exporting_package => 1 );
- return reverse uniq( _follow_also_real($exporting_package) );
+ return uniq( _follow_also_real($exporting_package) );
}
sub _follow_also_real {
}
sub _make_sub_exporter_params {
- my $class = shift;
- my $packages = shift;
- my $export_recorder = shift;
- my $is_reexport = shift;
- my $meta_lookup = shift;
+ my $class = shift;
+ my $packages = shift;
+ my $export_recorder = shift;
+ my $is_reexport = shift;
+ my $meta_lookup_override = shift;
my %exports;
+ my $current_meta_lookup;
for my $package ( @{$packages} ) {
my $args = $EXPORT_SPEC{$package}
or die "The $package package does not use Moose::Exporter\n";
+ $current_meta_lookup = $meta_lookup_override || $args->{meta_lookup};
+ $meta_lookup_override = $current_meta_lookup;
+
+ my $meta_lookup = $current_meta_lookup
+ || sub { Class::MOP::class_of(shift) };
+
for my $name ( @{ $args->{with_meta} } ) {
my $sub = $class->_sub_from_package( $package, $name )
or next;
$sub,
$export_recorder,
$meta_lookup,
- );
+ ) unless exists $exports{$name};
}
for my $name ( @{ $args->{with_caller} } ) {
$fq_name,
$sub,
$export_recorder,
- );
+ ) unless exists $exports{$name};
}
my @extra_exports = $class->_parse_trait_aliases(
$export_recorder->{$sub} = 1;
- $exports{$coderef_name} = sub {$sub};
+ $exports{$coderef_name} = sub { $sub }
+ unless exists $exports{$coderef_name};
}
}
warnings->import;
my $did_init_meta;
- for my $c ( grep { $_->can('init_meta') } $class, reverse @{$exports_from} ) {
+ for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) {
# init_meta can apply a role, which when loaded uses
# Moose::Exporter, which in turn sets $CALLER, so we need
use Moose ();
use Moose::Exporter;
+ sub meta_lookup { $_[0] }
+
BEGIN {
Moose::Exporter->setup_import_methods(
also => 'Moose',
meta_lookup => sub { Class::MOP::class_of('Class::Vacuum::Innards') },
+ with_meta => ['meta_lookup'],
);
}
}
has star_rod => (
is => 'ro',
);
+
+ ::is(meta_lookup, Class::Vacuum::Innards->meta, "right meta_lookup");
}
ok(Class::Vacuum::Innards->can('star_rod'), 'Vacuum stole the star_rod method');
ok(!Victim->can('star_rod'), 'Victim does not get it at all');
+{
+ package Class::Vacuum::Reexport;
+ use Moose::Exporter;
+
+ BEGIN {
+ Moose::Exporter->setup_import_methods(also => 'Class::Vacuum');
+ }
+}
+
+{
+ package Victim2;
+ BEGIN { Class::Vacuum::Reexport->import }
+
+ has parasol => (
+ is => 'ro',
+ );
+
+ ::is(meta_lookup, Class::Vacuum::Innards->meta, "right meta_lookup");
+}
+
+ok(Class::Vacuum::Innards->can('parasol'), 'Vacuum stole the parasol method');
+ok(!Victim2->can('parasol'), 'Victim does not get it at all');
+
done_testing;