From: Matt S Trout Date: Sat, 12 May 2012 00:41:11 +0000 (+0000) Subject: port to Import::Into X-Git-Tag: v1.001000~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1bacb018c6f5cac16afc1056028741bcf855a303;p=p5sagit%2FPackage-Variant.git port to Import::Into --- diff --git a/Changes b/Changes index a57045c..88789b4 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - Switch to Import::Into for exporting other things - Use Sub::Name to name installed things if available 1.000000 - 2012-01-23 diff --git a/lib/Package/Variant.pm b/lib/Package/Variant.pm index 87c0d74..7313a7f 100644 --- a/lib/Package/Variant.pm +++ b/lib/Package/Variant.pm @@ -1,7 +1,9 @@ package Package::Variant; use strictures 1; -use Carp qw( croak ); +use Import::Into; +use Module::Runtime qw(use_module); +use Carp qw(croak); our $VERSION = '1.000000'; # 1.0.0 @@ -92,23 +94,10 @@ sub import { sub build_variant_of { my ($me, $variable, @args) = @_; my $variant_name = "${variable}::_Variant_".++$Variable{$variable}{anon}; - my $import = $Variable{$variable}{args}{importing}; - my $setup = join("\n", - "package ${variant_name};", - (map sprintf( - q!use %s %s;!, - $import->[$_][0], - scalar(@{$import->[$_][1]}) - ? sprintf( - q!@{$import->[%d][1]}!, - $_, - ) - : '', - ), 0..$#$import), - "1;", - ); - eval $setup - or die "evaling ${setup} failed: $@"; + foreach my $to_import (@{$Variable{$variable}{args}{importing}}) { + my ($pkg, $args) = @$to_import; + use_module($pkg)->import::into($variant_name, @{$args}); + } my $subs = $Variable{$variable}{subs}; local @{$subs}{keys %$subs} = map $variant_name->can($_), keys %$subs; local $Variable{$variable}{install} = sub {