| 1 | package App::optargs; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use OptArgs; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use lib 'lib'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | our $VERSION = '0.1.21'; | |||||||||
| 7 | |||||||||||
| 8 | 1 | $OptArgs::COLOUR = 1; | |||||||||
| 9 | |||||||||||
| 10 | 1 | arg class => ( | |||||||||
| 11 | isa => 'Str', | ||||||||||
| 12 | required => 1, | ||||||||||
| 13 | comment => 'OptArgs-based module to load', | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | arg name => ( | ||||||||||
| 17 | isa => 'Str', | ||||||||||
| 18 | comment => 'Name of the command', | ||||||||||
| 19 | 3 | ▶ | default => sub { '<command>' } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ); | |||||||||
| 21 | |||||||||||
| 22 | 1 | opt indent => ( | |||||||||
| 23 | isa => 'Int', | ||||||||||
| 24 | comment => 'Number of spaces to indent sub-commands', | ||||||||||
| 25 | alias => 'i', | ||||||||||
| 26 | default => 4, | ||||||||||
| 27 | ); | ||||||||||
| 28 | |||||||||||
| 29 | 1 | opt spacer => ( | |||||||||
| 30 | isa => 'Str', | ||||||||||
| 31 | comment => 'Character to use for indent spaces', | ||||||||||
| 32 | default => ' ', | ||||||||||
| 33 | alias => 's', | ||||||||||
| 34 | ); | ||||||||||
| 35 | |||||||||||
| 36 | 1 | opt full => ( | |||||||||
| 37 | isa => 'Bool', | ||||||||||
| 38 | comment => 'Print the full usage messages', | ||||||||||
| 39 | alias => 'f', | ||||||||||
| 40 | ); | ||||||||||
| 41 | |||||||||||
| 42 | 4 | ▶ | sub run { | ||||||||
|
Subroutine
run: called CC=4 SCAR=16.0
Pod
documented
| |||||||||||
| 43 | 4 | my $opts = shift; | |||||||||
| 44 | |||||||||||
| 45 | 4 | ▶ | die $@ unless eval "require $opts->{class};"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | |||||||||||
| 47 | 4 | my $initial = do { my @tmp = split( /::/, $opts->{class} ) }; | |||||||||
| 48 | 4 | my $indent = $opts->{spacer} x $opts->{indent}; | |||||||||
| 49 | |||||||||||
| 50 | 4 | binmode( STDOUT, ':encoding(utf8)' ); | |||||||||
| 51 | |||||||||||
| 52 | 4 | foreach my $cmd ( OptArgs::_cmdlist() ) { | |||||||||
| 53 | 32 | my $length = do { my @tmp = split( /::/, $cmd ) } | |||||||||
| 54 | - $initial; | ||||||||||
| 55 | 32 | my $space = $indent x $length; | |||||||||
| 56 | |||||||||||
| 57 | 32 | ▶ | unless ( $opts->{full} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 32 | my $usage = OptArgs::_synopsis($cmd); | |||||||||
| 59 | 32 | $usage =~ s/^usage: \S+/$space$opts->{name}/; | |||||||||
| 60 | 32 | print $usage; | |||||||||
| 61 | 32 | next; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | my $usage = OptArgs::_usage($cmd); | |||||||||
| 65 | 0 | $usage =~ s/^usage: \S+/usage: $opts->{name}/; | |||||||||
| 66 | |||||||||||
| 67 | 0 | my $n = 79 - length $space; | |||||||||
| 68 | 0 | print $space, '#' x $n, "\n"; | |||||||||
| 69 | 0 | print $space, "# $cmd\n"; | |||||||||
| 70 | 0 | print $space, '#' x $n, "\n"; | |||||||||
| 71 | 0 | $usage =~ s/^/$space/gm; | |||||||||
| 72 | 0 | print $usage; | |||||||||
| 73 | 0 | print $space . "\n"; | |||||||||
| 74 | } | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 1 | 1; | |||||||||
| 78 | |||||||||||
| 79 | __END__ | ||||||||||