diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-07-10 19:46:05 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-07-10 19:46:05 -0400 |
commit | a78111e4a8945819186ab6182db924c2935a3930 (patch) | |
tree | 3302ad933ca87d9521195be706a59099229bf5e5 /lib/lexically.pm | |
parent | 151b8f09aa871fc9d2c4d0dc061fe71ca1719949 (diff) | |
download | lexically-a78111e4a8945819186ab6182db924c2935a3930.tar.gz lexically-a78111e4a8945819186ab6182db924c2935a3930.zip |
initial implementation
Diffstat (limited to 'lib/lexically.pm')
-rw-r--r-- | lib/lexically.pm | 40 |
1 files changed, 40 insertions, 0 deletions
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; |