| 1 | # ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package MooseX::App::Meta::Role::Class::Base; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 16 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 16 | ▶ | use List::Util qw(max first); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 16 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 16 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 16 | ▶ | use MooseX::App::Utils; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 16 | ▶ | use Module::Pluggable::Object; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 16 | ▶ | use File::Basename qw(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 16 | has 'app_messageclass' => ( | |||||||||||||||||||||||||||||||||||||||||
| 18 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | isa => 'ClassName', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | builder => '_build_app_messageclass', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 16 | has 'app_namespace' => ( | |||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | isa => 'MooseX::App::Types::List', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | builder => '_build_app_namespace', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | has 'app_exclude' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 33 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | isa => 'MooseX::App::Types::List', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 51 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 16 | ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | has 'app_base' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 40 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 10 | return File::Basename::basename($0); | |||||||||||||||||||||||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 16 | ); | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | has 'app_strict' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 49 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 51 | ▶ | default => sub {0}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 16 | ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | has 'app_fuzzy' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 55 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 51 | ▶ | default => sub {1}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 16 | ); | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | has 'app_command_name' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 61 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | isa => 'CodeRef', | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 51 | ▶ | default => sub { \&MooseX::App::Utils::class_to_command }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 16 | ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | has 'app_prefer_commandline' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 67 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 68 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 51 | ▶ | default => sub {0}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 16 | ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | has 'app_permute' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 73 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 51 | ▶ | default => sub {0}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 16 | ); | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 16 | has 'app_commands' => ( | |||||||||||||||||||||||||||||||||||||||||
| 79 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | isa => 'HashRef[Str]', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||
| 82 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | command_register => 'set', | ||||||||||||||||||||||||||||||||||||||||||
| 84 | command_get => 'get', | ||||||||||||||||||||||||||||||||||||||||||
| 85 | command_classes => 'values', | ||||||||||||||||||||||||||||||||||||||||||
| 86 | command_list => 'shallow_clone', | ||||||||||||||||||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | builder => '_build_app_commands', | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 13 | ▶ | sub _build_app_messageclass { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_app_messageclass: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 13 | return 'MooseX::App::Message::Block' | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | ▶ | sub _build_app_namespace { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_app_namespace: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 11 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 11 | return [ $self->name ]; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 11 | ▶ | sub _build_app_commands { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_app_commands: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 11 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 11 | my (@list); | |||||||||||||||||||||||||||||||||||||||||
| 106 | # Process namespace list | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 11 | foreach my $namespace ( @{ $self->app_namespace } ) { | |||||||||||||||||||||||||||||||||||||||||
| 108 | 11 | push(@list,$self->command_scan_namespace($namespace)); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 11 | my $commands = { @list }; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # Process excludes | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 11 | foreach my $exclude ( @{ $self->app_exclude } ) { | |||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | foreach my $command (keys %{$commands}) { | |||||||||||||||||||||||||||||||||||||||||
| 115 | delete $commands->{$command} | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 21 | ▶ | if $commands->{$command} =~ m/^\Q$exclude\E(::|$)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 11 | return $commands; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 83 | ▶ | sub command_check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_check: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 83 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 83 | foreach my $attribute ($self->command_usage_attributes($self,'all')) { | |||||||||||||||||||||||||||||||||||||||||
| 127 | 204 | $attribute->cmd_check(); | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 82 | return; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 11 | ▶ | sub command_scan_namespace { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_scan_namespace: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 11 | my ($self,$namespace) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | # Find all packages in namespace | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 11 | my $mpo = Module::Pluggable::Object->new( | |||||||||||||||||||||||||||||||||||||||||
| 137 | search_path => [ $namespace ], | ||||||||||||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 11 | my $commandsub = $self->app_command_name; | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 11 | my %return; | |||||||||||||||||||||||||||||||||||||||||
| 143 | # Loop all packages | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 11 | foreach my $command_class ($mpo->plugins) { | |||||||||||||||||||||||||||||||||||||||||
| 145 | 46 | my $command_class_name = substr($command_class,length($namespace)+2); | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | # subcommands support | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 46 | $command_class_name =~ s/::/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | # Extract command name | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 46 | $command_class_name =~ s/^\Q$namespace\E:://; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 46 | $command_class_name =~ s/^.+::([^:]+)$/$1/; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 46 | my $command = $commandsub->($command_class_name,$command_class); | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | # Check if command was loaded | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 46 | ▶ | $return{$command} = $command_class | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | if defined $command; | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 11 | return %return; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 69 | ▶ | sub command_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_args: called CC=26 SCAR=35.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 69 | my ($self,$metaclass) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 69 | ▶ | $metaclass ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$metaclass ||= $self
MC/DC0%0/2
$metaclass ||= $self
$metaclass
$self
Truth table33%1/3
A ||= B
A= $metaclassB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 69 | my $parsed_argv = MooseX::App::ParsedArgv->instance; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 69 | ▶ | unless ($metaclass->does_role('MooseX::App::Role::Common')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | Moose->throw_error('Class '.$metaclass->name.' is not a proper MooseX::App::Command class. You either need to use MooseX::App::Command or exclude this class via app_exclude') | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | # Process options | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 69 | my @attributes_option = $self->command_usage_attributes($metaclass,'option'); | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 69 | my ($return,$errors) = $self->command_parse_options(\@attributes_option); | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 68 | my %raw_error; | |||||||||||||||||||||||||||||||||||||||||
| 179 | # Loop all left over options | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 68 | foreach my $option ($parsed_argv->available('option')) { | |||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | my $key = $option->key; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | my $raw = $option->original; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | my $message; | |||||||||||||||||||||||||||||||||||||||||
| 184 | next | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | ▶ | if defined $raw_error{$raw}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | # Get possible options with double dash - might be missing | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | ▶ | if (length $key == 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $key == 1 and $raw =~ /^-(\w+)$/
MC/DC0%0/2
length $key == 1 and $raw =~ /^-(\w+)$/
length $key == 1
$raw =~ /^-(\w+)$/
Truth table33%1/3
A and B
A= length $key == 1B= $raw =~ /^-(\w+)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | && $raw =~ m/^-(\w+)$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 190 | POSSIBLE_ATTRIBUTES: | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | foreach my $attribute ($self->command_usage_attributes($metaclass,[qw(option proto)])) { | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | foreach my $name ($attribute->cmd_name_possible) { | |||||||||||||||||||||||||||||||||||||||||
| 193 | # TODO fuzzy match | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | if ($name eq $1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $raw_error{$raw} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $message = "Did you mean '--$name'?"; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | last POSSIBLE_ATTRIBUTES; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | # Handle error messages | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 2 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 2 | ▶ | if (defined $message) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $error = $self->command_message( | |||||||||||||||||||||||||||||||||||||||||
| 207 | header => "Unknown option '".$raw."'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 208 | body => $message, | ||||||||||||||||||||||||||||||||||||||||||
| 209 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 210 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | $error = $self->command_message( | |||||||||||||||||||||||||||||||||||||||||
| 213 | header => "Unknown option '".$option->key."'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 214 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | unshift(@{$errors},$error); | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | # Process positional parameters | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 68 | my @attributes_parameter = $self->command_usage_attributes($metaclass,'parameter'); | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 68 | foreach my $attribute (@attributes_parameter) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 36 | my $element = $parsed_argv->consume('parameter'); | |||||||||||||||||||||||||||||||||||||||||
| 225 | last | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 36 | ▶ | unless defined $element; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 22 | my ($parameter_value,$parameter_errors) = $self->command_process_attribute($attribute, [ $element->key ] ); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 22 | push(@{$errors},@{$parameter_errors}); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 22 | $return->{$attribute->name} = $parameter_value; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | # Handle all unconsumed parameters and options | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 68 | ▶ | if ($self->app_strict || $metaclass->command_strict) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->app_strict or $metaclass->command_strict
MC/DC50%1/2
$self->app_strict or $metaclass->command_strict
$self->app_strict
$metaclass->command_strict
Truth table66%2/3
A or B
A= $self->app_strictB= $metaclass->command_strict
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 34 | foreach my $parameter ($parsed_argv->available('parameter')) { | |||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | unshift(@{$errors}, | |||||||||||||||||||||||||||||||||||||||||
| 237 | $self->command_message( | ||||||||||||||||||||||||||||||||||||||||||
| 238 | header => "Unknown parameter '".$parameter->key."'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 239 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 240 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 241 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # Handle ENV | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 68 | foreach my $attribute ($self->command_usage_attributes($metaclass,'all')) { | |||||||||||||||||||||||||||||||||||||||||
| 247 | next | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 378 | ▶ | unless $attribute->can('has_cmd_env') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attribute->can("has_cmd_env") and $attribute->has_cmd_env
MC/DC50%1/2
$attribute->can("has_cmd_env") and $attribute->has_cmd_env
$attribute->can("has_cmd_env")
$attribute->has_cmd_env
Truth table66%2/3
A and B
A= $attribute->can("has_cmd_env")B= $attribute->has_cmd_env
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | && $attribute->has_cmd_env; | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 29 | my $cmd_env = $attribute->cmd_env; | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 29 | ▶ | if (exists $ENV{$cmd_env} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $ENV{$cmd_env} and not defined $$return{$attribute->name}
MC/DC100%2/2
exists $ENV{$cmd_env} and not defined $$return{$attribute->name}
exists $ENV{$cmd_env}
not defined $$return{$attribute->name}
Truth table100%3/3
A and not(B)
A= exists $ENV{$cmd_env}B= not defined $$return{$attribute->name}
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | && ! defined $return->{$attribute->name}) { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 3 | my $value = $ENV{$cmd_env}; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | ▶ | if ($attribute->has_type_constraint) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 3 | my $type_constraint = $attribute->type_constraint; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | ▶ | if ($attribute->should_coerce | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attribute->should_coerce and $type_constraint->has_coercion
MC/DC50%1/2
$attribute->should_coerce and $type_constraint->has_coercion
$attribute->should_coerce
$type_constraint->has_coercion
Truth table66%2/3
A and B
A= $attribute->should_coerceB= $type_constraint->has_coercion
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | && $type_constraint->has_coercion) { | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | my $coercion = $type_constraint->coercion; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | $value = $coercion->coerce($value) // $value; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$coercion->coerce($value) // $value
MC/DC0%0/2
$coercion->coerce($value) // $value
$coercion->coerce($value)
$value
Truth table33%1/3
A // B
A= $coercion->coerce($value)B= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 3 | $return->{$attribute->name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | my $error = $attribute->cmd_type_constraint_check($value); | |||||||||||||||||||||||||||||||||||||||||
| 269 | 3 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | push(@{$errors}, | |||||||||||||||||||||||||||||||||||||||||
| 271 | $self->command_message( | ||||||||||||||||||||||||||||||||||||||||||
| 272 | header => "Invalid environment value for '".$cmd_env."'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 273 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 274 | body => $error, | ||||||||||||||||||||||||||||||||||||||||||
| 275 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 276 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 68 | return ($return,$errors); | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 75 | ▶ | sub command_proto { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_proto: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 75 | my ($self,$metaclass) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 75 | ▶ | $metaclass ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$metaclass ||= $self
MC/DC0%0/2
$metaclass ||= $self
$metaclass
$self
Truth table33%1/3
A ||= B
A= $metaclassB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 75 | my @attributes; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 75 | foreach my $attribute ($self->command_usage_attributes($metaclass,'proto')) { | |||||||||||||||||||||||||||||||||||||||||
| 291 | next | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 96 | ▶ | unless $attribute->does('MooseX::App::Meta::Role::Attribute::Option') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$attribute->does("MooseX::App::Meta::Role::Attribute::Option") and $attribute->has_cmd_type
MC/DC0%0/2
$attribute->does("MooseX::App::Meta::Role::Attribute::Option") and $attribute->has_cmd_type
$attribute->does("MooseX::App::Meta::Role::Attribute::Option")
$attribute->has_cmd_type
Truth table33%1/3
A and B
A= $attribute->does("MooseX::App::Meta::Role::Attribute::Option")B= $attribute->has_cmd_type
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | && $attribute->has_cmd_type; | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 96 | push(@attributes,$attribute); | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 75 | return $self->command_parse_options(\@attributes); | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 144 | ▶ | sub command_parse_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_parse_options: called CC=20 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 144 | my ($self,$attributes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | # Build attribute lookup hash | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 144 | my %option_to_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 144 | foreach my $attribute (@{$attributes}) { | |||||||||||||||||||||||||||||||||||||||||
| 306 | 336 | foreach my $name ($attribute->cmd_name_possible) { | |||||||||||||||||||||||||||||||||||||||||
| 307 | 574 | ▶ | if (defined $option_to_attribute{$name} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $option_to_attribute{$name} and $option_to_attribute{$name} != $attribute
MC/DC50%1/2
defined $option_to_attribute{$name} and $option_to_attribute{$name} != $attribute
defined $option_to_attribute{$name}
$option_to_attribute{$name} != $attribute
Truth table66%2/3
A and B
A= defined $option_to_attribute{$name}B= $option_to_attribute{$name} != $attribute
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | && $option_to_attribute{$name} != $attribute) { | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | Moose->throw_error('Command line option conflict: '.$name); | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 573 | $option_to_attribute{$name} = $attribute; | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 143 | my $match = {}; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 143 | my $return = {}; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 143 | my @errors; | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | # Get ARGV | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 143 | my $parsed_argv = MooseX::App::ParsedArgv->instance; | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | # Loop all exact matches | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 143 | foreach my $option ($parsed_argv->available('option')) { | |||||||||||||||||||||||||||||||||||||||||
| 324 | 203 | ▶ | if (my $attribute = $option_to_attribute{$option->key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 89 | $option->consume($attribute); | |||||||||||||||||||||||||||||||||||||||||
| 326 | 89 | $match->{$attribute->name} = [ $option ]; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | # Process fuzzy matches | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 143 | ▶ | if ($self->app_fuzzy) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | # Loop all options (sorted by length) | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 139 | foreach my $option (sort { length($b->key) <=> length($a->key) } $parsed_argv->available('option')) { | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | # No fuzzy matching for one-letter flags | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 109 | my $option_length = length($option->key); | |||||||||||||||||||||||||||||||||||||||||
| 337 | next | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 109 | ▶ | if $option_length == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 105 | my ($match_attributes) = []; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | # Try to match attributes | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 105 | foreach my $name (keys %option_to_attribute) { | |||||||||||||||||||||||||||||||||||||||||
| 344 | next | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 466 | ▶ | if ($option_length >= length($name)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 111 | my $name_short = lc(substr($name,0,$option_length)); | |||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | # Partial match | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 111 | ▶ | if (lc($option->key) eq $name_short) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 16 | my $attribute = $option_to_attribute{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 16 | ▶ | unless (grep { $attribute == $_ } @{$match_attributes}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 16 | push(@{$match_attributes},$attribute); | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | # Process matches | ||||||||||||||||||||||||||||||||||||||||||
| 359 | # No match | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 105 | ▶ | if(@{$match_attributes} == 0) {} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | # One match | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 15 | elsif(@{$match_attributes} == 1) { | |||||||||||||||||||||||||||||||||||||||||
| 363 | 14 | my $attribute = $match_attributes->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 14 | $option->consume(); | |||||||||||||||||||||||||||||||||||||||||
| 365 | 14 | ▶ | $match->{$attribute->name} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$match{$attribute->name} ||= []
MC/DC100%1/1
$$match{$attribute->name} ||= []
$$match{$attribute->name}
Truth table100%2/2
A
A= $$match{$attribute->name}
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 14 | push(@{$match->{$attribute->name}},$option); | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | # Multiple matches | ||||||||||||||||||||||||||||||||||||||||||
| 369 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 1 | $option->consume(); | |||||||||||||||||||||||||||||||||||||||||
| 371 | push(@errors, | ||||||||||||||||||||||||||||||||||||||||||
| 372 | $self->command_message( | ||||||||||||||||||||||||||||||||||||||||||
| 373 | header => "Ambiguous option '".$option->key."'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 374 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 375 | body => "Could be\n".MooseX::App::Utils::format_list( # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | map { [ $_ ] } | |||||||||||||||||||||||||||||||||||||||||
| 377 | sort | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 2 | map { $_->cmd_name_primary } | |||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | @{$match_attributes} | |||||||||||||||||||||||||||||||||||||||||
| 380 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 381 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 382 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | # Check all attributes | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 143 | foreach my $attribute (@{$attributes}) { | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | next | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 334 | ▶ | unless exists $match->{$attribute->name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 95 | my @mapped_values; | |||||||||||||||||||||||||||||||||||||||||
| 394 | 95 | foreach my $element (@{$match->{$attribute->name}}) { | |||||||||||||||||||||||||||||||||||||||||
| 395 | 100 | push(@mapped_values,$element->all_values); | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | my $values = [ | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 110 | map { $_->value } | |||||||||||||||||||||||||||||||||||||||||
| 400 | 95 | sort { $a->position <=> $b->position } | |||||||||||||||||||||||||||||||||||||||||
| 401 | @mapped_values | ||||||||||||||||||||||||||||||||||||||||||
| 402 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | #warn Data::Dumper::Dumper($raw); | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 95 | my ($value,$errors) = $self->command_process_attribute( $attribute, $values ); | |||||||||||||||||||||||||||||||||||||||||
| 406 | 95 | push(@errors,@{$errors}); | |||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 95 | $return->{$attribute->name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 143 | return ($return,\@errors); | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 117 | ▶ | sub command_process_attribute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_process_attribute: called CC=17 SCAR=28.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 117 | my ($self,$attribute,$raw) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 117 | ▶ | $raw = [ $raw ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | unless ref($raw) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 117 | my @errors; | |||||||||||||||||||||||||||||||||||||||||
| 421 | my $value; | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | # Attribute with split | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 117 | ▶ | if ($attribute->has_cmd_split) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 1 | my @raw_unfolded; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | foreach (@{$raw}) { | |||||||||||||||||||||||||||||||||||||||||
| 427 | 2 | push(@raw_unfolded,split($attribute->cmd_split,$_)); | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | $raw = \@raw_unfolded; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | # Attribute with counter - transform value count into value | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 117 | ▶ | if ($attribute->cmd_count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 1 | $value = $raw = [ scalar(@$raw) ]; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | # Attribute with type constraint | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 117 | ▶ | if ($attribute->has_type_constraint) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 111 | my $type_constraint = $attribute->type_constraint; | |||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 111 | ▶ | if ($type_constraint->is_a_type_of('ArrayRef')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 5 | $value = $raw; | |||||||||||||||||||||||||||||||||||||||||
| 443 | } elsif ($type_constraint->is_a_type_of('HashRef')) { | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 4 | $value = {}; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 4 | foreach my $element (@{$raw}) { | |||||||||||||||||||||||||||||||||||||||||
| 446 | 6 | ▶ | if ($element =~ m/^([^=]+)=(.+?)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 5 | ▶ | $value->{$1} ||= $2; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$value->{$1} ||= $2
MC/DC0%0/2
$value->{$1} ||= $2
$value->{$1}
$2
Truth table33%1/3
A ||= B
A= $value->{$1}B= $2
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 1 | push(@errors, | |||||||||||||||||||||||||||||||||||||||||
| 450 | $self->command_message( | ||||||||||||||||||||||||||||||||||||||||||
| 451 | header => "Invalid value for '".$attribute->cmd_name_primary."'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 452 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 453 | body => "Value must be supplied as 'key=value' (not '$element')", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 454 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 455 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | } elsif ($type_constraint->is_a_type_of('Bool')) { | ||||||||||||||||||||||||||||||||||||||||||
| 459 | 26 | $value = $raw->[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | # if ($self->has_default | ||||||||||||||||||||||||||||||||||||||||||
| 462 | # && ! $self->is_default_a_coderef | ||||||||||||||||||||||||||||||||||||||||||
| 463 | # && $self->default == 1) { | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 76 | $value = $raw->[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 111 | ▶ | unless(defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 2 | push(@errors, | |||||||||||||||||||||||||||||||||||||||||
| 471 | $self->command_message( | ||||||||||||||||||||||||||||||||||||||||||
| 472 | header => "Missing value for '".$attribute->cmd_name_primary."'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 473 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 474 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 475 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 476 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 477 | 109 | ▶ | if ($attribute->should_coerce | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attribute->should_coerce and $type_constraint->has_coercion
MC/DC50%1/2
$attribute->should_coerce and $type_constraint->has_coercion
$attribute->should_coerce
$type_constraint->has_coercion
Truth table66%2/3
A and B
A= $attribute->should_coerceB= $type_constraint->has_coercion
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | && $type_constraint->has_coercion) { | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | my $coercion = $type_constraint->coercion; | |||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | ▶ | $value = $coercion->coerce($value) // $value; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$coercion->coerce($value) // $value
MC/DC0%0/2
$coercion->coerce($value) // $value
$coercion->coerce($value)
$value
Truth table33%1/3
A // B
A= $coercion->coerce($value)B= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 109 | my $error = $attribute->cmd_type_constraint_check($value); | |||||||||||||||||||||||||||||||||||||||||
| 483 | 109 | ▶ | if (defined $error) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 6 | push(@errors, | |||||||||||||||||||||||||||||||||||||||||
| 485 | $self->command_message( | ||||||||||||||||||||||||||||||||||||||||||
| 486 | header => "Invalid value for '".$attribute->cmd_name_primary."'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 487 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 488 | body => $error, | ||||||||||||||||||||||||||||||||||||||||||
| 489 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 490 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 6 | $value = $raw->[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 117 | return ($value,\@errors); | |||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 45 | ▶ | sub command_candidates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_candidates: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 45 | my ($self,$command) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 45 | my $lc_command = lc($command); | |||||||||||||||||||||||||||||||||||||||||
| 505 | 45 | my $commands = $self->app_commands; | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 45 | my @candidates; | |||||||||||||||||||||||||||||||||||||||||
| 508 | 45 | my $candidate_length = length($command); | |||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | # Compare all commands to find matching candidates | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 45 | foreach my $command_name (keys %$commands) { | |||||||||||||||||||||||||||||||||||||||||
| 512 | 320 | ▶ | if ($command_name eq $lc_command) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 1 | return $command_name; | |||||||||||||||||||||||||||||||||||||||||
| 514 | } elsif ($lc_command eq substr($command_name,0,$candidate_length)) { | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 32 | push(@candidates,$command_name); | |||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | 44 | return [ sort @candidates ]; | |||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 65 | ▶ | sub command_find { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_find: called CC=14 SCAR=27.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 65 | my ($self,$commands) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 65 | my $parsed_argv = MooseX::App::ParsedArgv->instance; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 65 | my $all_commands = $self->app_commands; | |||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | # Get parts | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 65 | my (@parts,@command_parts); | |||||||||||||||||||||||||||||||||||||||||
| 530 | 65 | ▶ | if (defined $commands) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 1 | ▶ | if (ref($commands) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | @parts = map { lc } @{$commands}; | |||||||||||||||||||||||||||||||||||||||||
| 533 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 1 | @parts = ( lc($commands) ); | |||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||
| 536 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 64 | @parts = $parsed_argv->elements_argv; | |||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | # Extract possible parts | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 65 | foreach my $part (@parts) { | |||||||||||||||||||||||||||||||||||||||||
| 542 | # Anyting staring with a dash cannot be a command | ||||||||||||||||||||||||||||||||||||||||||
| 543 | last | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 145 | ▶ | if $part =~ m/^-/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | 88 | push(@command_parts,lc($part)); | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | # Shortcut | ||||||||||||||||||||||||||||||||||||||||||
| 549 | return | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 65 | ▶ | unless scalar @command_parts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | # basically do a longest-match search | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 65 | for my $index (reverse(0..$#command_parts)) { | |||||||||||||||||||||||||||||||||||||||||
| 554 | 86 | my $command = join ' ', @command_parts[0..$index]; | |||||||||||||||||||||||||||||||||||||||||
| 555 | 86 | ▶ | if( $all_commands->{$command} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 37 | $parsed_argv->shift_argv for 0..$index; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 37 | return $command; | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | # didn't find an exact match, let's go to plan B | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 28 | foreach my $index (reverse(0..$#command_parts)) { | |||||||||||||||||||||||||||||||||||||||||
| 563 | 42 | my $command = join ' ', @command_parts[0..$index]; | |||||||||||||||||||||||||||||||||||||||||
| 564 | 42 | my $candidate = $self->command_candidates($command); | |||||||||||||||||||||||||||||||||||||||||
| 565 | 42 | ▶ | if (ref $candidate eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $parsed_argv->shift_argv; | |||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | return $candidate; | |||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 42 | ▶ | if (@{$candidate} == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 15 | next; | |||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 27 | elsif (@{$candidate} == 1) { | |||||||||||||||||||||||||||||||||||||||||
| 573 | 27 | ▶ | if ($self->app_fuzzy) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 26 | $parsed_argv->shift_argv; | |||||||||||||||||||||||||||||||||||||||||
| 575 | 26 | return $candidate->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 576 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 577 | 1 | return $self->command_message( | |||||||||||||||||||||||||||||||||||||||||
| 578 | header => "Unknown command '$command'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 579 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 580 | body => "Did you mean '".$candidate->[0]."'?", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 581 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||
| 584 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 585 | return $self->command_message( | ||||||||||||||||||||||||||||||||||||||||||
| 586 | header => "Ambiguous command '$command'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 587 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 588 | body => "Which command did you mean?\n". # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | MooseX::App::Utils::format_list(map { [ $_ ] } sort @{$candidate}), | |||||||||||||||||||||||||||||||||||||||||
| 590 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 1 | my $command = $command_parts[0]; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | return $self->command_message( | |||||||||||||||||||||||||||||||||||||||||
| 596 | header => "Unknown command '$command'", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 597 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 598 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | 75 | ▶ | sub command_parser_hints { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_parser_hints: called CC=28 SCAR=33.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 602 | 75 | my ($self,$metaclass) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 75 | ▶ | $metaclass ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$metaclass ||= $self
MC/DC0%0/2
$metaclass ||= $self
$metaclass
$self
Truth table33%1/3
A ||= B
A= $metaclassB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | 75 | my %hints; | |||||||||||||||||||||||||||||||||||||||||
| 607 | my %names; | ||||||||||||||||||||||||||||||||||||||||||
| 608 | 75 | my $return = { permute => [], novalue => [], fixedvalue => {} }; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 75 | foreach my $attribute ($self->command_usage_attributes($metaclass,[qw(option proto)])) { | |||||||||||||||||||||||||||||||||||||||||
| 610 | 352 | my $permute = 0; | |||||||||||||||||||||||||||||||||||||||||
| 611 | 352 | my $bool = 0; | |||||||||||||||||||||||||||||||||||||||||
| 612 | 352 | my $type_constraint = $attribute->type_constraint; | |||||||||||||||||||||||||||||||||||||||||
| 613 | 352 | ▶ | if ($type_constraint) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | 313 | ▶ | $permute = 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type_constraint->is_a_type_of("ArrayRef") or $type_constraint->is_a_type_of("HashRef")
MC/DC100%2/2
$type_constraint->is_a_type_of("ArrayRef") or $type_constraint->is_a_type_of("HashRef")
$type_constraint->is_a_type_of("ArrayRef")
$type_constraint->is_a_type_of("HashRef")
Truth table100%3/3
A or B
A= $type_constraint->is_a_type_of("ArrayRef")B= $type_constraint->is_a_type_of("HashRef")
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | if $type_constraint->is_a_type_of('ArrayRef') | ||||||||||||||||||||||||||||||||||||||||||
| 616 | || $type_constraint->is_a_type_of('HashRef'); | ||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | 313 | ▶ | $bool = 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | if $type_constraint->is_a_type_of('Bool'); | ||||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | 352 | ▶ | my $hint = { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$bool || $attribute->cmd_count
MC/DC100%2/2
$bool || $attribute->cmd_count
$bool
$attribute->cmd_count
Truth table100%3/3
A || B
A= $boolB= $attribute->cmd_count
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | name => $attribute->name, | ||||||||||||||||||||||||||||||||||||||||||
| 624 | bool => $bool, | ||||||||||||||||||||||||||||||||||||||||||
| 625 | novalue => $bool || $attribute->cmd_count, | ||||||||||||||||||||||||||||||||||||||||||
| 626 | permute => $permute, | ||||||||||||||||||||||||||||||||||||||||||
| 627 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 352 | foreach my $name ($attribute->cmd_name_list) { | |||||||||||||||||||||||||||||||||||||||||
| 630 | 577 | $names{$name} = $hints{$name} = $hint; | |||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | # Negated values | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 352 | ▶ | if ($bool) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | 145 | $hint->{fixedvalue} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 636 | 145 | ▶ | if ($attribute->has_cmd_negate) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | 11 | my $hint_neg = { %{$hint} }; # shallow copy | |||||||||||||||||||||||||||||||||||||||||
| 638 | 11 | $hint_neg->{fixedvalue} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 639 | 11 | foreach my $name (@{$attribute->cmd_negate}) { | |||||||||||||||||||||||||||||||||||||||||
| 640 | 14 | $names{$name} = $hints{$name} = $hint_neg; | |||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||
| 643 | } elsif ($attribute->cmd_count) { | ||||||||||||||||||||||||||||||||||||||||||
| 644 | 6 | $hint->{fixedvalue} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||
| 648 | 75 | ▶ | if ($self->app_fuzzy) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 649 | 73 | ▶ | my $length = max(map { length($_) } keys %names) // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
&max(map({length $_;} keys %names)) // 0
MC/DC0%0/1
&max(map({length $_;} keys %names)) // 0
&max(map({length $_;} keys %names))
Truth table50%1/2
A
A= &max(map({length $_;} keys %names))
| |||||||||||||||||||||||||||||||||||||||||||
| 650 | 73 | foreach my $l (reverse(2..$length)) { | |||||||||||||||||||||||||||||||||||||||||
| 651 | 638 | my %tmp; | |||||||||||||||||||||||||||||||||||||||||
| 652 | 638 | foreach my $name (keys %names) { | |||||||||||||||||||||||||||||||||||||||||
| 653 | next | ||||||||||||||||||||||||||||||||||||||||||
| 654 | 5080 | ▶ | if length($name) < $l; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 2287 | my $short_name = substr($name,0,$l); | |||||||||||||||||||||||||||||||||||||||||
| 656 | next | ||||||||||||||||||||||||||||||||||||||||||
| 657 | 2287 | ▶ | if defined $hints{$short_name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 1864 | ▶ | $tmp{$short_name} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$tmp{$short_name} ||= []
MC/DC100%1/1
$tmp{$short_name} ||= []
$tmp{$short_name}
Truth table100%2/2
A
A= $tmp{$short_name}
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | next | ||||||||||||||||||||||||||||||||||||||||||
| 660 | if defined $tmp{$short_name}->[0] | ||||||||||||||||||||||||||||||||||||||||||
| 661 | 1864 | ▶ | && $tmp{$short_name}->[0]->{name} eq $names{$name}->{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $tmp{$short_name}[0] and $tmp{$short_name}[0]{"name"} eq $names{$name}{"name"}
MC/DC0%0/2
defined $tmp{$short_name}[0] and $tmp{$short_name}[0]{"name"} eq $names{$name}{"name"}
defined $tmp{$short_name}[0]
$tmp{$short_name}[0]{"name"} eq $names{$name}{"name"}
Truth table66%2/3
A and B
A= defined $tmp{$short_name}[0]B= $tmp{$short_name}[0]{"name"} eq $names{$name}{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 662 | 1864 | push(@{$tmp{$short_name}},$names{$name}) | |||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||
| 664 | 638 | foreach my $short_name (keys %tmp) { | |||||||||||||||||||||||||||||||||||||||||
| 665 | next | ||||||||||||||||||||||||||||||||||||||||||
| 666 | 1599 | ▶ | if scalar @{$tmp{$short_name}} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | 1350 | $hints{$short_name} = $tmp{$short_name}->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | 75 | foreach my $name (keys %hints) { | |||||||||||||||||||||||||||||||||||||||||
| 673 | 1940 | ▶ | if ($hints{$name}->{novalue}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 674 | 1105 | push(@{$return->{novalue}},$name); | |||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 1940 | ▶ | if ($hints{$name}->{permute}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | 97 | push(@{$return->{permute}},$name); | |||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||
| 679 | 1940 | ▶ | if (defined $hints{$name}->{fixedvalue}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | 1105 | $return->{fixedvalue}{$name} = $hints{$name}->{fixedvalue}; | |||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | #warn Data::Dumper::Dumper($return); | ||||||||||||||||||||||||||||||||||||||||||
| 686 | 75 | return $return; | |||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | 159 | ▶ | sub command_message { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | 159 | my ($self,@args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 691 | 159 | my $messageclass = $self->app_messageclass; | |||||||||||||||||||||||||||||||||||||||||
| 692 | 159 | Class::Load::load_class($messageclass); | |||||||||||||||||||||||||||||||||||||||||
| 693 | 159 | return $messageclass->new(@args); | |||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | 68 | ▶ | sub command_check_attributes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_check_attributes: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 697 | 68 | my ($self,$command_meta,$errors,$params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | 68 | ▶ | $command_meta ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$command_meta ||= $self
MC/DC0%0/2
$command_meta ||= $self
$command_meta
$self
Truth table33%1/3
A ||= B
A= $command_metaB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | # Check required values | ||||||||||||||||||||||||||||||||||||||||||
| 702 | 68 | foreach my $attribute ($self->command_usage_attributes($command_meta,[qw(option proto parameter)])) { | |||||||||||||||||||||||||||||||||||||||||
| 703 | 378 | ▶ | if ($attribute->is_required | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$attribute->is_required and not exists $$params{$attribute->name} and not $attribute->has_default
$attribute->is_required and not exists $$params{$attribute->name}
MC/DC100%3/3
$attribute->is_required and not exists $$params{$attribute->name} and not $attribute->has_default
$attribute->is_required
not exists $$params{$attribute->name}
not $attribute->has_default
Truth table100%4/4
A and not(B) and not(C)
A= $attribute->is_requiredB= not exists $$params{$attribute->name}C= not $attribute->has_default
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | && ! exists $params->{$attribute->name} | ||||||||||||||||||||||||||||||||||||||||||
| 705 | && ! $attribute->has_default) { | ||||||||||||||||||||||||||||||||||||||||||
| 706 | 7 | ▶ | push(@{$errors}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | $self->command_message( | ||||||||||||||||||||||||||||||||||||||||||
| 708 | header => "Required ".($attribute->cmd_type eq 'parameter' ? 'parameter':'option')." '".$attribute->cmd_name_primary."' missing", # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 709 | type => "error", | ||||||||||||||||||||||||||||||||||||||||||
| 710 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 711 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | 68 | return $errors; | |||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | 636 | ▶ | sub command_usage_attributes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_usage_attributes: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 719 | 636 | my ($self,$metaclass,$types) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | 636 | ▶ | $metaclass ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$metaclass ||= $self
MC/DC0%0/2
$metaclass ||= $self
$metaclass
$self
Truth table66%2/3
A ||= B
A= $metaclassB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | 636 | ▶ | $types ||= [qw(option proto)]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$types ||= ["option", "proto"]
MC/DC100%1/1
$types ||= ["option", "proto"]
$types
Truth table100%2/2
A
A= $types
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 636 | ▶ | if ('' eq ref $types) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 724 | 450 | $types = [$types]; | |||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | 636 | ▶ | unless ($metaclass->does_role('MooseX::App::Role::Common')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | Moose->throw_error('Class '.$metaclass->name.' is not a proper MooseX::App::Command class. You either need to use MooseX::App::Command or exclude this class via app_exclude') | |||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | 636 | my @return; | |||||||||||||||||||||||||||||||||||||||||
| 732 | 636 | foreach my $attribute ($metaclass->get_all_attributes) { | |||||||||||||||||||||||||||||||||||||||||
| 733 | next | ||||||||||||||||||||||||||||||||||||||||||
| 734 | 4678 | ▶ | unless $attribute->does('MooseX::App::Meta::Role::Attribute::Option') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$attribute->does("MooseX::App::Meta::Role::Attribute::Option") and $attribute->has_cmd_type
MC/DC100%2/2
$attribute->does("MooseX::App::Meta::Role::Attribute::Option") and $attribute->has_cmd_type
$attribute->does("MooseX::App::Meta::Role::Attribute::Option")
$attribute->has_cmd_type
Truth table100%3/3
A and B
A= $attribute->does("MooseX::App::Meta::Role::Attribute::Option")B= $attribute->has_cmd_type
| |||||||||||||||||||||||||||||||||||||||||||
| 735 | && $attribute->has_cmd_type; | ||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||
| 737 | next | ||||||||||||||||||||||||||||||||||||||||||
| 738 | 3227 | ▶ | unless first { $attribute->cmd_type eq $_ or 'all' eq $_ } @$types; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||
| 740 | 2025 | push(@return,$attribute); | |||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | return (sort { | ||||||||||||||||||||||||||||||||||||||||||
| 744 | 636 | ▶ | $a->cmd_position <=> $b->cmd_position || | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$a->cmd_position <=> $b->cmd_position || $a->cmd_usage_name cmp $b->cmd_usage_name
MC/DC0%0/2
$a->cmd_position <=> $b->cmd_position || $a->cmd_usage_name cmp $b->cmd_usage_name
$a->cmd_position <=> $b->cmd_position
$a->cmd_usage_name cmp $b->cmd_usage_name
Truth table33%1/3
A || B
A= $a->cmd_position <=> $b->cmd_positionB= $a->cmd_usage_name cmp $b->cmd_usage_name
| |||||||||||||||||||||||||||||||||||||||||||
| 745 | $a->cmd_usage_name cmp $b->cmd_usage_name | ||||||||||||||||||||||||||||||||||||||||||
| 746 | } @return); | ||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||
| 749 | 35 | ▶ | sub command_usage_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_usage_options: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 750 | 35 | my ($self,$metaclass,$headline) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | 35 | ▶ | $headline ||= 'options:'; # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$headline ||= "options:"
MC/DC0%0/1
$headline ||= "options:"
$headline
Truth table50%1/2
A
A= $headline
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | 35 | ▶ | $metaclass ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$metaclass ||= $self
MC/DC0%0/2
$metaclass ||= $self
$metaclass
$self
Truth table33%1/3
A ||= B
A= $metaclassB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||
| 755 | 35 | my @options; | |||||||||||||||||||||||||||||||||||||||||
| 756 | 35 | foreach my $attribute ($self->command_usage_attributes($metaclass,[qw(option proto)])) { | |||||||||||||||||||||||||||||||||||||||||
| 757 | 172 | push(@options,[ | |||||||||||||||||||||||||||||||||||||||||
| 758 | $attribute->cmd_usage_name(), | ||||||||||||||||||||||||||||||||||||||||||
| 759 | $attribute->cmd_usage_description() | ||||||||||||||||||||||||||||||||||||||||||
| 760 | ]); | ||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | return | ||||||||||||||||||||||||||||||||||||||||||
| 764 | 35 | ▶ | unless scalar @options > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 35 | return $self->command_message( | |||||||||||||||||||||||||||||||||||||||||
| 767 | header => $headline, | ||||||||||||||||||||||||||||||||||||||||||
| 768 | body => MooseX::App::Utils::format_list(@options), | ||||||||||||||||||||||||||||||||||||||||||
| 769 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | 35 | ▶ | sub command_usage_parameters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_usage_parameters: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 773 | 35 | my ($self,$metaclass,$headline) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | 35 | ▶ | $headline ||= 'parameter:'; # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$headline ||= "parameter:"
MC/DC0%0/1
$headline ||= "parameter:"
$headline
Truth table50%1/2
A
A= $headline
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 35 | ▶ | $metaclass ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$metaclass ||= $self
MC/DC0%0/2
$metaclass ||= $self
$metaclass
$self
Truth table33%1/3
A ||= B
A= $metaclassB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | 35 | my @parameters; | |||||||||||||||||||||||||||||||||||||||||
| 779 | 35 | foreach my $attribute ( | |||||||||||||||||||||||||||||||||||||||||
| 780 | 21 | sort { $a->cmd_position <=> $b->cmd_position } | |||||||||||||||||||||||||||||||||||||||||
| 781 | $self->command_usage_attributes($metaclass,'parameter') | ||||||||||||||||||||||||||||||||||||||||||
| 782 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 783 | 21 | push(@parameters,[ | |||||||||||||||||||||||||||||||||||||||||
| 784 | $attribute->cmd_usage_name(), | ||||||||||||||||||||||||||||||||||||||||||
| 785 | $attribute->cmd_usage_description() | ||||||||||||||||||||||||||||||||||||||||||
| 786 | ]); | ||||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | return | ||||||||||||||||||||||||||||||||||||||||||
| 790 | 35 | ▶ | unless scalar @parameters > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | 7 | return $self->command_message( | |||||||||||||||||||||||||||||||||||||||||
| 793 | header => $headline, | ||||||||||||||||||||||||||||||||||||||||||
| 794 | body => MooseX::App::Utils::format_list(@parameters), | ||||||||||||||||||||||||||||||||||||||||||
| 795 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | 29 | ▶ | sub command_usage_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_usage_header: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 29 | my ($self,$command_meta_class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | 29 | my $caller = $self->app_base; | |||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | 29 | my ($command_name,$usage); | |||||||||||||||||||||||||||||||||||||||||
| 804 | 29 | ▶ | if ($command_meta_class) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | 23 | $command_name = $self->command_class_to_command($command_meta_class->name); | |||||||||||||||||||||||||||||||||||||||||
| 806 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 807 | 6 | $command_name = '<command>'; | |||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | 29 | ▶ | $command_meta_class ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$command_meta_class ||= $self
MC/DC0%0/2
$command_meta_class ||= $self
$command_meta_class
$self
Truth table66%2/3
A ||= B
A= $command_meta_classB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 811 | 29 | ▶ | if ($command_meta_class->can('command_usage') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$command_meta_class->can("command_usage") and $command_meta_class->command_usage_predicate
MC/DC50%1/2
$command_meta_class->can("command_usage") and $command_meta_class->command_usage_predicate
$command_meta_class->can("command_usage")
$command_meta_class->command_usage_predicate
Truth table66%2/3
A and B
A= $command_meta_class->can("command_usage")B= $command_meta_class->command_usage_predicate
| |||||||||||||||||||||||||||||||||||||||||||
| 812 | && $command_meta_class->command_usage_predicate) { | ||||||||||||||||||||||||||||||||||||||||||
| 813 | 1 | $usage = MooseX::App::Utils::format_text($command_meta_class->command_usage); | |||||||||||||||||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||
| 816 | 29 | ▶ | unless (defined $usage) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 818 | 28 | $usage = "$caller $command_name "; | |||||||||||||||||||||||||||||||||||||||||
| 819 | 28 | my @parameter= $self->command_usage_attributes($command_meta_class,'parameter'); | |||||||||||||||||||||||||||||||||||||||||
| 820 | 28 | foreach my $attribute (@parameter) { | |||||||||||||||||||||||||||||||||||||||||
| 821 | 21 | ▶ | if ($attribute->is_required) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | 2 | $usage .= "<".$attribute->cmd_usage_name.'> '; | |||||||||||||||||||||||||||||||||||||||||
| 823 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 824 | 19 | $usage .= '['.$attribute->cmd_usage_name.'] '; | |||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||
| 827 | 28 | $usage .= "[long options...] | |||||||||||||||||||||||||||||||||||||||||
| 828 | $caller help | ||||||||||||||||||||||||||||||||||||||||||
| 829 | $caller $command_name --help"; | ||||||||||||||||||||||||||||||||||||||||||
| 830 | 28 | $usage = MooseX::App::Utils::format_text($usage); | |||||||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||
| 833 | 29 | return $self->command_message( | |||||||||||||||||||||||||||||||||||||||||
| 834 | header => 'usage:', # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 835 | body => $usage, | ||||||||||||||||||||||||||||||||||||||||||
| 836 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||
| 839 | 36 | ▶ | sub command_usage_description { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_usage_description: called CC=6 SCAR=18.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 840 | 36 | my ($self,$command_meta_class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | 36 | ▶ | $command_meta_class ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$command_meta_class ||= $self
MC/DC0%0/2
$command_meta_class ||= $self
$command_meta_class
$self
Truth table33%1/3
A ||= B
A= $command_meta_classB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 843 | 36 | ▶ | if ($command_meta_class->can('command_long_description') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$command_meta_class->can("command_long_description") and $command_meta_class->command_long_description_predicate
MC/DC50%1/2
$command_meta_class->can("command_long_description") and $command_meta_class->command_long_description_predicate
$command_meta_class->can("command_long_description")
$command_meta_class->command_long_description_predicate
Truth table66%2/3
A and B
A= $command_meta_class->can("command_long_description")B= $command_meta_class->command_long_description_predicate
| |||||||||||||||||||||||||||||||||||||||||||
| 844 | && $command_meta_class->command_long_description_predicate) { | ||||||||||||||||||||||||||||||||||||||||||
| 845 | 13 | return $self->command_message( | |||||||||||||||||||||||||||||||||||||||||
| 846 | header => 'description:', # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 847 | body => MooseX::App::Utils::format_text($command_meta_class->command_long_description), | ||||||||||||||||||||||||||||||||||||||||||
| 848 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 849 | ▶ | } elsif ($command_meta_class->can('command_short_description') | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$command_meta_class->can("command_short_description") and $command_meta_class->command_short_description_predicate
MC/DC50%1/2
$command_meta_class->can("command_short_description") and $command_meta_class->command_short_description_predicate
$command_meta_class->can("command_short_description")
$command_meta_class->command_short_description_predicate
Truth table66%2/3
A and B
A= $command_meta_class->can("command_short_description")B= $command_meta_class->command_short_description_predicate
| |||||||||||||||||||||||||||||||||||||||||||
| 850 | && $command_meta_class->command_short_description_predicate) { | ||||||||||||||||||||||||||||||||||||||||||
| 851 | 1 | return $self->command_message( | |||||||||||||||||||||||||||||||||||||||||
| 852 | header => 'short description:', # LOCALIZE | ||||||||||||||||||||||||||||||||||||||||||
| 853 | body => MooseX::App::Utils::format_text($command_meta_class->command_short_description), | ||||||||||||||||||||||||||||||||||||||||||
| 854 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 855 | } | ||||||||||||||||||||||||||||||||||||||||||
| 856 | 22 | return; | |||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||
| 859 | 55 | ▶ | sub command_class_to_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_class_to_command: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 860 | 55 | my ($self,$command_class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | 55 | my $commands = $self->app_commands; | |||||||||||||||||||||||||||||||||||||||||
| 863 | 55 | foreach my $element (keys %$commands) { | |||||||||||||||||||||||||||||||||||||||||
| 864 | 164 | ▶ | if ($command_class eq $commands->{$element}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | 55 | return $element; | |||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||
| 872 | 29 | ▶ | sub command_subcommands { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_subcommands: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 873 | 29 | my ($self,$command_meta_class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||
| 875 | 29 | ▶ | $command_meta_class ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$command_meta_class ||= $self
MC/DC0%0/2
$command_meta_class ||= $self
$command_meta_class
$self
Truth table33%1/3
A ||= B
A= $command_meta_classB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 876 | 29 | my $command_class = $command_meta_class->name; | |||||||||||||||||||||||||||||||||||||||||
| 877 | 29 | my $command_name = $self->command_class_to_command($command_class); | |||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||
| 879 | 29 | my $commands = $self->app_commands; | |||||||||||||||||||||||||||||||||||||||||
| 880 | 29 | my $subcommands = {}; | |||||||||||||||||||||||||||||||||||||||||
| 881 | 29 | foreach my $command (keys %{$commands}) { | |||||||||||||||||||||||||||||||||||||||||
| 882 | next | ||||||||||||||||||||||||||||||||||||||||||
| 883 | 145 | ▶ | if $command eq $command_name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$command eq $command_name or not $command =~ /^\Q$command_name\E\s(.+)/
MC/DC100%2/2
$command eq $command_name or not $command =~ /^\Q$command_name\E\s(.+)/
$command eq $command_name
not $command =~ /^\Q$command_name\E\s(.+)/
Truth table100%3/3
A or not(B)
A= $command eq $command_nameB= not $command =~ /^\Q$command_name\E\s(.+)/
| |||||||||||||||||||||||||||||||||||||||||||
| 884 | || $command !~ m/^\Q$command_name\E\s(.+)/; | ||||||||||||||||||||||||||||||||||||||||||
| 885 | 2 | $subcommands->{$1} = $commands->{$command}; | |||||||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||
| 888 | 29 | return $subcommands; | |||||||||||||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||
| 891 | 29 | ▶ | sub command_usage_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_usage_command: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 892 | 29 | my ($self,$command_meta_class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||
| 894 | 29 | ▶ | $command_meta_class ||= $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$command_meta_class ||= $self
MC/DC0%0/2
$command_meta_class ||= $self
$command_meta_class
$self
Truth table33%1/3
A ||= B
A= $command_meta_classB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||
| 896 | 29 | my @usage; | |||||||||||||||||||||||||||||||||||||||||
| 897 | 29 | push(@usage,$self->command_usage_header($command_meta_class)); | |||||||||||||||||||||||||||||||||||||||||
| 898 | 29 | push(@usage,$self->command_usage_description($command_meta_class)); | |||||||||||||||||||||||||||||||||||||||||
| 899 | 29 | push(@usage,$self->command_usage_parameters($command_meta_class,'parameters:')); # LOCALIZE | |||||||||||||||||||||||||||||||||||||||||
| 900 | 29 | push(@usage,$self->command_usage_options($command_meta_class,'options:')); # LOCALIZE | |||||||||||||||||||||||||||||||||||||||||
| 901 | 29 | push(@usage,$self->command_usage_subcommands('available subcommands:',$self->command_subcommands($command_meta_class))); # LOCALIZE | |||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | 29 | return @usage; | |||||||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||
| 906 | 6 | ▶ | sub command_usage_global { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_usage_global: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 907 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||
| 909 | 6 | my @usage; | |||||||||||||||||||||||||||||||||||||||||
| 910 | 6 | push(@usage,$self->command_usage_header()); | |||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||
| 912 | 6 | my $description = $self->command_usage_description($self); | |||||||||||||||||||||||||||||||||||||||||
| 913 | 6 | ▶ | push(@usage,$description) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 914 | if $description; | ||||||||||||||||||||||||||||||||||||||||||
| 915 | 6 | push(@usage,$self->command_usage_parameters($self,'global parameters:')); # LOCALIZE | |||||||||||||||||||||||||||||||||||||||||
| 916 | 6 | push(@usage,$self->command_usage_options($self,'global options:')); # LOCALIZE | |||||||||||||||||||||||||||||||||||||||||
| 917 | 6 | push(@usage,$self->command_usage_subcommands('available commands:',$self->app_commands)); # LOCALIZE | |||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||
| 919 | 6 | return @usage; | |||||||||||||||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||
| 922 | 35 | ▶ | sub command_usage_subcommands { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_usage_subcommands: called CC=7 SCAR=19.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 923 | 35 | my ($self,$headline,$commands) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | 35 | my @commands; | |||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | 35 | foreach my $command (keys %$commands) { | |||||||||||||||||||||||||||||||||||||||||
| 928 | 25 | my $class = $commands->{$command}; | |||||||||||||||||||||||||||||||||||||||||
| 929 | 25 | Class::Load::load_class($class); | |||||||||||||||||||||||||||||||||||||||||
| 930 | } | ||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | 35 | foreach my $command (keys %$commands) { | |||||||||||||||||||||||||||||||||||||||||
| 933 | 25 | my $class = $commands->{$command}; | |||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||
| 935 | 25 | ▶ | unless ($class->can('meta') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class->can("meta") and $class->DOES("MooseX::App::Role::Common")
MC/DC0%0/2
$class->can("meta") and $class->DOES("MooseX::App::Role::Common")
$class->can("meta")
$class->DOES("MooseX::App::Role::Common")
Truth table33%1/3
A and B
A= $class->can("meta")B= $class->DOES("MooseX::App::Role::Common")
| |||||||||||||||||||||||||||||||||||||||||||
| 936 | && $class->DOES('MooseX::App::Role::Common')) { | ||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | Moose->throw_error('Class '.$class.' is not a proper MooseX::App::Command class. You either need to use MooseX::App::Command or exclude this class via app_exclude') | |||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | 25 | my $command_description; | |||||||||||||||||||||||||||||||||||||||||
| 941 | 25 | ▶ | $command_description = $class->meta->command_short_description | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 942 | if $class->meta->can('command_short_description'); | ||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||
| 944 | 25 | ▶ | $command_description ||= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$command_description ||= ""
MC/DC100%1/1
$command_description ||= ""
$command_description
Truth table100%2/2
A
A= $command_description
| |||||||||||||||||||||||||||||||||||||||||||
| 945 | 25 | push(@commands,[$command,$command_description]); | |||||||||||||||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||
| 948 | 35 | @commands = sort { $a->[0] cmp $b->[0] } @commands; | |||||||||||||||||||||||||||||||||||||||||
| 949 | 35 | push(@commands,['help','Prints this usage information']); # LOCALIZE | |||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||
| 951 | 35 | return $self->command_message( | |||||||||||||||||||||||||||||||||||||||||
| 952 | header => $headline, | ||||||||||||||||||||||||||||||||||||||||||
| 953 | body => MooseX::App::Utils::format_list(@commands), | ||||||||||||||||||||||||||||||||||||||||||
| 954 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||
| 957 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||
| 959 | __END__ | ||||||||||||||||||||||||||||||||||||||||||