| 1 | package Getopt::ArgParse::ActionStore; | ||||||||||||
| 2 | |||||||||||||
| 3 | 20 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 20 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 20 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 20 | ▶ | use Getopt::ArgParse::Parser; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 152 | ▶ | sub apply { | ||||||||||
|
Subroutine
apply: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||
| 10 | 152 | my $self = shift; | |||||||||||
| 11 | |||||||||||||
| 12 | 152 | my ($spec, $namespace, $values) = @_; | |||||||||||
| 13 | 152 | ▶ | $values ||= []; | ||||||||||
|
Condition50%1/2
$values ||= []
MC/DC0%0/1
$values ||= []
$values
Truth table50%1/2
A
A= $values
| |||||||||||||
| 14 | |||||||||||||
| 15 | return sprintf( | ||||||||||||
| 16 | '%s can only have one value', | ||||||||||||
| 17 | $spec->{dest}, | ||||||||||||
| 18 | 152 | ▶ | ) if @$values > 1; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 19 | |||||||||||||
| 20 | 151 | ▶ | if ($spec->{type} == Getopt::ArgParse::Parser::TYPE_BOOL) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | # If there is default true or false | ||||||||||||
| 22 | 85 | ▶ | my $default = $spec->{default} || [ 0 ]; | ||||||||||
|
Condition100%2/2
$spec->{'default'} || [0]
MC/DC100%1/1
$spec->{'default'} || [0]
$spec->{'default'}
Truth table100%2/2
A
A= $spec->{'default'}
| |||||||||||||
| 23 | |||||||||||||
| 24 | 85 | ▶ | if (@$values) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | # Negate the default if the arg appears on the command | ||||||||||||
| 26 | # line | ||||||||||||
| 27 | 11 | $namespace->set_attr($spec->{dest}, !$default->[0]); | |||||||||||
| 28 | } else { | ||||||||||||
| 29 | 74 | $namespace->set_attr($spec->{dest}, $default->[0]); | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | # make no_arg available | ||||||||||||
| 33 | 85 | $namespace->set_attr( 'no_' . $spec->{dest}, !$namespace->get_attr($spec->{dest}) ); | |||||||||||
| 34 | |||||||||||||
| 35 | 85 | return; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | # Don't set it to undef. We may operate on a namespace with this | ||||||||||||
| 39 | # attr already set. In that case we don't want to override it. | ||||||||||||
| 40 | 66 | ▶ | return unless @$values; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | |||||||||||||
| 42 | 49 | my $v = $values->[0]; | |||||||||||
| 43 | |||||||||||||
| 44 | 49 | $namespace->set_attr($spec->{dest}, $v); | |||||||||||
| 45 | |||||||||||||
| 46 | 49 | return ''; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 20 | 1; | |||||||||||
| 50 | |||||||||||||
| 51 | =head1 AUTHOR | ||||||||||||
| 52 | |||||||||||||
| 53 | Mytram <mytram2@gmail.com> (original author) | ||||||||||||
| 54 | |||||||||||||
| 55 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 56 | |||||||||||||
| 57 | This software is Copyright (c) 2014 by Mytram. | ||||||||||||
| 58 | |||||||||||||
| 59 | This is free software, licensed under: | ||||||||||||
| 60 | |||||||||||||
| 61 | The Artistic License 2.0 (GPL Compatible) | ||||||||||||
| 62 | |||||||||||||
| 63 | =cut | ||||||||||||