line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::CLI::Plugin::Config::YAML::Syck; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
App::CLI::Plugin::Config::YAML::Syck - for App::CLI::Extension config plugin module |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
1.2 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# MyApp.pm |
16
|
|
|
|
|
|
|
package MyApp; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use strict; |
19
|
|
|
|
|
|
|
use base qw(App::CLI::Extension); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# extension method |
22
|
|
|
|
|
|
|
__PACKAGE__->load_plugins(qw(Config::YAML::Syck)); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# extension method |
25
|
|
|
|
|
|
|
__PACKAGE__->config( config_file => "/path/to/config.yaml"); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# /path/to/config.yaml |
31
|
|
|
|
|
|
|
# --- |
32
|
|
|
|
|
|
|
# name: kurt |
33
|
|
|
|
|
|
|
# age: 27 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# MyApp/Hello.pm |
36
|
|
|
|
|
|
|
package MyApp::Hello; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use strict; |
39
|
|
|
|
|
|
|
use base qw(App::CLI::Command); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub run { |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my($self, @argv) = @_; |
44
|
|
|
|
|
|
|
print "Hello! my name is " . $self->config->{name} . "\n"; |
45
|
|
|
|
|
|
|
print "age is " . "$self->config->{age}\n"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# myapp |
49
|
|
|
|
|
|
|
#!/usr/bin/perl |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
use strict; |
52
|
|
|
|
|
|
|
use MyApp; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
MyApp->dispatch; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# execute |
57
|
|
|
|
|
|
|
[kurt@localhost ~] ./myapp hello |
58
|
|
|
|
|
|
|
Hello! my name is kurt |
59
|
|
|
|
|
|
|
age is 27 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 DESCRIPTION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
App::CLI::Extension YAML::Syck Configuration plugin module |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
The priority of the config file (name of the execute file in the case of *myapp*) |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1. /etc/myapp.yml |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
2. /usr/local/etc/myapp.yaml |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
3. $HOME/.myapp.yml |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
4. $APPCLI_CONFIGFILE(environ variable. if exists) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
5. command line option |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
myapp hello --configfile=/path/to/config.yml |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
6. config method setting |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__PACKAGE__->config(config_file => "/path/to/config.yml"); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
4
|
|
|
4
|
|
913412
|
use strict; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
156
|
|
86
|
4
|
|
|
4
|
|
3828
|
use FindBin qw($Script); |
|
4
|
|
|
|
|
16576
|
|
|
4
|
|
|
|
|
625
|
|
87
|
4
|
|
|
4
|
|
31
|
use File::Spec; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
37
|
|
88
|
4
|
|
|
4
|
|
3889
|
use YAML::Syck; |
|
4
|
|
|
|
|
9936
|
|
|
4
|
|
|
|
|
12395
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
our $VERSION = '1.2'; |
91
|
|
|
|
|
|
|
our @CONFIG_SEARCH_PATH = ("/etc", "/usr/local/etc", $ENV{HOME}); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 EXTENDED METHOD |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 setup |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub setup { |
102
|
|
|
|
|
|
|
|
103
|
3
|
|
|
3
|
1
|
23023
|
my($self, @argv) = @_; |
104
|
3
|
|
|
|
|
14
|
my $config_file_name = "${Script}.yml"; |
105
|
|
|
|
|
|
|
|
106
|
3
|
|
|
|
|
11
|
foreach my $search_path(@CONFIG_SEARCH_PATH){ |
107
|
|
|
|
|
|
|
|
108
|
9
|
100
|
|
|
|
128
|
my $file = File::Spec->catfile($search_path, (($search_path eq $ENV{HOME}) ? ".$config_file_name" : $config_file_name)); |
109
|
9
|
50
|
33
|
|
|
229
|
if(-e $file && -f $file){ |
110
|
0
|
|
|
|
|
0
|
$self->config(LoadFile($file)); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
3
|
100
|
66
|
|
|
24
|
if(exists $ENV{APPCLI_CONFIGFILE} && defined $ENV{APPCLI_CONFIGFILE}){$self->config(LoadFile($ENV{APPCLI_CONFIGFILE})); |
|
1
|
|
|
|
|
7
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
3
|
100
|
66
|
|
|
750
|
if(exists $self->{configfile} && defined $self->{configfile}){ |
118
|
1
|
|
|
|
|
25
|
$self->config(LoadFile($self->{configfile})); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
3
|
100
|
66
|
|
|
485
|
if(exists $self->config->{config_file} && defined $self->config->{config_file}){ |
122
|
1
|
|
|
|
|
127
|
$self->config(LoadFile($self->config->{config_file})); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
3
|
|
|
|
|
644
|
$self->maybe::next::method(@argv); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |