Subject: | Sandbox breaks when combining synopses that use Moose and Moose::Role |
'all_synopsis_ok' can have issues if the synopsis of one module breaks
something in the sandbox package for the synopsis of another.
For example, running the test in a dist that has one module whose
Synopsis has 'use Moose;' and another module has 'use Moose::Role;' the
whole thing dies:
You can reproduce with something like:
perl -MTest::Synopsis -e 'use strict; print
Test::Synopsis::_compile("use $_;") || $@ for qw(Moose Moose::Role)'
Test::Synopsis::Sandbox already has a metaclass, but it does not inherit
Moose::Meta::Role (Moose::Meta::Class=HASH(0x134bc98)). You cannot make
the same thing a role and a class. Remove either Moose or Moose::Role.
at
/home/rando/perl5/perlbrew/perls/5.14.2-st/lib/site_perl/5.14.2/x86_64-linux-thread-multi/Moose/Role.pm
line 129.
Moose::Role::init_meta('Moose::Role', 'for_class',
'Test::Synopsis::Sandbox', 'metaclass', undef, 'meta_name', 'meta')
called at
/home/rando/perl5/perlbrew/perls/5.14.2-st/lib/site_perl/5.14.2/x86_64-linux-thread-multi/Moose/Exporter.pm
line 435
Moose::Exporter::__ANON__('Moose::Role') called at (eval 244) line 1
Test::Synopsis::Sandbox::BEGIN() called at (eval 244) line 1
eval {...} called at (eval 244) line 1
eval 'use Moose::Role;' called at
/home/rando/perl5/perlbrew/perls/5.14.2-st/lib/site_perl/5.14.2/Test/Synopsis.pm
line 39
Test::Synopsis::_compile('use Moose::Role;') called at -e line 1
BEGIN failed--compilation aborted at (eval 244) line 1.
The attached patch uses a simple increment which seems fix the one-liner,
though I haven't yet produced a reliable test script to go with it.
perl 5.14.2, Test::Synopsis 0.06
Subject: | test-synopsis-sandbox-increment.patch |
diff --git a/lib/Test/Synopsis.pm b/lib/Test/Synopsis.pm
index fedeacd..14d8767 100644
--- a/lib/Test/Synopsis.pm
+++ b/lib/Test/Synopsis.pm
@@ -33,10 +33,11 @@ sub synopsis_ok {
}
}
+my $sandbox = 0;
sub _compile {
package
Test::Synopsis::Sandbox;
- eval $_[0]; ## no critic
+ eval sprintf "package\nTest::Synopsis::Sandbox%d;\n%s", ++$sandbox, $_[0]; ## no critic
}
sub extract_synopsis {