From: Chris Prather Date: Tue, 15 Feb 2011 16:36:09 +0000 (-0500) Subject: Reverse the output from _follow_also X-Git-Tag: 1.9903~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f7d62c2e1e079d69f1b12d2e9f299365dc49c72c;p=gitmo%2FMoose.git Reverse the output from _follow_also Turns out when we follow the export tree we return the list in the order we discovered, which is the inverse of the order we want. This wasn't ever a problem before because nobody has tried exporting more than one level off of Moose. Someone has now, so we need to reverse the entire list. Also we have added tests for second-order exports (exporting overridden exports) --- diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index 75b433e..377621c 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -136,7 +136,7 @@ sub _make_exporter { local %$seen = ( $exporting_package => 1 ); - return uniq( _follow_also_real($exporting_package) ); + return reverse uniq( _follow_also_real($exporting_package) ); } sub _follow_also_real { diff --git a/t/050_metaclasses/012_moose_exporter.t b/t/050_metaclasses/012_moose_exporter.t index 98bde56..3635a8b 100644 --- a/t/050_metaclasses/012_moose_exporter.t +++ b/t/050_metaclasses/012_moose_exporter.t @@ -267,11 +267,56 @@ use Test::Requires { } { - ok( ! WantsSugar->can('has'), 'WantsSugar::has() has been cleaned' ); - ok( ! WantsSugar->can('with'), 'WantsSugar::with() has been cleaned' ); + ok( ! WantsOverridingSugar->can('has'), 'WantsSugar::has() has been cleaned' ); + ok( ! WantsOverridingSugar->can('with'), 'WantsSugar::with() has been cleaned' ); +} + +{ + package MooseX::OverridingSugar::PassThru; + + sub with { + my $caller = shift->name; + return $caller . ' called with'; + } + + Moose::Exporter->setup_import_methods( + with_meta => ['with'], + also => 'MooseX::OverridingSugar', + ); + +} + +{ + + package WantsOverridingSugar::PassThru; + + MooseX::OverridingSugar::PassThru->import(); + + ::can_ok( 'WantsOverridingSugar::PassThru', 'has' ); + ::can_ok( 'WantsOverridingSugar::PassThru', 'with' ); + ::is( + has('foo'), + 'WantsOverridingSugar::PassThru called has', + 'has from MooseX::OverridingSugar is called, not has from Moose' + ); + + ::is( + with('foo'), + 'WantsOverridingSugar::PassThru called with', + 'with from MooseX::OverridingSugar::PassThru is called, not has from Moose' + ); + + + MooseX::OverridingSugar::PassThru->unimport(); +} + +{ + ok( ! WantsOverridingSugar::PassThru->can('has'), 'WantsOverridingSugar::PassThru::has() has been cleaned' ); + ok( ! WantsOverridingSugar::PassThru->can('with'), 'WantsOverridingSugar::PassThru::with() has been cleaned' ); } { + package NonExistentExport; use Moose ();