| 1 | package CLI::Driver::Action; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Kavorka '-all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Data::Printer alias => 'pdump'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use CLI::Driver::Class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use CLI::Driver::Method; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | ▶ | use CLI::Driver::Help; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 17 | ▶ | use Module::Load; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 17 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 17 | with 'CLI::Driver::CommonRole'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ############################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ###### PUBLIC ATTRIBUTES ###### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ############################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 17 | has name => ( is => 'rw', isa => 'Str' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 17 | has desc => ( is => 'rw', isa => 'Str' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 17 | has is_deprecated => ( is => 'rw', isa => 'Bool' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 17 | has class => ( is => 'rw', isa => 'CLI::Driver::Class' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 17 | has 'method' => ( is => 'rw', isa => 'CLI::Driver::Method' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 17 | has 'help' => ( is => 'rw', isa => 'CLI::Driver::Help' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 17 | has 'use_argv_map' => ( is => 'rw', isa => 'Bool' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ############################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ###### PUBLIC METHODS ###### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ############################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 17 | ▶ | method parse (HashRef :$href!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
parse: called CC=21 SCAR=34.9
Branch: 8 branches
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 240 | ▶ | if ( $href->{is_deprecated} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $string = $href->{is_deprecated}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $bool = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ( $string =~ /^true$/i or $string == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$string =~ /^true$/iu or $string == 1
MC/DC0%0/2
$string =~ /^true$/iu or $string == 1
$string =~ /^true$/iu
$string == 1
Truth table0%0/3
A or B
A= $string =~ /^true$/iuB= $string == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $bool = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $self->is_deprecated($bool); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 240 | ▶ | if ( $href->{class} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 240 | ▶ | my $class = CLI::Driver::Class->new(use_argv_map => $self->use_argv_map ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 240 | my $success = $class->parse( href => $href->{class} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 240 | ▶ | if ( !$success ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 240 | $self->class($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 240 | ▶ | if ( $href->{method} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 240 | ▶ | my $method = CLI::Driver::Method->new(use_argv_map => $self->use_argv_map ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 240 | my $success = $method->parse( href => $href->{method} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 240 | ▶ | if ( !$success ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 240 | $self->method($method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 240 | ▶ | if ( $href->{desc} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 240 | $self->desc( $href->{desc} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 240 | my $help = CLI::Driver::Help->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 240 | $help->parse( href => $href->{help} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 240 | $self->help($help); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 240 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 17 | ▶ | method usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
usage: not called CC=21 SCAR=60.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | printf "\nusage: %s %s [opts] [-?]\n", basename($0), $self->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | printf "description: %s\n", $self->desc if $self->desc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $help = $self->help; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my @opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | push @opts, @{ $self->class->attr }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | push @opts, @{ $self->method->args }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my %opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ( $opt->required ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $opts{ $opt->cli_arg } = $opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # and $opt->is_hard) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # $opts{ $opt->cli_arg } = $opt->method_arg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # print required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | foreach my $arg ( sort { uc($a) cmp uc($b) } keys %opts ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $opt = $opts{$arg}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $val = $opt->method_arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | printf "\t-%s <%s>", $arg, $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | print ' (soft)' if $opt->is_soft; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | print ' (multi value)' if $opt->is_array; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | printf "\t\t%s\n", $help->get_help($arg) if $help->get_help($arg); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | %opts = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ( $opt->is_optional and !$opt->is_flag ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt->is_optional and not $opt->is_flag
MC/DC0%0/2
$opt->is_optional and not $opt->is_flag
$opt->is_optional
not $opt->is_flag
Truth table0%0/3
A and not(B)
A= $opt->is_optionalB= not $opt->is_flag
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $opts{ $opt->cli_arg } = $opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # and $opt->is_hard) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # $opts{ $opt->cli_arg } = $opt->method_arg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # print "\n" if keys %opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # print optional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | foreach my $arg ( sort { uc($a) cmp uc($b) } keys %opts ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $opt = $opts{$arg}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $val = $opt->method_arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | printf "\t[ -%s <%s> ]", $arg, $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | print ' (multi value)' if $opt->is_array; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | printf "\t\t%s\n", $help->get_help($arg) if $help->get_help($arg); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | %opts = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if ( $opt->is_flag ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $opts{ $opt->cli_arg } = $opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # and $opt->is_hard) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # $opts{ $opt->cli_arg } = $opt->method_arg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # print "\n" if keys %opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # print flags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | foreach my $arg ( sort { uc($a) cmp uc($b) } keys %opts ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $opt = $opts{$arg}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | printf "\t[ --%s ]\n", $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | printf "\t\t%s\n", $help->get_help($arg) if $help->get_help($arg); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # print examples | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ( $help->has_examples ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $cmd = sprintf "%s %s", basename($0), $self->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | print "Examples:\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | foreach my $eg ( @{ $help->examples } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | printf "\t%s %s\n", $cmd, $eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ######################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 17 | ▶ | method _new_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_new_class: called CC=5 SCAR=16.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 30 | my $class = $self->class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 30 | my $class_name = $class->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 30 | my %attr = $class->get_signature; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 28 | load $class_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 28 | ▶ | my $obj = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | $class_name->new( %attr, use_argv_map => $self->use_argv_map ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # validate required class attributes were provided | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 28 | my @soft_req = $class->find_req_attrs( hard => 0, soft => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 28 | foreach my $opt (@soft_req) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 2 | my $attr = $opt->method_arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | ▶ | if ( !defined $obj->$attr ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | confess "failed to determine $attr"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 27 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 17 | ▶ | method do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
do: called CC=5 SCAR=16.3
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # this creates an instance of the user class defined in the yaml | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 30 | my $obj = $self->_new_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # prepare the method args from @ARGV or %ARGV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 27 | my $method = $self->method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 27 | my $method_name = $method->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 27 | my %sig = $method->get_signature; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 24 | ▶ | if ( $self->use_argv_map ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | ▶ | if ( keys %ARGV ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my @argv = %ARGV; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $self->die("extra args detected: @argv"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 23 | ▶ | if (@ARGV) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | $self->die("extra args detected: @ARGV"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # finally invoke the actual method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 23 | return $obj->$method_name(%sig); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||