From a78111e4a8945819186ab6182db924c2935a3930 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 10 Jul 2013 19:46:05 -0400 Subject: initial implementation --- lib/lexically.pm | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib') diff --git a/lib/lexically.pm b/lib/lexically.pm index e69de29..40b796d 100644 --- a/lib/lexically.pm +++ b/lib/lexically.pm @@ -0,0 +1,40 @@ +package lexically; +use strict; +use warnings; + +use Exporter (); +use Exporter::Lexical 0.02 (); +use Module::Runtime 'require_module'; + +our $INDEX = 0; + +sub import { + shift; + my ($package, @args) = @_; + + my $index = $INDEX++; + my $scratchpad = "lexically::scratchpad_$index"; + my $stash = do { + no strict 'refs'; + \%{ $scratchpad . '::' } + }; + + require_module($package); + + eval qq[package $scratchpad; '$package'->import(\@args)]; + die if $@; + + my @exports = grep { + ref(\$stash->{$_}) ne 'GLOB' || defined(*{ $stash->{$_} }{CODE}) + } keys %$stash; + + my $import = Exporter::Lexical::build_exporter({ + -exports => \@exports, + }, $scratchpad); + + $import->($package, @args); + + delete $lexically::{"scratchpad_${index}::"}; +} + +1; -- cgit v1.2.3-54-g00ecf