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/Flag.pm »
1 package Getopt::Kingpin::Commands;
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::Command;
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 _commands => sub {
12 113 ▶ return [];
Subroutine __ANON__: called CC=1 SCAR=0.0
13 28 };
14  
15 sub add {
16 86 ▶ my $self = shift;
Subroutine add: called CC=1 SCAR=0.0
Pod documented
17 86 my $hash = {@_};
18 86 my ($name, $description, $parent) = ($hash->{name}, $hash->{description}, $hash->{parent});
19  
20 86 my $command = Getopt::Kingpin::Command->new(name => $name, description => $description, parent => $parent);
21 86 push @{$self->_commands}, $command;
22  
23 86 return $command;
24 }
25  
26 sub count {
27 159 ▶ my $self = shift;
Subroutine count: called CC=1 SCAR=0.0
Pod documented
28 159 return scalar @{$self->_commands};
29 }
30  
31 sub get {
32 67 ▶ my $self = shift;
Subroutine get: called CC=3 SCAR=11.0
Pod documented
33 67 my ($name) = @_;
34 67 foreach my $cmd (@{$self->_commands}) {
35 60 ▶ if ($cmd->name eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd->name eq $name) 31 29 60
36 31 return $cmd;
37 }
38 }
39 36 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 28 1;
72 __END__
« blib/lib/Getopt/Kingpin/Args.pm ↑ Summary blib/lib/Getopt/Kingpin/Flag.pm »