From: Tomas Doran Date: Sun, 16 Nov 2008 17:17:45 +0000 (+0000) Subject: Fix another reentrancy issue in Moose::Exporter by additional localising of + test... X-Git-Tag: 0.62~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fdeb835471824db0cc6292600bee3d8d3e198098;p=gitmo%2FMoose.git Fix another reentrancy issue in Moose::Exporter by additional localising of + test case --- diff --git a/Changes b/Changes index e82b98b..e462290 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,10 @@ Revision history for Perl extension Moose same methods for a single role did not work right (worked just fine with multiple roles) - added test for this + * Moose::Exporter + - Catch another case where recursion caused the value + of $CALLER to be stamped on (t0m) + - added test for this (t0m) 0.61 Fri November 7, 2008 * Moose::Meta::Attribute diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index b4cf84a..5e66910 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -246,6 +246,7 @@ sub _make_import_sub { my $did_init_meta; for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) { + local $CALLER = $CALLER; $c->init_meta( for_class => $CALLER ); $did_init_meta = 1; } diff --git a/t/050_metaclasses/015_metarole.t b/t/050_metaclasses/015_metarole.t index 9a46ca5..a1a06c4 100644 --- a/t/050_metaclasses/015_metarole.t +++ b/t/050_metaclasses/015_metarole.t @@ -3,7 +3,10 @@ use strict; use warnings; -use Test::More tests => 72; +use lib 't/lib', 'lib'; + +use Test::More tests => 73; +use Test::Exception; use Moose::Util::MetaRole; @@ -482,3 +485,29 @@ use Moose::Util::MetaRole; is( My::Class11->meta()->constructor_class, 'My::Constructor', q{... and explicitly set constructor_class value is unchanged)} ); } + +{ + package ExportsMoose; + + Moose::Exporter->setup_import_methods( + also => 'Moose', + ); + + sub init_meta { + shift; + my %p = @_; + Moose->init_meta(%p); + return Moose::Util::MetaRole::apply_metaclass_roles( + for_class => $p{for_class}, + # Causes us to recurse through init_meta, as we have to + # load MyMetaclassRole from disk. + metaclass_roles => [qw/MyMetaclassRole/], + ); + } +} + +lives_ok { + package UsesExportedMoose; + ExportsMoose->import; +} 'import module which loads a role from disk during init_meta'; + diff --git a/t/lib/MyMetaclassRole.pm b/t/lib/MyMetaclassRole.pm new file mode 100644 index 0000000..362265a --- /dev/null +++ b/t/lib/MyMetaclassRole.pm @@ -0,0 +1,4 @@ +package MyMetaclassRole; +use Moose::Role; + +1;