blib/lib/Getopt/ArgParse/ActionStore.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 45 SCAR 34.0
CC
5
Cov
0%
apply
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 30.0
1 package Getopt::ArgParse::ActionStore;
2  
3 use strict;
4 use warnings;
5 use Carp;
6  
7 use Getopt::ArgParse::Parser;
8  
9 sub apply {
10 my $self = shift;
11  
12 my ($spec, $namespace, $values) = @_;
13 $values ||= [];
14  
15 return sprintf(
16 '%s can only have one value',
17 $spec->{dest},
18 ) if @$values > 1;
19  
20 if ($spec->{type} == Getopt::ArgParse::Parser::TYPE_BOOL) {
21 # If there is default true or false
22 my $default = $spec->{default} || [ 0 ];
23  
24 if (@$values) {
25 # Negate the default if the arg appears on the command
26 # line
27 $namespace->set_attr($spec->{dest}, !$default->[0]);
28 } else {
29 $namespace->set_attr($spec->{dest}, $default->[0]);
30 }
31  
32 # make no_arg available
33 $namespace->set_attr( 'no_' . $spec->{dest}, !$namespace->get_attr($spec->{dest}) );
34  
35 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 return unless @$values;
41  
42 my $v = $values->[0];
43  
44 $namespace->set_attr($spec->{dest}, $v);
45  
46 return '';
47 }
48  
49 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