allow an integer target to refer to a specific caller level, including file/line
[p5sagit/Import-Into.git] / lib / Import / Into.pm
index a3c5652..59c861b 100644 (file)
@@ -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) = @_;