| 1 | package CXC::Form::Tiny::Plugin::OptArgs2::Meta; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Form metaclass role for OptArgs2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Clone (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Ref::Util qw( is_plain_hashref is_arrayref is_regexpref is_ref ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Form::Tiny::Utils 'get_package_form_meta'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | use Types::Standard | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | qw( ArrayRef Bool CodeRef Dict Enum Int Optional RegexpRef Str Tuple Undef Value ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use Type::Params qw( signature_for ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use Types::Common::String qw ( NonEmptySimpleStr NonEmptyStr ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | ▶ | use experimental 'signatures', 'postderef', 'lexical_subs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my sub croak { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
croak: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | goto \&Carp::croak; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # need to stash which form this field was added to in order to handle | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # inheritance of inherited fields which aren't options, but which | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # contain nested forms which *are* options. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 39 | ▶ | around add_field => sub ( $orig, $self, @parameters ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # this may return either a FieldDefinition or a FieldDefinition, but | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # in either case, it has an addons methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 39 | my $field = $self->$orig( @parameters ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 39 | $field->addons->{ +__PACKAGE__ }{package} = $self->package; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 39 | return $field; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | has inherit_required => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | builder => sub { !!1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_inherit_required: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | has inherit_optargs => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 13 | ▶ | builder => sub { !!0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_inherit_optargs: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | has inherit_optargs_match => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | isa => Undef | ArrayRef [ Tuple [ Bool, RegexpRef ] ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | builder => sub { undef }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | has nested_path_sep => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 15 | ▶ | builder => sub { '_' }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_nested_path_sep: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | has _optargs => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ## no critic (Subroutines::ProtectPrivateSubs ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 9 | ▶ | builder => sub ( $self ) { $self->_build_opt_args->_optargs }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 10 | ▶ | sub optargs ( $self ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optargs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 10 | return Clone::clone( $self->_optargs ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | has rename => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | builder => sub ( $self ) { $self->_build_opt_args->rename }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | ▶ | sub rename_options ( $self, $opt ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rename_options: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | my $rename = $self->rename; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | for my $from ( keys $opt->%* ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 20 | my $to = $rename->{$from}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 20 | ▶ | croak( "unexpected option key: $from\n" ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | if !defined $to; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 20 | $opt->{$to} = delete $opt->{$from}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | ▶ | sub inflate_optargs ( $self, $optargs ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inflate_optargs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | state $folder = do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | require Hash::Fold; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | Hash::Fold->new( delimiter => chr( 0 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # make a copy of the flattened hash | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | my %flat = $optargs->%*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # translate the OptArgs names into that required by the Form::Tiny structure | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 2 | $self->rename_options( \%flat ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | return $folder->unfold( \%flat ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 10 | ▶ | sub _build_opt_args ( $self ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_opt_args: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 10 | my %rename; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | my @optargs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 10 | for my $aref ( $self->_create_options( \%rename )->@* ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 52 | my ( $name, $spec ) = $aref->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 52 | my %spec = $spec->%*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 52 | delete $spec{order}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 52 | push @optargs, $name, \%spec; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 10 | $self->_set__optargs( \@optargs ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 10 | $self->_set_rename( \%rename ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 18 | ▶ | my sub _match_inherit_optargs ( $matches, $package ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_match_inherit_optargs: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 18 | my $excluded = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 18 | for my $match ( $matches->@* ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 26 | my ( $retval, $qr ) = $match->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 26 | ▶ | return $retval if $package =~ $qr; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 16 | ▶ | $excluded++ unless $retval; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # if no exclusions, then user forgot to add the exclude all | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # catch-all at the end. just having inclusions doesn't make | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # sense. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 8 | return $excluded != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 89 | ▶ | sub _inherit_optargs ( $self, $package ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inherit_optargs: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 89 | ▶ | return $package eq $self->package | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/9
$package eq $self->package || $self->inherit_optargs && (!defined($self->inherit_optargs_match) || _match_inherit_optargs($self->inherit_optargs_match, $package))
$self->inherit_optargs and !defined($self->inherit_optargs_match) || _match_inherit_optargs($self->inherit_optargs_match, $package)
not defined $self->inherit_optargs_match or _match_inherit_optargs $self->inherit_optargs_match, $package
MC/DC100%4/4
$package eq $self->package || $self->inherit_optargs && (!defined($self->inherit_optargs_match) || _match_inherit_optargs($self->inherit_optargs_match, $package))
$package eq $self->package
$self->inherit_optargs
not defined $self->inherit_optargs_match
_match_inherit_optargs $self->inherit_optargs_match, $package
Truth table100%5/5
A || B and not(C) or D
A= $package eq $self->packageB= $self->inherit_optargsC= not defined $self->inherit_optargs_matchD= _match_inherit_optargs $self->inherit_optargs_match, $package
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | || ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | $self->inherit_optargs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | && ( !defined $self->inherit_optargs_match | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | || _match_inherit_optargs( $self->inherit_optargs_match, $package ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | ## no critic( ValuesAndExpressions::ProhibitImplicitNewlines ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | ## no critic( Subroutines::ProhibitManyArgs ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 27 | ▶ | sub _create_options ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_options: called CC=22 SCAR=34.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | $self, $rename, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 27 | $path = [], | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 27 | $opt_path = [], | |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 27 | $blueprint = $self->blueprint( recurse => 0 ), | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 27 | my @optargs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 27 | for my $field ( sort keys $blueprint->%* ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 93 | my $def = $blueprint->{$field}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 93 | ▶ | if ( is_plain_hashref( $def ) || ( my $is_subform = $def->is_subform ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
Ref::Util::XS::is_plain_hashref($def) or my $is_subform = $def->is_subform
MC/DC100%2/2
Ref::Util::XS::is_plain_hashref($def) or my $is_subform = $def->is_subform
Ref::Util::XS::is_plain_hashref($def)
my $is_subform = $def->is_subform
Truth table100%3/3
A or B
A= Ref::Util::XS::is_plain_hashref($def)B= my $is_subform = $def->is_subform
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # Normally a sub-form's options get a prefix based on the field name, e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # db.opts => --db-opts. Sometimes the extra levels are overkill for the option names, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # so if the options entry contains 'name' specification, use that for the prefix. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # unfortunately if the field name is nested, we only get here at the bottom of the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # hierarchy, so need to backtrack. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 23 | my @paths = ( [ $path->@*, $field ], [ $opt_path->@*, $field ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 23 | ▶ | if ( $is_subform ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 19 | ▶ | my $addons = $def->addons->{ +__PACKAGE__ } // croak( 'no addons for field ' . $def->name ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$def->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"} // croak('no addons for field ' . $def->name)
MC/DC0%0/2
$def->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"} // croak('no addons for field ' . $def->name)
$def->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"}
croak('no addons for field ' . $def->name)
Truth table33%1/3
A // B
A= $def->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"}B= croak('no addons for field ' . $def->name)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # bail if we're not inheriting | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 19 | ▶ | next unless $self->_inherit_optargs( $addons->{package} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 13 | ▶ | if ( defined( my $name = ( $addons->{optargs} // {} )->{name} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$addons->{"optargs"} // {}
MC/DC0%0/1
$addons->{"optargs"} // {}
$addons->{"optargs"}
Truth table50%1/2
A
A= $addons->{"optargs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ( my @fixup = $opt_path->@* ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my @comp = split( /[.]/, $def->name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | splice( @fixup, @fixup - @comp, @comp, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # replace default opt_path | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $paths[-1] = \@fixup; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $paths[-1] = [$name]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 13 | push @optargs, get_package_form_meta( blessed $def->type )->_create_options( $rename, @paths )->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 4 | push @optargs, $self->_create_options( $rename, @paths, $def )->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 70 | ▶ | my $addons = $def->addons->{ +__PACKAGE__ } // croak( 'no addons for field ' . $def->name ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$def->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"} // croak('no addons for field ' . $def->name)
MC/DC0%0/2
$def->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"} // croak('no addons for field ' . $def->name)
$def->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"}
croak('no addons for field ' . $def->name)
Truth table33%1/3
A // B
A= $def->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"}B= croak('no addons for field ' . $def->name)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 70 | ▶ | next unless defined( my $orig_optargs = $addons->{optargs} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | croak( "optargs initialized, but no option or argument specification for field $field?" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 70 | ▶ | if !defined $orig_optargs->{spec}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 70 | my $optargs = $orig_optargs->{spec}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # This bit deals with creating the option name and then mapping it back onto the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # Form::Tiny blueprint for the form, which may introduce extra layers in the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # nested hash if the field name has multiple components. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # Special cases arise: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # 1) multi-component field name, e.g. 'output.parsed' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # 2) options name ne field name, e.g. '--raw-output' ne 'output.raw'. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # 3) field name has an underscore, which can get confused | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # when the options are unflattened, as underscore is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # used to indicated nested structures | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # if @path > 1, then a multi-component name was given to form_field. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # Form::Tiny doesn't keep track of sub-forms' parents, so it doesn't know | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # so we keep track of the entire path via $path. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # we only need the last component to get the (leaf) form field name. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 70 | my $field_name = $def->get_name_path->path->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # this is the fully qualified normalized field name, with | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # components separated by NUL and will be used create the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # correct hierarchy when the options hash is unflattened. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 70 | my $fq_field_name = join( chr( 0 ), $path->@*, $field_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # generate the fully qualified option name using the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # specified field name. the field may specify an | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # alternate option name, so use that if specified. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 70 | ▶ | my $fq_option_name = $optargs->{name} // join( $self->nested_path_sep, $opt_path->@*, $field_name ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$optargs->{"name"} // join($self->nested_path_sep, @$opt_path, $field_name)
MC/DC100%1/1
$optargs->{"name"} // join($self->nested_path_sep, @$opt_path, $field_name)
$optargs->{"name"}
Truth table100%2/2
A
A= $optargs->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # store the mapping between option name and fully | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # qualified normalized field name. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 70 | ▶ | if ( defined( my $old_rename = $rename->{$fq_option_name} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | croak( "redefined rename of $fq_option_name to $fq_field_name (originally to $old_rename)" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 70 | $rename->{$fq_option_name} = $fq_field_name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | $optargs->{default} = $def->default->() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 70 | ▶ | if $optargs->{show_default} && $def->has_default; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$optargs->{"show_default"} and $def->has_default
MC/DC50%1/2
$optargs->{"show_default"} and $def->has_default
$optargs->{"show_default"}
$def->has_default
Truth table66%2/3
A and B
A= $optargs->{"show_default"}B= $def->has_default
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | push @optargs, [ $fq_option_name, $optargs ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 70 | ▶ | if $self->_inherit_optargs( $addons->{package} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | ## no critic (BuiltinFunctions::RequireSimpleSortBlock) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # no order, pass 'em through | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 74 | ( grep { !defined $_->[1]{order} } @optargs ), | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # order, sort 'em, but complain if multiple arguments with the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # same order, as that is not deterministic | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | my $order = $a->[1]{order} <=> $b->[1]{order}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | ▶ | croak( "$a->[0] and $b->[0] have the same argument order" ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | if $order == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | $order; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 27 | grep { defined $_->[1]{order} } @optargs | |||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | ) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 35 | ▶ | sub _add_optarg ( $self, $field, $spec ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_optarg: called CC=6 SCAR=18.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 35 | ▶ | my $stash = $field->addons->{ +__PACKAGE__ } //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$field->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"} //= {}
MC/DC0%0/1
$field->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"} //= {}
$field->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"}
Truth table50%1/2
A
A= $field->addons->{"CXC::Form::Tiny::Plugin::OptArgs2::Meta"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 35 | ▶ | my $optargs = ( $stash->{optargs} //= {} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$stash->{"optargs"} //= {}
MC/DC0%0/1
$stash->{"optargs"} //= {}
$stash->{"optargs"}
Truth table50%1/2
A
A= $stash->{"optargs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | croak( sprintf( 'duplicate definition for field %s', $field->name ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 35 | ▶ | if defined $optargs->{spec}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 35 | ▶ | $spec->{required} //= !!$field->required | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$spec->{"required"} //= !!$field->required
MC/DC0%0/1
$spec->{"required"} //= !!$field->required
$spec->{"required"}
Truth table50%1/2
A
A= $spec->{"required"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | if $self->inherit_required; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 35 | $optargs->{spec} = $spec; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 35 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 6 | ▶ | use constant OptionTypeEnums => qw( ArrayRef Flag Bool Counter HashRef Int Num Str ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 6 | ▶ | use constant OptionTypeMap => { map { $_ => "--$_" } OptionTypeEnums }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 6 | ▶ | use constant OptionType => Enum( [ values OptionTypeMap->%* ] ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 6 | ▶ | ->plus_coercions( NonEmptySimpleStr, sub { /^--/ ? $_ : "--$_" } ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 6 | ▶ | use constant ArgumentTypeEnums => qw( ArrayRef HashRef Int Num Str SubCmd ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 6 | ▶ | use constant ArgumentType => Enum [ArgumentTypeEnums]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 6 | ▶ | use constant ArgumentTypeMap => { map { $_ => $_ } ArgumentTypeEnums() }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 16 | ▶ | sub _resolve_type ( $field, $type_set ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_type: called CC=8 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # dynamic fields don't have types | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | return undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 16 | ▶ | unless defined $field | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $field and $field->isa("Form::Tiny::FieldDefinition") and $field->has_type
defined $field and $field->isa("Form::Tiny::FieldDefinition")
MC/DC0%0/3
defined $field and $field->isa("Form::Tiny::FieldDefinition") and $field->has_type
defined $field
$field->isa("Form::Tiny::FieldDefinition")
$field->has_type
Truth table25%1/4
A and B and C
A= defined $fieldB= $field->isa("Form::Tiny::FieldDefinition")C= $field->has_type
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | && $field->isa( 'Form::Tiny::FieldDefinition' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | && $field->has_type; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 16 | my $type = $field->type; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # take care of top level Any. Many other types inherit (eventually) from Any, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # so the inheritance scan below will resolve types we don't support | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # if we add Any to OptionTypeMap and ArgumentTypeMap | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | return $type_set->{Str} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 16 | ▶ | if index( '|Any|Path|File|Dir|', q{|} . $type->name . q{|} ) != -1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | return $type_set->{Bool} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 10 | ▶ | if $type->name eq 'BoolLike'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 9 | ▶ | while ( defined $type ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 15 | ▶ | return $type_set->{ $type->name } if exists $type_set->{ $type->name }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 6 | $type = $type->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 10 | signature_for _dsl_add_option => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | method => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | head => 1, # field context | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | bless => !!0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | named => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | name => Optional [NonEmptySimpleStr], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | alias => Optional [NonEmptySimpleStr], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | comment => NonEmptySimpleStr, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | default => Optional [ Value | CodeRef ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | required => Optional [Bool], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | hidden => Optional [Bool], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | isa => Optional [OptionType], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | isa_name => Optional [NonEmptySimpleStr], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | show_default => Optional [Bool], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | trigger => Optional [CodeRef], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | sub _dsl_add_option ( $self, $context, $spec ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 2 | ▶ | croak( q{The 'option' directive must be used after a field definition} ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | if !defined( $context ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 2 | my %spec = $spec->%*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | ▶ | $spec{isa} //= _resolve_type( $context, OptionTypeMap ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$spec{"isa"} //= _resolve_type($context, {"ArrayRef" => "--ArrayRef","Bool" => "--Bool","Counter" => "--Counter","Flag" => "--Flag","HashRef" => "--HashRef","Int" => "--Int","Num" => "--Num","Str" => "--Str"}) // croak(sprintf("'isa' attribute not specified or resolved for %s", $context->name))
_resolve_type($context, {"ArrayRef" => "--ArrayRef","Bool" => "--Bool","Counter" => "--Counter","Flag" => "--Flag","HashRef" => "--HashRef","Int" => "--Int","Num" => "--Num","Str" => "--Str"}) // croak(sprintf("'isa' attribute not specified or resolved for %s", $context->name))
MC/DC0%0/3
$spec{"isa"} //= _resolve_type($context, {"ArrayRef" => "--ArrayRef","Bool" => "--Bool","Counter" => "--Counter","Flag" => "--Flag","HashRef" => "--HashRef","Int" => "--Int","Num" => "--Num","Str" => "--Str"}) // croak(sprintf("'isa' attribute not specified or resolved for %s", $context->name))
$spec{"isa"}
_resolve_type($context, {"ArrayRef" => "--ArrayRef","Bool" => "--Bool","Counter" => "--Counter","Flag" => "--Flag","HashRef" => "--HashRef","Int" => "--Int","Num" => "--Num","Str" => "--Str"})
croak(sprintf("'isa' attribute not specified or resolved for %s", $context->name))
Truth table0%0/4
A //= B // C
A= $spec{"isa"}B= _resolve_type($context, {"ArrayRef" => "--ArrayRef","Bool" => "--Bool","Counter" => "--Counter","Flag" => "--Flag","HashRef" => "--HashRef","Int" => "--Int","Num" => "--Num","Str" => "--Str"})C= croak(sprintf("'isa' attribute not specified or resolved for %s", $context->name))
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | // croak( sprintf( q{'isa' attribute not specified or resolved for %s}, $context->name ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 2 | $self->_add_optarg( $context, \%spec ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 6 | signature_for _dsl_add_argument => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | method => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | head => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | bless => !!0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | named => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | name => Optional [NonEmptySimpleStr], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | comment => NonEmptySimpleStr, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | default => Optional [ Value | CodeRef ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | greedy => Optional [Bool], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | fallthru => Optional [Bool], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | isa => Optional [ArgumentType], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | isa_name => Optional [NonEmptySimpleStr], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | required => Optional [Bool], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | show_default => Optional [Bool], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | order => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | sub _dsl_add_argument ( $self, $context, $spec ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 2 | ▶ | croak( q{The 'argument' directive must be used after a field definition} ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | if !defined( $context ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 2 | my %spec = $spec->%*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 2 | ▶ | $spec{isa} //= _resolve_type( $context, ArgumentTypeMap ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$spec{"isa"} //= _resolve_type($context, {"ArrayRef" => "ArrayRef","HashRef" => "HashRef","Int" => "Int","Num" => "Num","Str" => "Str","SubCmd" => "SubCmd"}) // croak(sprintf("'isa' attribute not specified or resolved for %s", $context->name))
MC/DC0%0/2
$spec{"isa"} //= _resolve_type($context, {"ArrayRef" => "ArrayRef","HashRef" => "HashRef","Int" => "Int","Num" => "Num","Str" => "Str","SubCmd" => "SubCmd"}) // croak(sprintf("'isa' attribute not specified or resolved for %s", $context->name))
$spec{"isa"}
_resolve_type($context, {"ArrayRef" => "ArrayRef","HashRef" => "HashRef","Int" => "Int","Num" => "Num","Str" => "Str","SubCmd" => "SubCmd"}) // croak(sprintf("'isa' attribute not specified or resolved for %s", $context->name))
Truth table33%1/3
A //= B
A= $spec{"isa"}B= _resolve_type($context, {"ArrayRef" => "ArrayRef","HashRef" => "HashRef","Int" => "Int","Num" => "Num","Str" => "Str","SubCmd" => "SubCmd"}) // croak(sprintf("'isa' attribute not specified or resolved for %s", $context->name))
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | // croak( sprintf( q{'isa' attribute not specified or resolved for %s}, $context->name ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 1 | $self->_add_optarg( $context, \%spec ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 6 | ▶ | use constant { INCLUDE => q{+}, EXCLUDE => q{-} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 34 | ▶ | my sub parse_inherit_matches ( $default, $entries ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_inherit_matches: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 34 | my @matches; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 34 | my $include = $default; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 34 | for my $entry ( $entries->@* ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 38 | ▶ | if ( is_arrayref( $entry ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 4 | push @matches, __SUB__->( $include, $entry )->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | elsif ( is_regexpref( $entry ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 9 | push @matches, [ $include eq INCLUDE, $entry ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | ▶ | elsif ( $entry eq EXCLUDE || $entry eq EXCLUDE ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$entry eq "-" or $entry eq "-"
MC/DC0%0/2
$entry eq "-" or $entry eq "-"
$entry eq "-"
$entry eq "-"
Truth table33%1/3
A or B
A= $entry eq "-"B= $entry eq "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 6 | $include = $entry; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 6 | next; # avoid reset of $include to default below | |||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # every thing else is a regexp as a string; turn into a regexp | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | push @matches, [ $include eq INCLUDE, qr/$entry/ ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # reset include to default | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 5 | $include = $default; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 3 | return \@matches; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 6 | signature_for _dsl_optargs_opts => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | method => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | head => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | named => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | inherit_required => Optional [Bool], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | inherit_optargs => Optional [Bool], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | inherit_optargs_match => Optional [ArrayRef], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | nested_path_sep => Optional [Str], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | sub _dsl_optargs_opts ( $self, $context, $args ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | ▶ | croak( q{The 'optargs_opts' directive must be used before any fields are defined} ) | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | if defined( $context ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | ▶ | $self->_set_inherit_required( $args->inherit_required ) | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | if $args->has_inherit_required; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | ▶ | $self->_set_inherit_optargs( $args->inherit_optargs ) | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | if $args->has_inherit_optargs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | ▶ | if ( $args->has_inherit_optargs_match ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | my $match = $args->inherit_optargs_match; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | $match = [$match] unless is_arrayref( $match ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | my $matches = parse_inherit_matches( INCLUDE, $match ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | $self->_set_inherit_optargs_match( $matches ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | $self->_set_nested_path_sep( $args->nested_path_sep ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | if $args->has_nested_path_sep; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # This file is part of CXC-Form-Tiny-Plugin-OptArgs2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # This software is Copyright (c) 2023 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||