summaryrefslogtreecommitdiffstats
path: root/lib/lexically.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lexically.pm')
-rw-r--r--lib/lexically.pm40
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;