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