blib/lib/Getopt/Kingpin/Args.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 100% 6 / 6 totaltotal 97.7% 85 / 87 SCAR 19.5
CC
7
Cov
98%
get
3.0
_help_length
3.0
__ANON__
2.0
CRAP 7.0
« blib/lib/Getopt/Kingpin/Command.pm ↑ Summary blib/lib/Getopt/Kingpin/Commands.pm »
1 package Getopt::Kingpin::Args;
2 31 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use Object::Simple -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 31 ▶use Getopt::Kingpin::Arg;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 31 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 31 our $VERSION = "0.10";
10  
11 has _args => sub {
12 166 ▶ return [];
Subroutine __ANON__: called CC=1 SCAR=0.0
13 31 };
14  
15 has _args_remain => sub {
16 0 ▶ return [];
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 31 };
18  
19 sub add {
20 123 ▶ my $self = shift;
Subroutine add: called CC=1 SCAR=0.0
Pod documented
21 123 my $hash = {@_};
22 123 my ($name, $description) = ($hash->{name}, $hash->{description});
23  
24 123 my $arg = Getopt::Kingpin::Arg->new(
25 name => $name,
26 description => $description,
27 );
28 123 push @{$self->_args}, $arg;
29  
30 123 return $arg;
31 }
32  
33 sub count {
34 628 ▶ my $self = shift;
Subroutine count: called CC=1 SCAR=0.0
Pod documented
35 628 return scalar @{$self->_args};
36 }
37  
38 sub get {
39 4 ▶ my $self = shift;
Subroutine get: called CC=3 SCAR=11.0
Pod documented
40 4 my ($name) = @_;
41  
42 4 foreach my $arg ($self->get_all) {
43 5 ▶ if ($arg->name eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->name eq $name) 3 2 5
44 3 return $arg;
45 }
46 }
47 1 croak "get($name) failed";
48 }
49  
50 sub get_by_index {
51 195 ▶ my $self = shift;
Subroutine get_by_index: called CC=2 SCAR=6.9
Pod documented
52 195 my ($index) = @_;
53  
54 195 ▶ if ($self->count <= $index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->count <= $index) 1 194 195
55 1 return;
56 }
57  
58 194 return $self->_args->[$index];
59 }
60  
61 sub get_all {
62 85 ▶ my $self = shift;
Subroutine get_all: called CC=1 SCAR=0.0
Pod documented
63 85 return @{$self->_args};
64 }
65  
66 sub _help_length {
67 17 ▶ my $self = shift;
Subroutine _help_length: called CC=3 SCAR=11.0
68  
69 17 my $max_length_of_arg = 0;
70 17 foreach my $arg ($self->get_all) {
71 30 ▶ if ($max_length_of_arg < length $arg->help_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_length_of_arg < length $arg->help_name) 19 11 30
72 19 $max_length_of_arg = length $arg->help_name;
73 }
74 }
75 17 return $max_length_of_arg;
76  
77 }
78  
79 sub help {
80 17 ▶ my $self = shift;
Subroutine help: called CC=2 SCAR=6.9
Pod documented
81 17 my $ret = "";
82  
83 17 $ret .= "Args:\n";
84  
85 17 my $len = $self->_help_length;
86 17 foreach my $arg ($self->get_all) {
87 30 $ret .= sprintf " %-${len}s %s\n",
88 $arg->help_name,
89 $arg->description;
90 }
91  
92 17 return $ret;
93 }
94  
95 31 1;
96 __END__
« blib/lib/Getopt/Kingpin/Command.pm ↑ Summary blib/lib/Getopt/Kingpin/Commands.pm »