| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Egg::Plugin::ConfigLoader; |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# $Id: ConfigLoader.pm 337 2008-05-14 12:30:09Z lushe $ |
|
6
|
|
|
|
|
|
|
# |
|
7
|
1
|
|
|
1
|
|
453
|
use strict; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
41
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
405
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '3.00'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _load_config { |
|
13
|
0
|
|
|
0
|
|
|
my $class= shift; |
|
14
|
0
|
0
|
|
|
|
|
my $conf = $_[0] ? ($_[1] ? {@_}: $_[0]): 0; |
|
|
|
0
|
|
|
|
|
|
|
15
|
0
|
0
|
0
|
|
|
|
if ($conf and ref($conf) eq 'SCALAR') { |
|
|
|
0
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $path= $$conf; |
|
17
|
0
|
|
|
|
|
|
$path=~s{/+$} []; |
|
18
|
0
|
|
|
|
|
|
my $name_lc= $class->lc_namespace; |
|
19
|
0
|
0
|
|
|
|
|
my $yaml= $path=~m{\.ya?ml$}i ? $path |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
: -e "$path/etc/${name_lc}.yaml" ? "$path/etc/${name_lc}.yaml" |
|
21
|
|
|
|
|
|
|
: -e "$path/etc/${name_lc}.yml" ? "$path/etc/${name_lc}.yml" |
|
22
|
|
|
|
|
|
|
: -e "$path/${name_lc}.yaml" ? "$path/${name_lc}.yaml" |
|
23
|
|
|
|
|
|
|
: -e "$path/${name_lc}.yml" ? "$path/${name_lc}.yml" |
|
24
|
|
|
|
|
|
|
: die q{ Configuration is not found. }; |
|
25
|
0
|
|
|
|
|
|
require YAML; |
|
26
|
0
|
|
|
|
|
|
$conf= YAML::LoadFile($yaml); |
|
27
|
0
|
0
|
0
|
|
|
|
$conf->{root} ||= $path unless $path=~m{\.yaml$}; |
|
28
|
|
|
|
|
|
|
} elsif (! $conf) { |
|
29
|
0
|
0
|
|
|
|
|
$class= ref($class) if ref($class); |
|
30
|
0
|
0
|
|
|
|
|
"${class}::config"->require or die $@; |
|
31
|
0
|
|
|
|
|
|
$conf= "${class}::config"->out; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
0
|
|
|
|
|
|
$class->_check_config($conf); |
|
34
|
0
|
|
|
|
|
|
$class->egg_var_deep($conf, $conf->{dir}); |
|
35
|
0
|
|
|
|
|
|
$class->egg_var_deep($conf, $conf); |
|
36
|
0
|
|
|
|
|
|
$conf; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__END__ |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Egg::Plugin::ConfigLoader - An external configuration for Egg is loaded. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use Egg qw/ ConfigLoader /; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
When this plugin is used, it comes to take the configuration from the outside |
|
54
|
|
|
|
|
|
|
though L<Egg> treats it as a configuration when HASH is passed to the method |
|
55
|
|
|
|
|
|
|
of '_startup'. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This plugin comes to be loaded beforehand in the default of Egg and config.pm |
|
58
|
|
|
|
|
|
|
in the library of the project is taken as a configuration. In this case, |
|
59
|
|
|
|
|
|
|
the argument is not given to the method of '_startup'. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
If it wants to do the configuration by the YAML format, passing to the YAML file |
|
62
|
|
|
|
|
|
|
is passed to '_startup' by the SCALAR reference. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Controller - /path/to/MyApp/lib/MyApp.pm |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__PACKAGE__->_startup(\"/path/to/MyApp/etc/MyApp.yaml"); |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
[project_name_lc].yaml or [project_name_lc].yml ties and it looks for the file |
|
69
|
|
|
|
|
|
|
without the file name in passing. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# It looks for myapp.yaml or myapp.yml |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__PACKAGE__->_startup(\"/path/to/MyApp/etc"); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Please make the configuration of the YAML format beforehand. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
% cd /path/to/MyApp |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
% vi myapp.yaml |
|
80
|
|
|
|
|
|
|
or |
|
81
|
|
|
|
|
|
|
% vi etc/myapp.yaml |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
title: MyApp |
|
84
|
|
|
|
|
|
|
root: /path/to/MyApp |
|
85
|
|
|
|
|
|
|
dir: |
|
86
|
|
|
|
|
|
|
.......... |
|
87
|
|
|
|
|
|
|
.... |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
L<Egg::Release>, |
|
92
|
|
|
|
|
|
|
L<YAML>, |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 AUTHOR |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
103
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
|
104
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |