| 1 | package Import::Export; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 6 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 6 | ▶ | use namespace::clean (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 6 | our $VERSION = '0.08'; | |||||||||||||
| 7 | |||||||||||||||
| 8 | 6 | our %EX; | |||||||||||||
| 9 | |||||||||||||||
| 10 | 6 | our %EXTYPE = ( | |||||||||||||
| 11 | '&' => \&_export_code, | ||||||||||||||
| 12 | '$' => \&_export_scalar, | ||||||||||||||
| 13 | '@' => \&_export_array, | ||||||||||||||
| 14 | '%' => \&_export_hash, | ||||||||||||||
| 15 | '*' => \&_export_glob, | ||||||||||||||
| 16 | ); | ||||||||||||||
| 17 | |||||||||||||||
| 18 | sub import { | ||||||||||||||
| 19 | 19 | ▶ | my ($pkg, $options, $caller) = (shift, {}, caller()); | ||||||||||||
|
Subroutine
import: called CC=7 SCAR=19.5
| |||||||||||||||
| 20 | 19 | ▶ | return unless my @export = @_; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | Carp::croak('define your %EX export hash') | ||||||||||||||
| 22 | 13 | ▶ | unless (%EX) = %{"${pkg}::EX"}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | 12 | ▶ | $options = pop @export if ref $export[-1]; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | 12 | ▶ | $caller = $options->{-caller} if exists $options->{-caller}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | 12 | my @exported = export($pkg, $caller, @export); | |||||||||||||
| 27 | |||||||||||||||
| 28 | 10 | ▶ | $options->{clean} and "$options->{clean}" eq "import" | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 29 | ? namespace::clean->clean_subroutines( # sub import { p->import(@export, { clean => 'import' }) } | ||||||||||||||
| 30 | $caller, | ||||||||||||||
| 31 | @exported | ||||||||||||||
| 32 | ) | ||||||||||||||
| 33 | : namespace::clean->import( # use p @export, { clean => 1 } | ||||||||||||||
| 34 | -cleanee => $caller, | ||||||||||||||
| 35 | @exported | ||||||||||||||
| 36 | ); | ||||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | sub export { | ||||||||||||||
| 40 | 17 | ▶ | my ($pkg, $caller, @exported) = (shift, shift); | ||||||||||||
|
Subroutine
export: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||
| 41 | 17 | ▶ | while (my $ex = shift) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 20 | my $type; | |||||||||||||
| 43 | 20 | ▶ | if ( ! $EX{$ex} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | my @export = grep { | ||||||||||||||
| 45 | 6 | grep { $_ =~ m{\Q$ex\E} } @{ $EX{$_} } | |||||||||||||
| 46 | } keys %EX; | ||||||||||||||
| 47 | scalar @export | ||||||||||||||
| 48 | 6 | ▶ | ? return export($pkg, $caller, (@export, @_)) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | : Carp::croak "$ex is not exported"; | ||||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 14 | ▶ | $type = ($ex =~ s/^(\W)//) ? $1 : "&"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 14 | ▶ | $caller->can($ex) and next; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | |||||||||||||||
| 55 | 13 | ▶ | my $exporting = $EXTYPE{$type} or Carp::croak("Cant export symbol $type"); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 56 | 12 | *{"${caller}::${ex}"} = $exporting->($pkg, $ex); | |||||||||||||
| 57 | 12 | push @exported, $ex; | |||||||||||||
| 58 | } | ||||||||||||||
| 59 | 10 | return @exported; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 7 | ▶ | sub _export_code { \&{"$_[0]::$_[1]"} } | ||||||||||||
|
Subroutine
_export_code: called CC=1 SCAR=0.0
| |||||||||||||||
| 63 | 2 | ▶ | sub _export_scalar { \${"$_[0]::$_[1]"} } | ||||||||||||
|
Subroutine
_export_scalar: called CC=1 SCAR=0.0
| |||||||||||||||
| 64 | 1 | ▶ | sub _export_array { \@{"$_[0]::$_[1]"} } | ||||||||||||
|
Subroutine
_export_array: called CC=1 SCAR=0.0
| |||||||||||||||
| 65 | 1 | ▶ | sub _export_hash { \%{"$_[0]::$_[1]"} } | ||||||||||||
|
Subroutine
_export_hash: called CC=1 SCAR=0.0
| |||||||||||||||
| 66 | 1 | ▶ | sub _export_glob { *{"$_[0]::$_[1]"} } | ||||||||||||
|
Subroutine
_export_glob: called CC=1 SCAR=0.0
| |||||||||||||||
| 67 | |||||||||||||||
| 68 | 6 | 1; | |||||||||||||
| 69 | |||||||||||||||
| 70 | __END__ | ||||||||||||||