X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FImport-Into.git;a=blobdiff_plain;f=lib%2FImport%2FInto.pm;fp=lib%2FImport%2FInto.pm;h=11040cc5c7d03c171d475ce8bccafb0e29ac953d;hp=74b7358d9093c688b80beb9bb8d2c62745580e21;hb=568eef3eaba8968cd37b29f669648c302bf7ac60;hpb=995d8262bd1c7cc306aee068943efa7d205605c0 diff --git a/lib/Import/Into.pm b/lib/Import/Into.pm index 74b7358..11040cc 100644 --- a/lib/Import/Into.pm +++ b/lib/Import/Into.pm @@ -7,15 +7,25 @@ our $VERSION = '1.001001'; # 1.1.1 sub _prelude { my $target = shift; - my ($package, $file, $line) - = $target =~ /[^0-9]/ ? ($target) : caller($target + 2); + my ($package, $file, $line, $level) + = ref $target ? @{$target}{qw(package filename line)} + : $target =~ /[^0-9]/ ? ($target) + : (undef, undef, undef, $target); + if (defined $level) { + my ($p, $fn, $ln) = caller($level + 2); + $package ||= $p; + $file ||= $fn; + $line ||= $ln; + } qq{package $package;\n} . ($file ? "#line $line \"$file\"\n" : '') } sub _make_action { my ($action, $target) = @_; - eval _prelude($target).qq{sub { shift->$action(\@_) }} + my $version = ref $target && $target->{version}; + my $ver_check = $version ? '$_[0]->VERSION($version);' : ''; + eval _prelude($target).qq{sub { $ver_check shift->$action(\@_) }} or die "Failed to build action sub to ${action} for ${target}: $@"; }