X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fmetaclasses%2Fmoose_exporter.t;h=fd0d9ea0cef5484efaf942ffd778b869fe0ae47a;hb=9398581271f50b3d7bf4be076d23e278eee9cbc7;hp=bed631b1d0eec588adc002b54d5a206117a7f8a9;hpb=6bd9df2b273b5784fadb33a1d61d4d108519adf8;p=gitmo%2FMoose.git diff --git a/t/metaclasses/moose_exporter.t b/t/metaclasses/moose_exporter.t index bed631b..fd0d9ea 100644 --- a/t/metaclasses/moose_exporter.t +++ b/t/metaclasses/moose_exporter.t @@ -5,6 +5,7 @@ use warnings; use Test::More; use Test::Fatal; +use Test::Moose; use Test::Requires { 'Test::Output' => '0.01', # skip all if not installed @@ -587,4 +588,94 @@ use Test::Requires { BEGIN { is_deeply(\@init_metas_called, [ 4, 3, 2, 1 ]) || diag(Dumper(\@init_metas_called)) } } +# Using "also => [ 'MooseX::UsesAlsoMoose', 'MooseX::SomethingElse' ]" should +# continue to work. The init_meta order needs to be MooseX::CurrentExporter, +# MooseX::UsesAlsoMoose, Moose, MooseX::SomethingElse. This is a pretty ugly +# and messed up use case, but necessary until we come up with a better way to +# do it. + +{ + my @init_metas_called; + + BEGIN { + package AlsoTest::Role1; + use Moose::Role; + + $INC{'AlsoTest/Role1.pm'} = __FILE__; + } + + BEGIN { + package AlsoTest1; + use Moose::Exporter; + + Moose::Exporter->setup_import_methods( + also => [ 'Moose' ], + ); + + sub init_meta { + shift; + my %opts = @_; + ::ok(!Class::MOP::class_of($opts{for_class})); + push @init_metas_called, 1; + } + + $INC{'AlsoTest1.pm'} = __FILE__; + } + + BEGIN { + package AlsoTest2; + use Moose::Exporter; + use Moose::Util::MetaRole (); + + Moose::Exporter->setup_import_methods; + + sub init_meta { + shift; + my %opts = @_; + ::ok(Class::MOP::class_of($opts{for_class})); + Moose::Util::MetaRole::apply_metaroles( + for => $opts{for_class}, + class_metaroles => { + class => ['AlsoTest::Role1'], + }, + ); + push @init_metas_called, 2; + } + + $INC{'AlsoTest2.pm'} = __FILE__; + } + + BEGIN { + package AlsoTest3; + use Moose::Exporter; + + Moose::Exporter->setup_import_methods( + also => [ 'AlsoTest1', 'AlsoTest2' ], + ); + + sub init_meta { + shift; + my %opts = @_; + ::ok(!Class::MOP::class_of($opts{for_class})); + push @init_metas_called, 3; + } + + $INC{'AlsoTest3.pm'} = __FILE__; + } + + BEGIN { @init_metas_called = () } + { + package UsesAlsoTest3; + use AlsoTest3; + } + use Data::Dumper; + BEGIN { + is_deeply(\@init_metas_called, [ 3, 1, 2 ]) + || diag(Dumper(\@init_metas_called)); + isa_ok(Class::MOP::class_of('UsesAlsoTest3'), 'Moose::Meta::Class'); + does_ok(Class::MOP::class_of('UsesAlsoTest3'), 'AlsoTest::Role1'); + } + +} + done_testing;