Yath/Option/BoolMap.pm untested

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