blib/lib/Import/Export.pm

filter: Statementstmt 100% 44 / 44 Branchbran 100% 24 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 100% 78 / 78 SCAR 25.6
CC
13
Cov
100%
import
7.0
export
7.0
BEGIN
1.0
CRAP 13.0
↑ Summary
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
BranchTrueFalseTotal
unless my(@export) = 6 13 19
21 Carp::croak('define your %EX export hash')
22 13 ▶ unless (%EX) = %{"${pkg}::EX"};
Branch: 1 branch
BranchTrueFalseTotal
unless %EX = %{"${pkg}::EX";} 1 12 13
23  
24 12 ▶ $options = pop @export if ref $export[-1];
Branch: 1 branch
BranchTrueFalseTotal
if ref $export[-1] 2 10 12
25 12 ▶ $caller = $options->{-caller} if exists $options->{-caller};
Branch: 1 branch
BranchTrueFalseTotal
if exists $options->{"-caller"} 1 11 12
26 12 my @exported = export($pkg, $caller, @export);
27  
28 10 ▶ $options->{clean} and "$options->{clean}" eq "import"
Branch: 2 branches
BranchTrueFalseTotal
$options->{"clean"} and qq[$options->{"clean"}] eq "import" ? "namespace::clean"->clean_subroutines($caller, @exported) : "namespace::clean"->import("-cleanee", $caller, @exported) 2 8 10
"$options->{'clean'}" eq 'import' ? : 1 1 2
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
BranchTrueFalseTotal
if (my $ex = shift()) 20 10 30
42 20 my $type;
43 20 ▶ if ( ! $EX{$ex} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($EX{$ex}) 6 14 20
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
BranchTrueFalseTotal
scalar @export ? : 5 1 6
49 : Carp::croak "$ex is not exported";
50 }
51  
52 14 ▶ $type = ($ex =~ s/^(\W)//) ? $1 : "&";
Branch: 1 branch
BranchTrueFalseTotal
$ex =~ s/^(\W)// ? : 6 8 14
53 14 ▶ $caller->can($ex) and next;
Branch: 1 branch
BranchTrueFalseTotal
$caller->can($ex) and next 1 13 14
54  
55 13 ▶ my $exporting = $EXTYPE{$type} or Carp::croak("Cant export symbol $type");
Branch: 1 branch
BranchTrueFalseTotal
my $exporting = $EXTYPE{$type} or Carp::croak("Cant export symbol $type") 1 12 13
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__
↑ Summary