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 28 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 28 ▶use Object::Simple -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 28 ▶use Getopt::Kingpin::Arg;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 28 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 28 our $VERSION = "0.09";
10  
11 has _args => sub {
12 133 ▶ return [];
Subroutine __ANON__: called CC=1 SCAR=0.0
13 28 };
14  
15 has _args_remain => sub {
16 0 ▶ return [];
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 28 };
18  
19 sub add {
20 100 ▶ my $self = shift;
Subroutine add: called CC=1 SCAR=0.0
Pod documented
21 100 my $hash = {@_};
22 100 my ($name, $description) = ($hash->{name}, $hash->{description});
23  
24 100 my $arg = Getopt::Kingpin::Arg->new(
25 name => $name,
26 description => $description,
27 );
28 100 push @{$self->_args}, $arg;
29  
30 100 return $arg;
31 }
32  
33 sub count {
34 531 ▶ my $self = shift;
Subroutine count: called CC=1 SCAR=0.0
Pod documented
35 531 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 199 ▶ my $self = shift;
Subroutine get_by_index: called CC=2 SCAR=6.9
Pod documented
52 199 my ($index) = @_;
53  
54 199 ▶ if ($self->count <= $index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->count <= $index) 1 198 199
55 1 return;
56 }
57  
58 198 return $self->_args->[$index];
59 }
60  
61 sub get_all {
62 76 ▶ my $self = shift;
Subroutine get_all: called CC=1 SCAR=0.0
Pod documented
63 76 return @{$self->_args};
64 }
65  
66 sub _help_length {
67 15 ▶ my $self = shift;
Subroutine _help_length: called CC=3 SCAR=11.0
68  
69 15 my $max_length_of_arg = 0;
70 15 foreach my $arg ($self->get_all) {
71 27 ▶ if ($max_length_of_arg < length $arg->help_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_length_of_arg < length $arg->help_name) 17 10 27
72 17 $max_length_of_arg = length $arg->help_name;
73 }
74 }
75 15 return $max_length_of_arg;
76  
77 }
78  
79 sub help {
80 15 ▶ my $self = shift;
Subroutine help: called CC=2 SCAR=6.9
Pod documented
81 15 my $ret = "";
82  
83 15 $ret .= "Args:\n";
84  
85 15 my $len = $self->_help_length;
86 15 foreach my $arg ($self->get_all) {
87 27 $ret .= sprintf " %-${len}s %s\n",
88 $arg->help_name,
89 $arg->description;
90 }
91  
92 15 return $ret;
93 }
94  
95 28 1;
96 __END__
« blib/lib/Getopt/Kingpin/Command.pm ↑ Summary blib/lib/Getopt/Kingpin/Commands.pm »