| 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.04'; | |||||||||||||||||||||||||||
| 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 | 19 | ▶ | method register(@classes) { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 19 | foreach my $class (@classes) { | |||||||||||||||||||||||||||
| 19 | 103 | ▶ | if (!$class->can('NAMES')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 58 | (my $file = "$class.pm") =~ s{::}{/}g; | |||||||||||||||||||||||||||
| 21 | 58 | require $file; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | 103 | ▶ | croak sprintf('Getopt::Pad: %s class %s does not provide a NAMES list', $kind, $class) unless $class->can('NAMES'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # Registering a class again is harmless; taking a name away from | ||||||||||||||||||||||||||||
| 26 | # another class is not, so it fails instead of silently winning. | ||||||||||||||||||||||||||||
| 27 | 103 | foreach my $name (map { lc } $class->NAMES->@*) { | |||||||||||||||||||||||||||
| 28 | 237 | my $owner = $entries{$name}; | |||||||||||||||||||||||||||
| 29 | 237 | ▶ | croak sprintf("Getopt::Pad: %s name '%s' is already registered by %s", $kind, $name, $owner) if defined $owner && $owner ne $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $owner and $owner ne $class
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
| |||||||||||||||||||||||||||||
| 30 | 236 | $entries{$name} = $class; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 18 | return $self; | |||||||||||||||||||||||||||
| 35 | 12 | } | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1247 | ▶ | method resolve($name) { | ||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 1247 | ▶ | my $class = $entries{lc($name // '')}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$name // ""
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||
| 39 | 1247 | ▶ | specError("unknown %s '%s' (known: %s)", $kind, $name // '', join(', ', $self->knownNames)) unless defined $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$name // ""
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1242 | return $class; | |||||||||||||||||||||||||||
| 42 | 12 | } | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5 | ▶ | method knownNames() { | ||||||||||||||||||||||||||
|
Subroutine
knownNames: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 5 | return sort keys %entries; | |||||||||||||||||||||||||||
| 46 | 12 | } | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 12 | 1; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | __END__ | ||||||||||||||||||||||||||||