App/optargs.pm

filter: Statementstmt 80.0% 36 / 45 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 80.3% 45 / 56 CC 4 SCAR 10.2
CC
4
Cov
78%
run
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.8
« OptArgs.pm ↑ Summary
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
BranchTrueFalseTotal
unless eval qq[require $opts->{"class"};] 0 4 4
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
BranchTrueFalseTotal
unless ($opts->{"full"}) 32 0 32
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__
« OptArgs.pm ↑ Summary