Pad/Registry.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 10 / 10 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 94.9% 75 / 79 CC 12 SCAR 16.1
CC
12
Cov
97%
register
7.0
resolve
6.1
BEGIN
1.0
CRAP 5.0
« Pad/Util.pm ↑ Summary Pad/Help.pm »
1 12 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 12 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 class Getopt::Pad::Registry {
5 12 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶ use Getopt::Pad::Util qw(specError);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 our $VERSION = '0.06';
9  
10 # Registration errors are reported at the registerType/registerFormat
11 # caller, not inside those one-line forwarders.
12 12 our @CARP_NOT = qw(Getopt::Pad::Type Getopt::Pad::Config::Format);
13  
14 12 field $kind :param;
15 12 field %entries;
16  
17 20 ▶ method register(@classes) {
Subroutine register: called CC=7 SCAR=19.5
Pod documented
18 20 foreach my $class (@classes) {
19 # A class the program already defines is taken as it is, so a
20 # missing NAMES is reported as that, not as a missing file.
21 124 ▶ if (!$class->can('new')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->can("new")) 78 46 124
22 78 (my $file = "$class.pm") =~ s{::}{/}g;
23 78 require $file;
24 }
25 124 ▶ croak sprintf('Getopt::Pad: %s class %s does not provide a NAMES list', $kind, $class) unless $class->can('NAMES');
Branch: 1 branch
BranchTrueFalseTotal
unless $class->can("NAMES") 1 123 124
26  
27 # Registering a class again is harmless; taking a name away from
28 # another class is not, so it fails instead of silently winning.
29 123 foreach my $name (map { lc } $class->NAMES->@*) {
30 257 my $owner = $entries{$name};
31 257 ▶ croak sprintf("Getopt::Pad: %s name '%s' is already registered by %s", $kind, $name, $owner) if defined $owner && $owner ne $class;
Branch: 1 branch
BranchTrueFalseTotal
if defined $owner and $owner ne $class 1 256 257
Condition100%3/3
defined $owner and $owner ne $class
!ll&&!rl&&r
25511
MC/DC100%2/2
defined $owner and $owner ne $class
defined $owner $owner ne $class
Truth table100%3/3
A and B
A= defined $ownerB= $owner ne $class
ABresult
0X0
100
111
32 256 $entries{$name} = $class;
33 }
34 }
35  
36 18 return $self;
37 12 }
38  
39 # An unknown name is reported for $owner (e.g. "option 'retries'") when
40 # one is given.
41 1409 ▶ method resolve($name, $owner = undef) {
Subroutine resolve: called CC=6 SCAR=18.0
Pod documented
42 1409 ▶ my $class = $entries{lc($name // '')};
Condition50%1/2
$name // ""
l!l
14090
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
43 1409 ▶ return $class if defined $class;
Branch: 1 branch
BranchTrueFalseTotal
if defined $class 1404 5 1409
44  
45 5 ▶ my $problem = sprintf("unknown %s '%s' (known: %s)", $kind, $name // '', join(', ', $self->knownNames));
Condition50%1/2
$name // ""
l!l
50
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
46 5 ▶ specError('%s', defined $owner ? sprintf('%s: %s', $owner, $problem) : $problem);
Branch: 1 branch
BranchTrueFalseTotal
defined $owner ? : 3 2 5
47 12 }
48  
49 5 ▶ method knownNames() {
Subroutine knownNames: called CC=1 SCAR=0.0
Pod documented
50 5 return sort keys %entries;
51 12 }
52 }
53  
54 12 1;
55  
56 __END__
« Pad/Util.pm ↑ Summary Pad/Help.pm »