« blib/lib/Perlmazing/Perlmazing/dir.pm
↑ Summary
lib/Perlmazing/Perlmazing/Precompile/sort_by_key.pm »
| 1 | package Perlmazing::Engine::Exporter; | ||||||||||||||||||||||||||||||
| 2 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 30 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 30 | ▶ | use Carp; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 30 | our $VERSION = '1.2810'; | |||||||||||||||||||||||||||||
| 6 | 30 | my $package = __PACKAGE__; | |||||||||||||||||||||||||||||
| 7 | 30 | my $imports; | |||||||||||||||||||||||||||||
| 8 | my $exports; | ||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 1363 | ▶ | sub import { | ||||||||||||||||||||||||||||
|
Subroutine
import: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||
| 11 | 1363 | my $self = shift; | |||||||||||||||||||||||||||||
| 12 | 1363 | my @call = caller 0; | |||||||||||||||||||||||||||||
| 13 | 1363 | my $pack = $call[0]; | |||||||||||||||||||||||||||||
| 14 | 30 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | 1363 | ▶ | if ($self eq $package) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 16 | 0 | my $in_isa = grep { /^\Q$package\E$/ } @{"${pack}::ISA"}; | |||||||||||||||||||||||||||||
| 17 | 30 | ▶ | unshift (@{"${pack}::ISA"}, __PACKAGE__) unless $in_isa; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 18 | } else { | ||||||||||||||||||||||||||||||
| 19 | 1333 | ▶ | if (my @call = caller 1) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 20 | 1333 | ▶ | $pack = $call[0] if $call[3] eq "${self}::import"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||
| 22 | 1333 | ▶ | return if $imports->{$pack}->{$self}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 23 | 1333 | my @export = (@_, @{"${self}::EXPORT"}); | |||||||||||||||||||||||||||||
| 24 | 1333 | @export = $self->_expand_names(@export); | |||||||||||||||||||||||||||||
| 25 | 1333 | my $no = {map {$_ => 1} grep {$_ =~ /^!/} @export}; | |||||||||||||||||||||||||||||
| 26 | 1333 | my @yes = grep {!$no->{"!$_"}} grep {$_ !~ /^!/} @export; | |||||||||||||||||||||||||||||
| 27 | 1333 | for my $i (@yes) { | |||||||||||||||||||||||||||||
| 28 | 14828 | $package->export($self, $i, $pack); | |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||
| 30 | 1333 | $imports->{$pack}->{$self}++; | |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | 1338 | ▶ | sub _expand_names { | ||||||||||||||||||||||||||||
|
Subroutine
_expand_names: called CC=11 SCAR=24.4
| |||||||||||||||||||||||||||||||
| 35 | 1338 | my $self = shift; | |||||||||||||||||||||||||||||
| 36 | 1338 | my @expanded; | |||||||||||||||||||||||||||||
| 37 | 30 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 38 | 1338 | for my $i (@_) { | |||||||||||||||||||||||||||||
| 39 | 14860 | my $no = $i =~ s/^!//; | |||||||||||||||||||||||||||||
| 40 | 14860 | ▶ | my $neg = $no ? '!' : ''; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 41 | 14860 | ▶ | if ($i =~ /^:(\w+)$/) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 42 | 5 | my $name = $1; | |||||||||||||||||||||||||||||
| 43 | 5 | ▶ | croak "Package $self doesn't define tag '$name' in \%EXPORT_TAGS" unless exists ${"${self}::EXPORT_TAGS"}{$name}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 44 | 5 | ▶ | push @expanded, map {($_ =~ s/^!//) ? ($no ? $_ : "$neg$_") : "$neg$_"} $self->_expand_names(@{${"${self}::EXPORT_TAGS"}{$name}}); | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||||
| 46 | 14855 | push @expanded, "$neg$i"; | |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||
| 49 | 1338 | my $seen; | |||||||||||||||||||||||||||||
| 50 | my @final; | ||||||||||||||||||||||||||||||
| 51 | 1338 | for my $i (@expanded) { | |||||||||||||||||||||||||||||
| 52 | 14937 | push @final, $i; | |||||||||||||||||||||||||||||
| 53 | 14937 | $seen->{$i}++; | |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||
| 55 | 1338 | my $found_symbols = {map {$_ => 1} @{"${self}::found_symbols"}}; | |||||||||||||||||||||||||||||
| 56 | 1338 | for my $i (@final) { | |||||||||||||||||||||||||||||
| 57 | 14937 | (my $name = $i) =~ s/^!//; | |||||||||||||||||||||||||||||
| 58 | 14937 | ▶ | croak "Unknown symbol '$name' from package '$self'" unless defined(&{"${self}::$name"}) or exists $found_symbols->{$name}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined &{"${self}::$name";} or exists $found_symbols->{$name}
MC/DC0%0/2
defined &{"${self}::$name";} or exists $found_symbols->{$name}
defined &{"${self}::$name";}
exists $found_symbols->{$name}
Truth table33%1/3
A or B
A= defined &{"${self}::$name";}B= exists $found_symbols->{$name}
| |||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||
| 60 | 1338 | @final; | |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | 14828 | ▶ | sub export { | ||||||||||||||||||||||||||||
|
Subroutine
export: called CC=18 SCAR=48.4
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 64 | 14828 | my $self = shift; | |||||||||||||||||||||||||||||
| 65 | 14828 | my ($from, $symbol, $to) = (shift, shift, shift); | |||||||||||||||||||||||||||||
| 66 | 14828 | my $sigil = '&'; | |||||||||||||||||||||||||||||
| 67 | 0 | $symbol =~ s/^(:|\&|\$|\%|\@|\*)/$sigil = $1; ''/e; | |||||||||||||||||||||||||||||
| 68 | 14828 | ▶ | croak "Unknown symbol type for expression '$symbol' in EXPORT" if $symbol =~ /^\W/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 69 | 30 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 70 | 30 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 71 | 14828 | ▶ | if ($sigil eq ':') { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 72 | 0 | my $tags = \%{"${from}::EXPORT_TAGS"}; | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if (not exists $tags->{$symbol}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 74 | 0 | croak "Export tag '$symbol' is not defined in package $from"; | |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | unless (ref($tags->{$symbol}) eq 'ARRAY') { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 77 | 0 | croak "Export tags should contain array refs"; | |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||
| 79 | 0 | for my $i (@{$tags->{$symbol}}) { | |||||||||||||||||||||||||||||
| 80 | 0 | $self->export($from, $i, $to); | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||
| 82 | } elsif ($sigil eq '&') { | ||||||||||||||||||||||||||||||
| 83 | 14828 | ▶ | if (not defined *{"${from}::$symbol"}{CODE}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 84 | 0 | eval "sub ${from}::$symbol"; ## no critic | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | croak "Cannot create symbol for sub ${from}::$symbol: $@" if $@; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||
| 87 | 14828 | ▶ | if (not $exports->{$to}->{$symbol}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 88 | 14768 | ▶ | if (defined *{"${to}::$symbol"}{CODE}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 89 | 0 | croak "Cannot define symbol &${to}::$symbol: symbol is already defined under the same namespace and name"; | |||||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||||
| 91 | 14768 | *{"${to}::$symbol"} = *{"${from}::$symbol"}{CODE}; | |||||||||||||||||||||||||||||
| 92 | 14768 | $exports->{$to}->{$symbol}++; | |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||
| 95 | } elsif ($sigil eq '$') { | ||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if (not defined *{"${from}::$symbol"}{SCALAR}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 97 | 0 | ${"${from}::$symbol"} = undef; | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||
| 99 | 0 | *{"${to}::$symbol"} = *{"${from}::$symbol"}{SCALAR}; | |||||||||||||||||||||||||||||
| 100 | } elsif ($sigil eq '@') { | ||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (not defined *{"${from}::$symbol"}{ARRAY}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 102 | 0 | @{"${from}::$symbol"} = (); | |||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||
| 104 | 0 | *{"${to}::$symbol"} = *{"${from}::$symbol"}{ARRAY}; | |||||||||||||||||||||||||||||
| 105 | } elsif ($sigil eq '%') { | ||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if (not defined *{"${from}::$symbol"}{HASH}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 107 | 0 | %{"${from}::$symbol"} = (); | |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||
| 109 | 0 | *{"${to}::$symbol"} = *{"${from}::$symbol"}{HASH}; | |||||||||||||||||||||||||||||
| 110 | } elsif ($sigil eq '*') { | ||||||||||||||||||||||||||||||
| 111 | 0 | *{"${to}::$symbol"} = *{"${from}::$symbol"}; | |||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||
| 113 | 0 | croak "I don't know how to handle '$symbol' in EXPORT"; | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | 30 | 1; | |||||||||||||||||||||||||||||