| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Exporter::Lite; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | require 5.006; | 
| 4 | 1 |  |  | 1 |  | 32458 | use warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 47 |  | 
| 5 | 1 |  |  | 1 |  | 7 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 118 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.08'; | 
| 8 |  |  |  |  |  |  | our @EXPORT = qw(import); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | sub import { | 
| 12 | 12 |  |  | 12 |  | 18129 | my($exporter, @imports)  = @_; | 
| 13 | 12 |  |  |  |  | 43 | my($caller, $file, $line) = caller; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 1 |  |  | 1 |  | 6 | no strict 'refs'; | 
|  | 1 |  |  |  |  | 7 |  | 
|  | 1 |  |  |  |  | 346 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 12 | 100 |  |  |  | 39 | unless( @imports ) {        # Default import. | 
| 18 | 4 |  |  |  |  | 6 | @imports = @{$exporter.'::EXPORT'}; | 
|  | 4 |  |  |  |  | 19 |  | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  | else { | 
| 21 |  |  |  |  |  |  | # Because @EXPORT_OK = () would indicate that nothing is | 
| 22 |  |  |  |  |  |  | # to be exported, we cannot simply check the length of @EXPORT_OK. | 
| 23 |  |  |  |  |  |  | # We must to oddness to see if the variable exists at all as | 
| 24 |  |  |  |  |  |  | # well as avoid autovivification. | 
| 25 |  |  |  |  |  |  | # XXX idea stolen from base.pm, this might be all unnecessary | 
| 26 | 8 |  |  |  |  | 15 | my $eokglob; | 
| 27 | 8 | 50 | 50 |  |  | 11 | if( $eokglob = ${$exporter.'::'}{EXPORT_OK} and *$eokglob{ARRAY} ) { | 
|  | 8 |  |  |  |  | 82 |  | 
| 28 | 8 | 50 |  |  |  | 11 | if( @{$exporter.'::EXPORT_OK'} ) { | 
|  | 8 |  |  |  |  | 29 |  | 
| 29 |  |  |  |  |  |  | # This can also be cached. | 
| 30 | 40 |  |  |  |  | 61 | my %ok = map { s/^&//; $_ => 1 } @{$exporter.'::EXPORT_OK'}, | 
|  | 40 |  |  |  |  | 109 |  | 
|  | 8 |  |  |  |  | 23 |  | 
| 31 | 8 |  |  |  |  | 18 | @{$exporter.'::EXPORT'}; | 
|  | 8 |  |  |  |  | 22 |  | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 8 |  |  |  |  | 31 | my($denied) = grep {s/^&//; !$ok{$_}} @imports; | 
|  | 16 |  |  |  |  | 32 |  | 
|  | 16 |  |  |  |  | 45 |  | 
| 34 | 8 | 100 |  |  |  | 40 | _not_exported($denied, $exporter, $file, $line) if $denied; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  | else {      # We don't export anything. | 
| 37 | 0 |  |  |  |  | 0 | _not_exported($imports[0], $exporter, $file, $line); | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 11 |  |  |  |  | 34 | _export($caller, $exporter, @imports); | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub _export { | 
| 48 | 11 |  |  | 11 |  | 27 | my($caller, $exporter, @imports) = @_; | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 1 |  |  | 1 |  | 7 | no strict 'refs'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 455 |  | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | # Stole this from Exporter::Heavy.  I'm sure it can be written better | 
| 53 |  |  |  |  |  |  | # but I'm lazy at the moment. | 
| 54 | 11 |  |  |  |  | 24 | foreach my $sym (@imports) { | 
| 55 |  |  |  |  |  |  | # shortcut for the common case of no type character | 
| 56 | 21 | 100 |  |  |  | 77 | (*{$caller.'::'.$sym} = \&{$exporter.'::'.$sym}, next) | 
|  | 17 |  |  |  |  | 2622 |  | 
|  | 17 |  |  |  |  | 48 |  | 
| 57 |  |  |  |  |  |  | unless $sym =~ s/^(\W)//; | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 4 |  |  |  |  | 12 | my $type = $1; | 
| 60 | 4 |  |  |  |  | 13 | my $caller_sym = $caller.'::'.$sym; | 
| 61 | 4 |  |  |  |  | 7 | my $export_sym = $exporter.'::'.$sym; | 
| 62 | 4 |  |  |  |  | 530 | *{$caller_sym} = | 
| 63 | 1 |  |  |  |  | 3 | $type eq '&' ? \&{$export_sym} : | 
| 64 | 3 |  |  |  |  | 9 | $type eq '$' ? \${$export_sym} : | 
| 65 | 0 |  |  |  |  | 0 | $type eq '@' ? \@{$export_sym} : | 
| 66 | 0 |  |  |  |  | 0 | $type eq '%' ? \%{$export_sym} : | 
| 67 | 0 |  |  |  |  | 0 | $type eq '*' ?  *{$export_sym} : | 
| 68 | 4 | 0 |  |  |  | 17 | do { require Carp; Carp::croak("Can't export symbol: $type$sym") }; | 
|  | 0 | 0 |  |  |  | 0 |  | 
|  | 0 | 0 |  |  |  | 0 |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | #"# | 
| 74 |  |  |  |  |  |  | sub _not_exported { | 
| 75 | 1 |  |  | 1 |  | 2 | my($thing, $exporter, $file, $line) = @_; | 
| 76 | 1 |  |  |  |  | 14 | die sprintf qq|"%s" is not exported by the %s module at %s line %d\n|, | 
| 77 |  |  |  |  |  |  | $thing, $exporter, $file, $line; | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | 1; | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | __END__ |