Revision history for Package-Variant
+ - fix pragmas applied by modules listed in "importing" from leaking out
+ into unexpected scopes
+
1.001004 2013-05-04
- fix documentation of "build_variant_of" method (RT#84554 -- thanks,
Scott Miller!)
use strictures 1;
use Import::Into;
-use Module::Runtime qw(use_module);
+use Module::Runtime qw(require_module);
use Carp qw(croak);
our $VERSION = '1.001004'; # 1.1.4
my $variant_name = "${variable}::_Variant_".++$Variable{$variable}{anon};
foreach my $to_import (@{$Variable{$variable}{args}{importing}}) {
my ($pkg, $args) = @$to_import;
- use_module($pkg)->import::into($variant_name, @{$args});
+ require_module $pkg;
+ eval q{ BEGIN { $pkg->import::into($variant_name, @{$args}) }; 1; }
+ or die $@;
}
my $subs = $Variable{$variable}{subs};
local @{$subs}{keys %$subs} = map $variant_name->can($_), keys %$subs;
--- /dev/null
+use strictures 1;
+use Test::More;
+use Test::Fatal;
+use Package::Variant ();
+
+BEGIN {
+ package TestPragma;
+ use Package::Variant
+ importing => [ 'strict' ];
+ sub make_variant { }
+ $INC{'TestPragma.pm'} = __FILE__;
+}
+
+is exception {
+ eval q{
+ no strict;
+ use TestPragma;
+ $var = $var;
+ 1;
+ } or die $@;
+}, undef, 'pragmas not applied where PV package used';
+
+is exception {
+ eval q{
+ no strict;
+ BEGIN { my $p = TestPragma(); }
+ $var2 = $var2;
+ 1;
+ } or die $@;
+}, undef, 'pragmas not applied where PV generator used';
+
+done_testing;