blib/lib/Evo/Export/Meta.pm

filter: Statementstmt 27.9% 24 / 86 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 33.3% 7 / 21 Podpod 0.0% 0 / 14 totaltotal 18.3% 31 / 169 CC 22 SCAR 25.8
CC
22
Cov
19%
expand_wildcards
42.0
request
23.5
export_proxy
12.0
CRAP 13.2
« blib/lib/Test/Evo/Benchmark.pm ↑ Summary blib/lib/Evo/Test/Call.pm »
1 package Evo::Export::Meta;
2 43 ▶use Evo 'Evo::Internal::Util; Carp croak; Module::Load load';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 43 our @CARP_NOT = qw(Evo Evo::Export Evo::Internal::Util);
5  
6 0 ▶sub package($self) { $self->{package} }
Subroutine package: not called CC=1 SCAR=6.9
Pod undocumented
7 0 ▶sub symbols($self) { $self->{symbols} //= {} }
Subroutine symbols: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
$self->{"symbols"} //= {}
l!l
00
MC/DC0%0/1
$self->{"symbols"} //= {}
$self->{"symbols"}
Truth table0%0/2
A
A= $self->{"symbols"}
Aresult
11
00
8  
9 0 ▶sub new ($me, $pkg, %opts) {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
10 0 ▶ $me = ref($me) if ref $me;
Branch: 1 branch
BranchTrueFalseTotal
if ref $me 0 0 0
11 0 bless {%opts, package => $pkg}, $me;
12 }
13  
14 0 ▶sub find_or_bind_to ($me, $pkg, %opts) {
Subroutine find_or_bind_to: not called CC=2 SCAR=8.7
Pod undocumented
15 43 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
16 43 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 0 ▶ ${"${pkg}::EVO_EXPORT_META"} ||= $me->new($pkg, %opts);
Condition0%0/3
${"${pkg}::EVO_EXPORT_META";} ||= $me->new($pkg, %opts)
l!l&&r!l&&!r
000
MC/DC0%0/2
${"${pkg}::EVO_EXPORT_META";} ||= $me->new($pkg, %opts)
${"${pkg}::EVO_EXPORT_META";} $me->new($pkg, %opts)
Truth table0%0/3
A ||= B
A= ${"${pkg}::EVO_EXPORT_META";}B= $me->new($pkg, %opts)
ABresult
1X1
011
000
18 }
19  
20 # it's important to return same function for the same module
21 # we're storing it in the module, not in slot, to be able to easy destroy a module
22 0 ▶sub request ($self, $name, $dpkg) {
Subroutine request: not called CC=6 SCAR=31.6
Pod undocumented
23 0 my $slot = $self->find_slot($name);
24 0 my $fn;
25 0 my $type = $slot->{type};
26 0 ▶ if ($type eq 'code') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'code') { } 0 0 0
elsif ($type eq 'gen') { } 0 0 0
27 0 $fn = $slot->{code};
28 }
29 elsif ($type eq 'gen') {
30 43 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 43 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
32 0 my $pkg = $self->package;
33 0 ▶ my $cache = ${"${dpkg}::EVO_EXPORT_CACHE"} ||= {};
Condition0%0/2
${"${dpkg}::EVO_EXPORT_CACHE";} ||= {}
l!l
00
MC/DC0%0/1
${"${dpkg}::EVO_EXPORT_CACHE";} ||= {}
${"${dpkg}::EVO_EXPORT_CACHE";}
Truth table0%0/2
A
A= ${"${dpkg}::EVO_EXPORT_CACHE";}
Aresult
11
00
34 0 ▶ return $cache->{$pkg}{$name} if $cache->{$pkg}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $cache->{$pkg}{$name} 0 0 0
35 0 return $cache->{$pkg}{$name} = $slot->{gen}->($self->package, $dpkg);
36 }
37  
38 0 ▶ croak "Something wrong" unless $fn;
Branch: 1 branch
BranchTrueFalseTotal
unless $fn 0 0 0
39 0 return $fn;
40 }
41  
42 # traverse to find gen via links, return Module, name, gen
43 0 ▶sub find_slot ($self, $name) {
Subroutine find_slot: not called CC=2 SCAR=17.9
Pod undocumented
44 0 ▶ croak qq{"${\$self->package}" doesn't export "$name"} unless my $slot = $self->symbols->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless my $slot = $self->symbols->{$name} 0 0 0
45 }
46  
47 0 ▶sub init_slot ($self, $name, $val) {
Subroutine init_slot: not called CC=2 SCAR=17.9
Pod undocumented
48 0 my $pkg = $self->package;
49 0 ▶ croak "$pkg already exports $name" if $self->symbols->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->symbols->{$name} 0 0 0
50 0 $self->symbols->{$name} = $val;
51 }
52  
53 0 ▶sub export_from ($self, $name, $origpkg, $origname) {
Subroutine export_from: not called CC=1 SCAR=6.9
Pod undocumented
54 0 my $slot = $self->find_or_bind_to($origpkg)->find_slot($origname);
55 0 $self->init_slot($name, $slot);
56 }
57  
58 0 ▶sub export_gen ($self, $name, $gen) {
Subroutine export_gen: not called CC=1 SCAR=6.9
Pod undocumented
59 0 $self->init_slot($name, {gen => $gen, type => 'gen'});
60 }
61  
62 0 ▶sub export_code ($self, $name, $sub) {
Subroutine export_code: not called CC=1 SCAR=6.9
Pod undocumented
63 0 $self->init_slot($name, {type => 'code', code => $sub});
64 }
65  
66 0 ▶sub export ($self, $name_as) {
Subroutine export: not called CC=3 SCAR=20.3
Pod undocumented
67 0 my $pkg = $self->package;
68 0 my ($name, $as) = split ':', $name_as;
69 0 ▶ $as ||= $name;
Condition0%0/3
$as ||= $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$as ||= $name
$as $name
Truth table0%0/3
A ||= B
A= $asB= $name
ABresult
1X1
011
000
70 0 my $full = "${pkg}::$name";
71 43 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
72 0 ▶ my $sub = *{$full}{CODE} or croak "Subroutine $full doesn't exists";
Branch: 1 branch
BranchTrueFalseTotal
my $sub = *{$full;}{"CODE"} or croak("Subroutine $full doesn't exists") 0 0 0
73 0 $self->export_code($as, $sub);
74 }
75  
76  
77 0 ▶sub export_proxy ($self, $origpkg, @xlist) {
Subroutine export_proxy: not called CC=3 SCAR=24.8
Pod undocumented
78 0 $origpkg = Evo::Internal::Util::resolve_package($self->package, $origpkg);
79 0 load $origpkg;
80 0 my @list = $self->find_or_bind_to($origpkg)->expand_wildcards(@xlist);
81  
82 0 foreach my $name_as (@list) {
83 0 my ($origname, $name) = split ':', $name_as;
84 0 ▶ $name ||= $origname;
Condition0%0/3
$name ||= $origname
l!l&&r!l&&!r
000
MC/DC0%0/2
$name ||= $origname
$name $origname
Truth table0%0/3
A ||= B
A= $nameB= $origname
ABresult
1X1
011
000
85 0 $self->export_from($name, $origpkg, $origname);
86 }
87 }
88  
89  
90 0 ▶sub expand_wildcards ($self, @list) {
Subroutine expand_wildcards: not called CC=6 SCAR=37.4
Pod undocumented
91 0 my %symbols = $self->symbols->%*;
92 0 my (%minus, %res);
93 0 foreach my $cur (@list) {
94 0 ▶ if ($cur eq '*') {
Branch: 2 branches
BranchTrueFalseTotal
if ($cur eq '*') { } 0 0 0
elsif ($cur =~ /^-(.+)/u) { } 0 0 0
95 0 ▶ croak "${\$self->package} exports nothing" unless %symbols;
Branch: 1 branch
BranchTrueFalseTotal
unless %symbols 0 0 0
96 0 $res{$_}++ for keys %symbols;
97 }
98 elsif ($cur =~ /^-(.+)/) {
99 0 $minus{$1}++;
100 }
101 else {
102 0 $res{$cur}++;
103 }
104 }
105 0 return (sort grep { !$minus{$_} } keys %res);
106 }
107  
108 0 ▶sub install ($self, $dst, @xlist) {
Subroutine install: not called CC=3 SCAR=24.8
Pod undocumented
109 0 my @list = $self->expand_wildcards(@xlist);
110  
111 0 my $liststr = join '; ', @list;
112 0 my $exporter = $self->package;
113  
114 0 my %patch;
115 0 foreach my $name_as (@list) {
116 0 my ($name, $as) = split ':', $name_as;
117 0 ▶ $as ||= $name;
Condition0%0/3
$as ||= $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$as ||= $name
$as $name
Truth table0%0/3
A ||= B
A= $asB= $name
ABresult
1X1
011
000
118 0 my $fn = $self->request($name, $dst);
119 0 $patch{$as} = $fn;
120 }
121 0 Evo::Internal::Util::monkey_patch $dst, %patch;
122 }
123  
124 43 ▶no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
125 43 *info = *symbols;
126  
127 43 1;
128  
129 __END__
« blib/lib/Test/Evo/Benchmark.pm ↑ Summary blib/lib/Evo/Test/Call.pm »