| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package lexically; | 
| 2 |  |  |  |  |  |  | BEGIN { | 
| 3 | 1 |  |  | 1 |  | 21831 | $lexically::AUTHORITY = 'cpan:DOY'; | 
| 4 |  |  |  |  |  |  | } | 
| 5 |  |  |  |  |  |  | { | 
| 6 |  |  |  |  |  |  | $lexically::VERSION = '0.01'; | 
| 7 |  |  |  |  |  |  | } | 
| 8 | 1 |  |  | 1 |  | 9 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 9 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 30 |  | 
| 10 |  |  |  |  |  |  | # ABSTRACT: lexically import functions from non-lexical exporters | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 1 |  |  | 1 |  | 881 | use Exporter::Lexical 0.02 (); | 
|  | 1 |  |  |  |  | 948 |  | 
|  | 1 |  |  |  |  | 24 |  | 
| 13 | 1 |  |  | 1 |  | 828 | use Module::Runtime 'require_module'; | 
|  | 1 |  |  |  |  | 1625 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | our $INDEX = 0; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | sub import { | 
| 19 | 1 |  |  | 1 |  | 6 | shift; | 
| 20 | 1 |  |  |  |  | 2 | my ($package, @args) = @_; | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 1 |  |  |  |  | 3 | my $index = $INDEX++; | 
| 23 | 1 |  |  |  |  | 2 | my $scratchpad = "lexically::scratchpad_$index"; | 
| 24 | 1 |  |  |  |  | 2 | my $stash = do { | 
| 25 | 1 |  |  | 1 |  | 92 | no strict 'refs'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 161 |  | 
| 26 | 1 |  |  |  |  | 1 | \%{ $scratchpad . '::' } | 
|  | 1 |  |  |  |  | 6 |  | 
| 27 |  |  |  |  |  |  | }; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 1 |  |  |  |  | 11 | require_module($package); | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 1 |  |  |  |  | 164 | eval qq[package $scratchpad; '$package'->import(\@args)]; | 
| 32 | 1 | 50 |  |  |  | 5 | die if $@; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 1 |  |  |  |  | 8 | my @exports = grep { | 
| 35 | 1 | 50 |  |  |  | 3 | ref(\$stash->{$_}) ne 'GLOB' || defined(*{ $stash->{$_} }{CODE}) | 
|  | 1 |  |  |  |  | 6 |  | 
| 36 |  |  |  |  |  |  | } keys %$stash; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 1 |  |  |  |  | 8 | my $import = Exporter::Lexical::build_exporter({ | 
| 39 |  |  |  |  |  |  | -exports => \@exports, | 
| 40 |  |  |  |  |  |  | }, $scratchpad); | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 1 |  |  |  |  | 10 | $import->($package, @args); | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 1 |  |  |  |  | 1998 | delete $lexically::{"scratchpad_${index}::"}; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | 1; | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | __END__ |