From: Graham Knop Date: Sat, 7 Sep 2013 21:20:28 +0000 (-0400) Subject: allow an integer target to refer to a specific caller level, including file/line X-Git-Tag: v1.002000~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ac6d2081e8a5f1e5dbe0f95685080edaf40ca48b;p=p5sagit%2FImport-Into.git allow an integer target to refer to a specific caller level, including file/line --- diff --git a/lib/Import/Into.pm b/lib/Import/Into.pm index a3c5652..59c861b 100644 --- a/lib/Import/Into.pm +++ b/lib/Import/Into.pm @@ -9,12 +9,16 @@ my %importers; sub _importer { my $target = shift; - \($importers{$target} ||= eval qq{ - package $target; - sub { my \$m = splice \@_, 1, 1; shift->\$m(\@_) }; - } or die "Couldn't build importer for $target: $@") + my ($package, $file, $line) = $target =~ /[^0-9]/ ? ($target) : caller($target + 1); + my $code = qq{package $package;\n} + . ($file ? "#line $line \"$file\"\n" : '') + . 'sub { my $m = splice @_, 1, 1; shift->$m(@_) };'."\n"; + my $sub = \(eval $code + or die "Couldn't build importer for $package: $@"); + $importers{$target} = $sub + unless $file; + $sub; } - sub import::into { my ($class, $target, @args) = @_;