line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ============================================================================ |
2
|
|
|
|
|
|
|
package MooseX::App::Plugin::Config; |
3
|
|
|
|
|
|
|
# ============================================================================ |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
5008
|
use 5.010; |
|
6
|
|
|
|
|
22
|
|
6
|
6
|
|
|
6
|
|
35
|
use utf8; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
49
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
157
|
use namespace::autoclean; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
47
|
|
9
|
6
|
|
|
6
|
|
735
|
use Moose::Role; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
57
|
|
10
|
6
|
|
|
6
|
|
37519
|
use MooseX::App::Role; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
26
|
|
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
20738
|
use Config::Any; |
|
6
|
|
|
|
|
45104
|
|
|
6
|
|
|
|
|
711
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'config' => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
predicate => 'has_config', |
17
|
|
|
|
|
|
|
documentation => q[Path to command config file], |
18
|
|
|
|
|
|
|
traits => ['MooseX::App::Meta::Role::Attribute::Option'], |
19
|
|
|
|
|
|
|
cmd_type => 'proto', |
20
|
|
|
|
|
|
|
cmd_position => 99990, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has '_config_data' => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
isa => 'HashRef', |
26
|
|
|
|
|
|
|
predicate => 'has_config_data', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub plugin_metaroles { |
30
|
5
|
|
|
5
|
0
|
16
|
my ($self,$class) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return { |
33
|
5
|
|
|
|
|
83
|
class => ['MooseX::App::Plugin::Config::Meta::Class'], |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=encoding utf8 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
MooseX::App::Plugin::Config - Config files your MooseX::App applications |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
In your base class: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
package MyApp; |
52
|
|
|
|
|
|
|
use MooseX::App qw(Config); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
option 'global_option' => ( |
55
|
|
|
|
|
|
|
is => 'rw', |
56
|
|
|
|
|
|
|
isa => 'Int', |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
In your command class: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package MyApp::Some_Command; |
62
|
|
|
|
|
|
|
use MooseX::App::Command; |
63
|
|
|
|
|
|
|
extends qw(MyApp); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
option 'some_option' => ( |
66
|
|
|
|
|
|
|
is => 'rw', |
67
|
|
|
|
|
|
|
isa => 'Str', |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Now create a config file (see L<Config::Any>) eg. a yaml file: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
--- |
73
|
|
|
|
|
|
|
global: |
74
|
|
|
|
|
|
|
global_option: 123 |
75
|
|
|
|
|
|
|
some_command: |
76
|
|
|
|
|
|
|
global_option: 234 |
77
|
|
|
|
|
|
|
some_option: "hello world" |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The user can now call the program with a config file: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
bash$ myapp some_command --config /path/to/config.yml |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 config |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Read the config filename |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 _config_data |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The full content of the loaded config file |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SEE ALSO |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
L<Config::Any> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |