From: Matt S Trout Date: Sun, 10 Nov 2013 18:57:52 +0000 (+0000) Subject: split out _make_action X-Git-Tag: v1.002000~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FImport-Into.git;a=commitdiff_plain;h=5f5f09b18af4987858e59a00204ceb49ff6f8ed0 split out _make_action --- diff --git a/lib/Import/Into.pm b/lib/Import/Into.pm index 3314ec3..a9f4a6c 100644 --- a/lib/Import/Into.pm +++ b/lib/Import/Into.pm @@ -8,21 +8,25 @@ our $VERSION = '1.001001'; # 1.1.1 sub _prelude { my $target = shift; my ($package, $file, $line) - = $target =~ /[^0-9]/ ? ($target) : caller($target + 1); + = $target =~ /[^0-9]/ ? ($target) : caller($target + 2); qq{package $package;\n} . ($file ? "#line $line \"$file\"\n" : '') } +sub _make_action { + my ($action, $target) = @_; + eval _prelude($target).qq{sub { shift->$action(\@_) }} + or die "Failed to build action sub to ${action} for ${target}: $@"; +} + sub import::into { my ($class, $target, @args) = @_; - eval _prelude($target) . '$class->import(@args); 1' - or die $@; + _make_action(import => $target)->($class, @args); } sub unimport::out_of { my ($class, $target, @args) = @_; - eval _prelude($target) . '$class->unimport(@args); 1' - or die $@; + _make_action(unimport => $target)->($class, @args); } 1;