| 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
| |||||||||||
| 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
| |||||||||||
| 55 | 2 | foreach my $sub ($cmd->commands->get_all) { | |||||||||
| 56 | 5 | ▶ | next if $sub->name eq "help"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||