blib/lib/Keyword/Pluggable.pm

filter: Statementstmt 90.9% 50 / 55 Branchbran 65.0% 13 / 20 Conditioncond 64.7% 11 / 17 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 79.8% 91 / 114 CC 18 SCAR 21.9
CC
18
Cov
80%
define
14.5
undefine
7.7
BEGIN
1.0
CRAP 8.9
↑ Summary Pluggable.xs »
1 package Keyword::Pluggable;
2  
3 7 ▶use v5.14.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 our %kw;
6  
7 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 our $VERSION = '1.05';
12 7 XSLoader::load __PACKAGE__, $VERSION;
13 }
14  
15 7 my %modes = (
16 'statement' => MODE_STATEMENT,
17 'expression' => MODE_EXPRESSION,
18 'dynamic' => MODE_DYNAMIC,
19 );
20  
21 9 ▶sub define {
Subroutine define: called CC=14 SCAR=26.7
Pod documented
22 9 my %p = @_;
23 9 my ($kw, $sub, $expression, $global, $package) = @p{qw(keyword code expression global package)};
24 9 ▶ $kw =~ /^\p{XIDS}\p{XIDC}*\z/ or croak "'$kw' doesn't look like an identifier";
Branch: 1 branch
BranchTrueFalseTotal
$kw =~ /^\p{XIDS}\p{XIDC}*\z/u or croak("'${kw}' doesn't look like an identifier") 9 0 9
25 9 ▶ defined($sub) or croak "'code' is not defined";
Branch: 1 branch
BranchTrueFalseTotal
defined $sub or croak("'code' is not defined") 9 0 9
26 9 ▶ $expression //= 'statement';
Condition100%2/2
$expression //= "statement"
l!l
72
MC/DC100%1/1
$expression //= "statement"
$expression
Truth table100%2/2
A
A= $expression
Aresult
11
00
27 9 ▶ my $sub_is_code = (ref($sub) and
Condition50%3/6
ref $sub && (UNIVERSAL::isa($sub, 'CODE') || $sub->isa('CODE'))
!ll&&!rl&&r
603
UNIVERSAL::isa($sub, "CODE") or $sub->isa("CODE")
l!l&&r!l&&!r
300
MC/DC33%1/3
ref $sub && (UNIVERSAL::isa($sub, 'CODE') || $sub->isa('CODE'))
ref $sub UNIVERSAL::isa($sub, "CODE") $sub->isa("CODE")
Truth table50%2/4
A && B or C
A= ref $subB= UNIVERSAL::isa($sub, "CODE")C= $sub->isa("CODE")
ABCresult
0XX0
1000
11X1
1011
28 (UNIVERSAL::isa($sub, 'CODE') or
29 $sub->isa('CODE')));
30 9 ▶ $sub_is_code or $expression ne 'dynamic' or croak("expression=dynamic requires a coderef");
Branch: 1 branch
BranchTrueFalseTotal
$sub_is_code or $expression ne "dynamic" or croak("expression=dynamic requires a coderef") 9 0 9
Condition66%2/3
$sub_is_code or $expression ne "dynamic"
l!l&&r!l&&!r
360
MC/DC0%0/2
$sub_is_code or $expression ne "dynamic"
$sub_is_code $expression ne "dynamic"
Truth table66%2/3
A or B
A= $sub_is_codeB= $expression ne "dynamic"
ABresult
1X1
011
000
31  
32 9 ▶ my $xsub = $sub_is_code ? $sub : sub { substr ${$_[0]}, 0, 0, $sub };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$sub_is_code ? : 3 6 9
33  
34 my $entry = [ $xsub,
35 9 ▶ ($modes{$expression} //
Branch: 1 branch
BranchTrueFalseTotal
$expression ? : 3 3 6
Condition100%2/2
$modes{$expression} // ($expression ? 1 : 0)
l!l
36
MC/DC100%1/1
$modes{$expression} // ($expression ? 1 : 0)
$modes{$expression}
Truth table100%2/2
A
A= $modes{$expression}
Aresult
11
00
36 ($expression? MODE_EXPRESSION: MODE_STATEMENT)) ];
37  
38 9 ▶ if ( defined $package) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $package) { } 2 7 9
elsif ($global) { } 2 5 7
39 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 my $keywords = \%{$package . '::/keywords' };
41 2 $keywords->{$kw} = $entry;
42 } elsif ( $global ) {
43 2 define_global($kw, $entry);
44 } else {
45 5 ▶ my %keywords = %{$^H{+HINTK_KEYWORDS} // {}};
Condition100%2/2
$^H{"Keyword::Pluggable/keywords"} // {}
l!l
14
MC/DC100%1/1
$^H{"Keyword::Pluggable/keywords"} // {}
$^H{"Keyword::Pluggable/keywords"}
Truth table100%2/2
A
A= $^H{"Keyword::Pluggable/keywords"}
Aresult
11
00
46 5 $keywords{$kw} = $entry;
47 5 $^H{+HINTK_KEYWORDS} = \%keywords;
48 }
49 }
50  
51 1 ▶sub undefine {
Subroutine undefine: called CC=5 SCAR=20.5
Pod documented
52 1 my %p = @_;
53 1 my ($kw, $global, $package) = @p{qw(keyword global package)};
54 1 ▶ $kw =~ /^\p{XIDS}\p{XIDC}*\z/ or croak "'$kw' doesn't look like an identifier";
Branch: 1 branch
BranchTrueFalseTotal
$kw =~ /^\p{XIDS}\p{XIDC}*\z/u or croak("'${kw}' doesn't look like an identifier") 1 0 1
55  
56 1 ▶ if ( defined $package ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $package) { } 1 0 1
elsif ($global) { } 0 0 0
57 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 my $keywords = \%{$package . '::/keywords' };
59 1 delete $keywords->{$kw};
60 } elsif ( $global ) {
61 0 undefine_global($kw);
62 } else {
63 0 ▶ my %keywords = %{$^H{+HINTK_KEYWORDS} // {}};
Condition0%0/2
$^H{"Keyword::Pluggable/keywords"} // {}
l!l
00
MC/DC0%0/1
$^H{"Keyword::Pluggable/keywords"} // {}
$^H{"Keyword::Pluggable/keywords"}
Truth table0%0/2
A
A= $^H{"Keyword::Pluggable/keywords"}
Aresult
11
00
64 0 delete $keywords{$kw};
65 0 $^H{+HINTK_KEYWORDS} = \%keywords;
66 }
67 }
68  
69 7 ▶END { cleanup() }
Subroutine END: called CC=1 SCAR=0.0
70  
71 7 'ok'
72  
73 __END__
↑ Summary Pluggable.xs »