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