| 1 | # ============================================================================ | ||||||||||||||||||||
| 2 | package MooseX::App::Role::Base; | ||||||||||||||||||||
| 3 | # ============================================================================ | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 16 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 16 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 16 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 16 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 75 | ▶ | sub initialize_command_class { | ||||||||||||||||||
|
Subroutine
initialize_command_class: called CC=10 SCAR=23.3
Pod
undocumented
| |||||||||||||||||||||
| 12 | 75 | my ($class,$command_class,%args) = @_; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 75 | my $meta = $class->meta; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 75 | ▶ | Moose->throw_error('initialize_command_class is a class method') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | if blessed($class); | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 75 | my ($ok,$error) = Class::Load::try_load_class($command_class); | |||||||||||||||||||
| 20 | 75 | ▶ | unless ($ok) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 0 | Moose->throw_error($error); | |||||||||||||||||||
| 22 | } | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 75 | ▶ | my $command_meta = $command_class->meta || $meta; | ||||||||||||||||||
|
Condition33%1/3
$command_class->meta || $meta
MC/DC0%0/2
$command_class->meta || $meta
$command_class->meta
$meta
Truth table33%1/3
A || B
A= $command_class->metaB= $meta
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # Build MooseX::App::ParsedArgv and set hints | ||||||||||||||||||||
| 27 | 75 | my $parsed_argv = MooseX::App::ParsedArgv->instance(); | |||||||||||||||||||
| 28 | 75 | my $hints = $meta->command_parser_hints($command_meta); | |||||||||||||||||||
| 29 | 75 | $parsed_argv->hints_fixedvalue($hints->{fixedvalue}); | |||||||||||||||||||
| 30 | 75 | $parsed_argv->hints_novalue($hints->{novalue}); | |||||||||||||||||||
| 31 | 75 | ▶ | if ($meta->app_permute) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 34 | $parsed_argv->hints_permute($hints->{permute}); | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 75 | my ($proto_result,$proto_errors) = $meta->command_proto($command_meta); | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # TODO return some kind of null class object | ||||||||||||||||||||
| 38 | return | ||||||||||||||||||||
| 39 | 75 | ▶ | unless defined $proto_result; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 75 | my @errors = @{$proto_errors}; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | # Return user-requested help | ||||||||||||||||||||
| 44 | 75 | ▶ | if ($proto_result->{help_flag}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 6 | return MooseX::App::Message::Envelope->new( | |||||||||||||||||||
| 46 | $meta->command_usage_command($command_class->meta), | ||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 69 | my ($result,$errors) = $meta->command_args($command_meta); | |||||||||||||||||||
| 51 | 68 | push(@errors,@{$errors}); | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 68 | my %params; | |||||||||||||||||||
| 54 | 68 | ▶ | if ($meta->app_prefer_commandline) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | %params = ( | ||||||||||||||||||||
| 56 | %args, # configs passed to new | ||||||||||||||||||||
| 57 | 7 | %{ $proto_result }, # config params | |||||||||||||||||||
| 58 | 7 | %{ $result }, # params from CLI | |||||||||||||||||||
| 59 | ); | ||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||
| 61 | %params = ( | ||||||||||||||||||||
| 62 | 61 | %{ $proto_result }, # config params | |||||||||||||||||||
| 63 | 61 | %{ $result }, # params from CLI | |||||||||||||||||||
| 64 | %args, # configs passed to new | ||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 68 | $meta->command_check_attributes($command_meta,\@errors,\%params); | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 68 | ▶ | if (scalar @errors) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 23 | return MooseX::App::Message::Envelope->new( | |||||||||||||||||||
| 72 | @errors, | ||||||||||||||||||||
| 73 | $meta->command_usage_command($command_meta), | ||||||||||||||||||||
| 74 | 1, # exitcode | ||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 45 | my $command_object = $command_class->new( | |||||||||||||||||||
| 79 | %params, | ||||||||||||||||||||
| 80 | extra_argv => [ $parsed_argv->extra ], | ||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 45 | ▶ | if (scalar @errors) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 0 | return MooseX::App::Message::Envelope->new( | |||||||||||||||||||
| 85 | @errors, | ||||||||||||||||||||
| 86 | $meta->command_usage_command($command_meta), | ||||||||||||||||||||
| 87 | 1, # exitcode | ||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 45 | return $command_object; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 16 | 1; | |||||||||||||||||||