From: Graham Knop Date: Fri, 27 Sep 2013 16:54:02 +0000 (-0400) Subject: use different variable for target of initial import vs generated import for clarity X-Git-Tag: v1.002000~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d61014ce3f63d541db3164e5c743e32db2bab238;p=p5sagit%2FPackage-Variant.git use different variable for target of initial import vs generated import for clarity --- diff --git a/lib/Package/Variant.pm b/lib/Package/Variant.pm index 8ff3f56..4aeda2a 100644 --- a/lib/Package/Variant.pm +++ b/lib/Package/Variant.pm @@ -54,11 +54,10 @@ my $sub_namer = eval { } || sub { $_[-1] }; sub import { - my $target = caller; + my $variable = caller; my $me = shift; - my $last = (split '::', $target)[-1]; + my $last = (split '::', $variable)[-1]; my $anon = 'A000'; - my $variable = $target; my %args = @_; no strict 'refs'; $Variable{$variable} = { @@ -71,7 +70,7 @@ sub import { map +($_ => sub {}), @{$args{subs}||[]}, }, }; - *{"${target}::import"} = sub { + *{"${variable}::import"} = sub { my $target = caller; my (undef, %arg) = @_; my $as = defined($arg{as}) ? $arg{as} : $last; @@ -82,11 +81,11 @@ sub import { }; my $subs = $Variable{$variable}{subs}; foreach my $name (keys %$subs) { - *{"${target}::${name}"} = sub { + *{"${variable}::${name}"} = sub { goto &{$subs->{$name}} }; } - *{"${target}::install"} = sub { + *{"${variable}::install"} = sub { goto &{$Variable{$variable}{install}}; } }