| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 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 // ""
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||
| 43 | 1409 | ▶ | return $class if defined $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 5 | ▶ | my $problem = sprintf("unknown %s '%s' (known: %s)", $kind, $name // '', join(', ', $self->knownNames)); | ||||||||||||||||||||||||||
|
Condition50%1/2
$name // ""
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||
| 46 | 5 | ▶ | specError('%s', defined $owner ? sprintf('%s: %s', $owner, $problem) : $problem); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||