| 1 | # ============================================================================ | ||||||||||||||||||||||||||||
| 2 | package MooseX::App::Plugin::Config::Meta::Class; | ||||||||||||||||||||||||||||
| 3 | # ============================================================================ | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 21 | ▶ | around 'command_proto' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 12 | 21 | my ($orig,$self,$metaclass) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 21 | my ($result,$errors) = $self->$orig($metaclass); | |||||||||||||||||||||||||||
| 15 | delete $result->{config} | ||||||||||||||||||||||||||||
| 16 | 21 | ▶ | unless defined $result->{config}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 21 | return $self->proto_config($metaclass,$result,$errors); | |||||||||||||||||||||||||||
| 19 | 7 | }; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 21 | ▶ | sub proto_config { | ||||||||||||||||||||||||||
|
Subroutine
proto_config: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 21 | my ($self,$metaclass,$result,$errors) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Check if we have a config | ||||||||||||||||||||||||||||
| 25 | return ($result,$errors) | ||||||||||||||||||||||||||||
| 26 | 21 | ▶ | unless defined $result->{config}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Read config | ||||||||||||||||||||||||||||
| 29 | 4 | my $config_file = $result->{config}; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 4 | ▶ | unless (-e $config_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | push(@{$errors}, | |||||||||||||||||||||||||||
| 33 | $self->command_message( | ||||||||||||||||||||||||||||
| 34 | header => "Could not find config file '".$config_file."'", | ||||||||||||||||||||||||||||
| 35 | type => "error", | ||||||||||||||||||||||||||||
| 36 | ), | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | 1 | return ($result,$errors); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | my $configs = Config::Any->load_files({ | |||||||||||||||||||||||||||
| 42 | files => [ $config_file ], | ||||||||||||||||||||||||||||
| 43 | use_ext => 1, | ||||||||||||||||||||||||||||
| 44 | }); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | my $command_name = $self->command_class_to_command($metaclass->name); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 3 | my ($config_data) = values %{$configs->[0]}; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # Merge | ||||||||||||||||||||||||||||
| 51 | 3 | ▶ | $config_data->{global} ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$config_data->{"global"} ||= {}
MC/DC0%0/1
$config_data->{"global"} ||= {}
$config_data->{"global"}
Truth table50%1/2
A
A= $config_data->{"global"}
| |||||||||||||||||||||||||||||
| 52 | 3 | ▶ | $config_data->{$command_name} ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$config_data->{$command_name} ||= {}
MC/DC100%1/1
$config_data->{$command_name} ||= {}
$config_data->{$command_name}
Truth table100%2/2
A
A= $config_data->{$command_name}
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Set config data | ||||||||||||||||||||||||||||
| 55 | 3 | $result->{config} = $result->{config}; | |||||||||||||||||||||||||||
| 56 | 3 | $result->{_config_data} = $config_data; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # Lopp all attributes | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 3 | foreach my $attribute ($self->command_usage_attributes($metaclass,'all')) { | |||||||||||||||||||||||||||
| 61 | 14 | my $attribute_name = $attribute->name; | |||||||||||||||||||||||||||
| 62 | next | ||||||||||||||||||||||||||||
| 63 | 14 | ▶ | if $attribute_name eq 'config' || $attribute_name eq 'help_flag'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$attribute_name eq "config" or $attribute_name eq "help_flag"
MC/DC100%2/2
$attribute_name eq "config" or $attribute_name eq "help_flag"
$attribute_name eq "config"
$attribute_name eq "help_flag"
Truth table100%3/3
A or B
A= $attribute_name eq "config"B= $attribute_name eq "help_flag"
| |||||||||||||||||||||||||||||
| 64 | $result->{$attribute_name} = $config_data->{global}{$attribute_name} | ||||||||||||||||||||||||||||
| 65 | 8 | ▶ | if defined $config_data->{global}{$attribute_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | $result->{$attribute_name} = $config_data->{$command_name}{$attribute_name} | ||||||||||||||||||||||||||||
| 67 | 8 | ▶ | if defined $config_data->{$command_name}{$attribute_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 3 | return ($result,$errors); | |||||||||||||||||||||||||||
| 71 | }; | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 7 | 1; | |||||||||||||||||||||||||||