From: Graham Knop Date: Sun, 10 Nov 2013 18:51:25 +0000 (-0500) Subject: eval code directly instead of generating a sub X-Git-Tag: v1.002000~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FImport-Into.git;a=commitdiff_plain;h=324e7017c37f3ba326a3c04af62067aa1d561f03 eval code directly instead of generating a sub --- diff --git a/lib/Import/Into.pm b/lib/Import/Into.pm index 043786a..3314ec3 100644 --- a/lib/Import/Into.pm +++ b/lib/Import/Into.pm @@ -5,30 +5,24 @@ use warnings FATAL => 'all'; our $VERSION = '1.001001'; # 1.1.1 -my %importers; - -sub _importer { +sub _prelude { my $target = shift; my ($package, $file, $line) = $target =~ /[^0-9]/ ? ($target) : caller($target + 1); - my $code = qq{package $package;\n} + 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) = @_; - $class->${_importer($target)}(import => @args); + eval _prelude($target) . '$class->import(@args); 1' + or die $@; } sub unimport::out_of { my ($class, $target, @args) = @_; - $class->${_importer($target)}(unimport => @args); + eval _prelude($target) . '$class->unimport(@args); 1' + or die $@; } 1;