App/Plugin/Config/Meta/Class.pm

filter: Statementstmt 100% 38 / 38 Branchbran 100% 12 / 12 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 95.5% 65 / 68 CC 11 SCAR 19.1
CC
11
Cov
98%
proto_config
10.0
__ANON__
2.0
BEGIN
1.0
CRAP 6.8
« App/Role/Base.pm ↑ Summary App/Message/Envelope.pm »
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
BranchTrueFalseTotal
unless defined $result->{"config"} 17 4 21
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
BranchTrueFalseTotal
unless defined $result->{"config"} 17 4 21
27  
28 # Read config
29 4 my $config_file = $result->{config};
30  
31 4 ▶ unless (-e $config_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $config_file) 1 3 4
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"} ||= {}
l!l
30
MC/DC0%0/1
$config_data->{"global"} ||= {}
$config_data->{"global"}
Truth table50%1/2
A
A= $config_data->{"global"}
Aresult
11
00
52 3 ▶ $config_data->{$command_name} ||= {};
Condition100%2/2
$config_data->{$command_name} ||= {}
l!l
21
MC/DC100%1/1
$config_data->{$command_name} ||= {}
$config_data->{$command_name}
Truth table100%2/2
A
A= $config_data->{$command_name}
Aresult
11
00
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
BranchTrueFalseTotal
if $attribute_name eq "config" or $attribute_name eq "help_flag" 6 8 14
Condition100%3/3
$attribute_name eq "config" or $attribute_name eq "help_flag"
l!l&&r!l&&!r
338
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"
ABresult
1X1
011
000
64 $result->{$attribute_name} = $config_data->{global}{$attribute_name}
65 8 ▶ if defined $config_data->{global}{$attribute_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config_data->{"global"}{$attribute_name} 3 5 8
66 $result->{$attribute_name} = $config_data->{$command_name}{$attribute_name}
67 8 ▶ if defined $config_data->{$command_name}{$attribute_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config_data->{$command_name}{$attribute_name} 4 4 8
68 }
69  
70 3 return ($result,$errors);
71 };
72  
73 7 1;
« App/Role/Base.pm ↑ Summary App/Message/Envelope.pm »