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};
BEGIN {
package TestSugar;
- use Exporter;
+ use Exporter 'import';
our @EXPORT_OK = qw( declare );
sub declare { push @DECLARED, [@_] }
$INC{'TestSugar.pm'} = __FILE__;
'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';