From: Robert Sedlacek Date: Mon, 28 Nov 2011 20:50:58 +0000 (+0100) Subject: import arguments now supported X-Git-Tag: v1.000000~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1abbe9d7ebbbf384569a0a74bd96a1d17843c749;p=p5sagit%2FPackage-Variant.git import arguments now supported --- diff --git a/lib/Package/Variant.pm b/lib/Package/Variant.pm index c99e24f..7e0cbe0 100644 --- a/lib/Package/Variant.pm +++ b/lib/Package/Variant.pm @@ -40,8 +40,14 @@ sub import { sub build_variant_of { my ($me, $variable, @args) = @_; my $variant_name = "${variable}::_Variant_".++$Variable{$variable}{anon}; - my @to_import = keys %{$Variable{$variable}{args}{importing}||{}}; - my $setup = join("\n", "package ${variant_name};", (map "use $_;", @to_import), "1;"); + my $import = $Variable{$variable}{args}{importing} || {}; + my $setup = join("\n", + "package ${variant_name};", + (map sprintf( + q!use %s @{$import->{'%s'}||[]};!, $_, quotemeta($_), + ), keys %$import), + "1;", + ); eval $setup or die "evaling ${setup} failed: $@"; my $subs = $Variable{$variable}{subs}; diff --git a/t/01simple.t b/t/01simple.t index 535d499..1520886 100644 --- a/t/01simple.t +++ b/t/01simple.t @@ -7,7 +7,7 @@ my @DECLARED; BEGIN { package TestSugar; - use Exporter; + use Exporter 'import'; our @EXPORT_OK = qw( declare ); sub declare { push @DECLARED, [@_] } $INC{'TestSugar.pm'} = __FILE__; @@ -49,7 +49,7 @@ is_deeply shift(@DECLARED), [target => $variant], 'target passed via proxy'; is_deeply shift(@DECLARED), [args => [3..7]], 'arguments passed via proxy'; -is_deeply shift(@DECLARED), [class => $variant], +is_deeply shift(@DECLARED), [class => 'TestVariable'], 'class method resolution'; is scalar(@DECLARED), 0, 'proxy sub called right amount of times';