Yath/Option/BoolMap.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 91 CC 6 SCAR 17.6
CC
6
Cov
0%
custom_matches
20.0
requires_arg
6.0
init
6.0
CRAP 5.8
1 use warnings;
2  
3 our $VERSION = '2.000007';
4  
5 use Carp qw/croak/;
6  
7 use parent 'Getopt::Yath::Option::Map';
8 use Getopt::Yath::HashBase qw/+pattern +requires_arg +custom_matches/;
9  
10 sub allows_list { 1 }
11 sub allows_default { 1 }
12 sub allows_arg { 1 }
13 sub allows_autofill { 0 }
14 sub requires_autofill { 0 }
15  
16 sub notes { (shift->SUPER::notes(), 'Can be specified multiple times') }
17  
18 sub requires_arg { $_[0]->{+REQUIRES_ARG} ? 1 : 0 }
19  
20 sub init {
21 my $self = shift;
22 $self->SUPER::init(@_);
23  
24 croak "A 'pattern' is required" unless $self->{+PATTERN};
25  
26 return $self;
27 }
28  
29 sub no_arg_value { $_[0]->field, 1 }
30  
31 sub pattern {
32 my $self = shift;
33  
34 my $append = $self->{+PATTERN};
35 return qr/^--(no-)?$append$/;
36 }
37  
38 sub default_long_examples {
39 my $self = shift;
40 my $out = $self->SUPER::default_long_examples(@_);
41 push @$out => $self->pattern;
42 return $out;
43 }
44  
45 sub default_short_examples {
46 my $self = shift;
47 my $out = $self->SUPER::default_short_examples(@_);
48 push @$out => $self->pattern;
49 return $out;
50 }
51  
52 sub custom_matches {
53 my $self = shift;
54 my $pattern = $self->pattern;
55  
56 return sub {
57 my ($input, $state) = @_;
58  
59 return $self->{+CUSTOM_MATCHES}->($self, @_)
60 if $self->{+CUSTOM_MATCHES};
61  
62 return unless $input =~ $pattern;
63 my ($no, $key) = ($1, $2);
64 return ($self, 1, [$key => $no ? 0 : 1]);
65 };
66 }
67  
68 sub doc_forms {
69 my $self = shift;
70 my %params = @_;
71  
72 my ($forms, $no_forms) = $self->SUPER::doc_forms(%params);
73  
74 my $inner = "" . $self->{+PATTERN};
75 $inner =~ s{^\Q(?^:\E}{};
76 $inner =~ s{\)$}{};
77  
78 return ($forms, $no_forms, ["/^--(no-)?$inner\$/"]);
79 }
80  
81 1;
82  
83 __END__