File Coverage

blib/lib/Getopt/Yath/Option/Count.pm
Criterion Covered Total %
statement 36 41 87.8
branch 2 6 33.3
condition 1 5 20.0
subroutine 18 20 90.0
pod 0 15 0.0
total 57 87 65.5


line stmt bran cond sub pod time code
1             package Getopt::Yath::Option::Count;
2 1     1   6 use strict;
  1         1  
  1         31  
3 1     1   3 use warnings;
  1         1  
  1         52  
4              
5 1     1   5 use Carp qw/croak/;
  1         1  
  1         69  
6              
7             our $VERSION = '2.000007';
8              
9 1     1   4 use parent 'Getopt::Yath::Option';
  1         106  
  1         11  
10 1     1   65 use Getopt::Yath::HashBase;
  1         2  
  1         6  
11              
12 9     9 0 22 sub allows_shortval { 0 }
13 3     3 0 7 sub allows_arg { 1 }
14 10     10 0 23 sub requires_arg { 0 }
15 7     7 0 9 sub allows_autofill { 0 }
16 1     1 0 2 sub requires_autofill { 0 }
17 47     47 0 120 sub is_populated { 1 } # Always populated
18              
19 7     7 0 9 sub no_arg_value { () }
20              
21 3     3 0 4 sub clear_field { ${$_[1]} = 0 } # --no-count
  3         5  
22              
23             # Autofill should be 0 if not specified
24 0   0 0 0 0 sub get_autofill_value { $_[0]->SUPER::get_autofill_value() // 0 }
25              
26 2     2 0 3 sub default_long_examples {my $self = shift; ['', '=COUNT'] }
  2         14  
27 2     2 0 8 sub default_short_examples {my $self = shift; ['', $self->short, ($self->short x 2) . '..', '=COUNT'] }
  2         19  
28              
29 2     2 0 30 sub notes { (shift->SUPER::notes(), 'Can be specified multiple times, counter bumps each time it is used.') }
30              
31             # --count
32             # --count=5
33             sub add_value {
34 61     61 0 87 my $self = shift;
35 61         95 my ($ref, @val) = @_;
36              
37             # Explicit value set
38 61 100       215 return $$ref = $val[0] if @val;
39              
40             # Make sure we have a sane start
41 7   33     13 $$ref //= $self->get_autofill_value;
42              
43             # Bump by one
44 7         8 return ${$ref}++;
  7         26  
45             }
46              
47 48     48 0 101 sub can_set_env { 1 }
48              
49             sub get_env_value {
50 0     0 0   my $opt = shift;
51 0           my ($var, $ref) = @_;
52              
53 0 0         return $$ref unless $var =~ m/^!/;
54 0 0         return $ref ? 0 : 1;
55             }
56              
57             1;
58              
59             __END__