line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ============================================================================ |
2
|
|
|
|
|
|
|
package MooseX::App::Plugin::Config::Meta::Class; |
3
|
|
|
|
|
|
|
# ============================================================================ |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
4259
|
use 5.010; |
|
6
|
|
|
|
|
14
|
|
6
|
6
|
|
|
6
|
|
25
|
use utf8; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
43
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
116
|
use namespace::autoclean; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
37
|
|
9
|
6
|
|
|
6
|
|
376
|
use Moose::Role; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
41
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
around 'command_proto' => sub { |
12
|
|
|
|
|
|
|
my ($orig,$self,$metaclass) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my ($result,$errors) = $self->$orig($metaclass); |
15
|
|
|
|
|
|
|
delete $result->{config} |
16
|
|
|
|
|
|
|
unless defined $result->{config}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
return $self->proto_config($metaclass,$result,$errors); |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub proto_config { |
22
|
20
|
|
|
20
|
0
|
48
|
my ($self,$metaclass,$result,$errors) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Check if we have a config |
25
|
|
|
|
|
|
|
return ($result,$errors) |
26
|
20
|
100
|
|
|
|
121
|
unless defined $result->{config}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Read config |
29
|
4
|
|
|
|
|
18
|
my $config_file = Path::Class::File->new($result->{config}); |
30
|
|
|
|
|
|
|
|
31
|
4
|
100
|
|
|
|
429
|
unless (-e $config_file->stringify) { |
32
|
1
|
|
|
|
|
109
|
push(@{$errors}, |
|
1
|
|
|
|
|
12
|
|
33
|
|
|
|
|
|
|
$self->command_message( |
34
|
|
|
|
|
|
|
header => "Could not find config file '".$config_file->stringify."'", |
35
|
|
|
|
|
|
|
type => "error", |
36
|
|
|
|
|
|
|
), |
37
|
|
|
|
|
|
|
); |
38
|
1
|
|
|
|
|
19
|
return ($result,$errors); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
194
|
my $config_file_name = $config_file->stringify; |
42
|
3
|
|
|
|
|
96
|
my $configs = Config::Any->load_files({ |
43
|
|
|
|
|
|
|
files => [ $config_file_name ], |
44
|
|
|
|
|
|
|
use_ext => 1, |
45
|
|
|
|
|
|
|
}); |
46
|
|
|
|
|
|
|
|
47
|
3
|
|
|
|
|
38718
|
my $command_name = $self->command_class_to_command($metaclass->name); |
48
|
|
|
|
|
|
|
|
49
|
3
|
|
|
|
|
7
|
my ($config_data) = values %{$configs->[0]}; |
|
3
|
|
|
|
|
20
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Merge |
52
|
3
|
|
50
|
|
|
16
|
$config_data->{global} ||= {}; |
53
|
3
|
|
100
|
|
|
20
|
$config_data->{$command_name} ||= {}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Set config data |
56
|
3
|
|
|
|
|
13
|
$result->{config} = $result->{config}; |
57
|
3
|
|
|
|
|
13
|
$result->{_config_data} = $config_data; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Lopp all attributes |
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
|
|
30
|
foreach my $attribute ($self->command_usage_attributes($metaclass,'all')) { |
62
|
14
|
|
|
|
|
65
|
my $attribute_name = $attribute->name; |
63
|
|
|
|
|
|
|
next |
64
|
14
|
100
|
100
|
|
|
110
|
if $attribute_name eq 'config' || $attribute_name eq 'help_flag'; |
65
|
|
|
|
|
|
|
$result->{$attribute_name} = $config_data->{global}{$attribute_name} |
66
|
8
|
100
|
|
|
|
29
|
if defined $config_data->{global}{$attribute_name}; |
67
|
|
|
|
|
|
|
$result->{$attribute_name} = $config_data->{$command_name}{$attribute_name} |
68
|
8
|
100
|
|
|
|
36
|
if defined $config_data->{$command_name}{$attribute_name}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
3
|
|
|
|
|
134
|
return ($result,$errors); |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |