| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # ABSTRACT: Import Routines By Any Means Necessary | 
| 2 |  |  |  |  |  |  | package Extorter; | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 2 |  |  | 2 |  | 17254 | use 5.10.0; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 76 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 2 |  |  | 2 |  | 7 | use strict; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 50 |  | 
| 7 | 2 |  |  | 2 |  | 18 | use warnings; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 48 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 866 | use Import::Into; | 
|  | 2 |  |  |  |  | 4331 |  | 
|  | 2 |  |  |  |  | 461 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | our $VERSION = '0.09'; # VERSION | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub import { | 
| 14 | 4 |  |  | 4 |  | 25 | my $class  = shift; | 
| 15 | 4 |  |  |  |  | 7 | my $target = caller; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 4 | 100 |  |  |  | 23 | my @imports = @_ or return; | 
| 18 | 3 |  |  |  |  | 11 | $class->extort::into($target, $_) for @imports; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 3 |  |  |  |  | 1414 | return; | 
| 21 |  |  |  |  |  |  | } | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub extort::into { | 
| 24 | 14 |  |  | 14 |  | 1095 | my $class  = shift; | 
| 25 | 14 |  |  |  |  | 14 | my $target = shift; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 14 | 50 |  |  |  | 32 | my @imports = @_ or return; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 14 | 50 |  |  |  | 37 | @imports = map join('::', $imports[0], $_), @imports[1..$#imports] | 
| 30 |  |  |  |  |  |  | if @imports > 1; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 14 |  |  |  |  | 13 | my %seen; | 
| 33 | 14 |  |  |  |  | 17 | for my $import (@imports) { | 
| 34 | 14 |  |  |  |  | 75 | my @captures = $import =~ /^(\w.+)(?:\^|::)(.*)/; | 
| 35 | 14 | 100 |  |  |  | 34 | @captures = $import =~ /^\*(.+)/ unless @captures; | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 14 |  |  |  |  | 21 | my ($namespace, $argument) = @captures; | 
| 38 | 14 | 50 |  |  |  | 22 | next unless $namespace; | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 14 | 100 |  |  |  | 22 | unless ($argument) { | 
| 41 | 3 |  |  |  |  | 11 | $namespace->import::into($target); | 
| 42 | 3 |  |  |  |  | 964 | next; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 11 | 50 |  |  |  | 555 | $seen{$namespace}++ | 
| 46 |  |  |  |  |  |  | || eval "require $namespace"; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 11 | 50 |  |  |  | 8562 | if ($argument =~ /\W/) { | 
| 49 | 0 |  |  |  |  | 0 | $namespace->import::into($target, $argument); | 
| 50 | 0 |  |  |  |  | 0 | next; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 2 |  |  | 2 |  | 10 | no strict 'refs'; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 131 |  | 
| 54 | 11 |  |  |  |  | 11 | my %EXPORT_TAGS = %{"${namespace}::EXPORT_TAGS"}; | 
|  | 11 |  |  |  |  | 62 |  | 
| 55 | 11 | 50 |  |  |  | 23 | if ($EXPORT_TAGS{$argument}) { | 
| 56 | 0 |  |  |  |  | 0 | $namespace->import::into($target, $argument); | 
| 57 | 0 |  |  |  |  | 0 | next; | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 11 | 50 |  |  |  | 77 | if ($namespace->can($argument)) { | 
| 61 | 2 |  |  | 2 |  | 8 | no warnings 'redefine'; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 289 |  | 
| 62 | 11 |  |  |  |  | 12 | *{"${target}::${argument}"} = \&{"${namespace}::${argument}"}; | 
|  | 11 |  |  |  |  | 49 |  | 
|  | 11 |  |  |  |  | 23 |  | 
| 63 | 11 |  |  |  |  | 35 | next; | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | # fallback | 
| 67 | 0 |  |  |  |  | 0 | $namespace->import::into($target, $argument); | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 14 |  |  |  |  | 52 | return; | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | 1; | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | __END__ |