blib/lib/Getopt/Kingpin/Commands.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 5 / 5 totaltotal 100% 78 / 78 SCAR 19.5
CC
7
Cov
100%
help
5.0
get
3.0
BEGIN
1.0
CRAP 7.0
« blib/lib/Getopt/Kingpin/Args.pm ↑ Summary blib/lib/Getopt/Kingpin/Arg.pm »
1 package Getopt::Kingpin::Commands;
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::Command;
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 _commands => sub {
12 123 ▶ return [];
Subroutine __ANON__: called CC=1 SCAR=0.0
13 31 };
14  
15 sub add {
16 93 ▶ my $self = shift;
Subroutine add: called CC=1 SCAR=0.0
Pod documented
17 93 my $hash = {@_};
18 93 my ($name, $description, $parent) = ($hash->{name}, $hash->{description}, $hash->{parent});
19  
20 93 my $command = Getopt::Kingpin::Command->new(name => $name, description => $description, parent => $parent);
21 93 push @{$self->_commands}, $command;
22  
23 93 return $command;
24 }
25  
26 sub count {
27 173 ▶ my $self = shift;
Subroutine count: called CC=1 SCAR=0.0
Pod documented
28 173 return scalar @{$self->_commands};
29 }
30  
31 sub get {
32 76 ▶ my $self = shift;
Subroutine get: called CC=3 SCAR=11.0
Pod documented
33 76 my ($name) = @_;
34 76 foreach my $cmd (@{$self->_commands}) {
35 66 ▶ if ($cmd->name eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd->name eq $name) 34 32 66
36 34 return $cmd;
37 }
38 }
39 42 return;
40 }
41  
42 sub get_all {
43 15 ▶ my $self = shift;
Subroutine get_all: called CC=1 SCAR=0.0
Pod documented
44 15 return @{$self->_commands};
45 }
46  
47 sub help {
48 6 ▶ my $self = shift;
Subroutine help: called CC=5 SCAR=16.1
Pod documented
49 6 my $ret = "";
50  
51 6 $ret .= "Commands:\n";
52  
53 6 foreach my $cmd ($self->get_all) {
54 17 ▶ if ($cmd->commands->count > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd->commands->count > 1) { } 2 15 17
55 2 foreach my $sub ($cmd->commands->get_all) {
56 5 ▶ next if $sub->name eq "help";
Branch: 1 branch
BranchTrueFalseTotal
if $sub->name eq "help" 2 3 5
57 3 $ret .= sprintf " %s %s\n", $cmd->name, $sub->name;
58 3 $ret .= sprintf " %s\n", $sub->description;
59 3 $ret .= sprintf "\n";
60 }
61 } else {
62 15 $ret .= sprintf " %s\n", $cmd->help_short;
63 15 $ret .= sprintf " %s\n", $cmd->description;
64 15 $ret .= sprintf "\n";
65 }
66 }
67  
68 6 return $ret;
69 }
70  
71 31 1;
72 __END__
« blib/lib/Getopt/Kingpin/Args.pm ↑ Summary blib/lib/Getopt/Kingpin/Arg.pm »