line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Amon2::Config::Simple; |
2
|
25
|
|
|
25
|
|
250
|
use strict; |
|
25
|
|
|
|
|
55
|
|
|
25
|
|
|
|
|
758
|
|
3
|
25
|
|
|
25
|
|
158
|
use warnings; |
|
25
|
|
|
|
|
60
|
|
|
25
|
|
|
|
|
654
|
|
4
|
25
|
|
|
25
|
|
134
|
use File::Spec; |
|
25
|
|
|
|
|
48
|
|
|
25
|
|
|
|
|
469
|
|
5
|
25
|
|
|
25
|
|
122
|
use Carp (); |
|
25
|
|
|
|
|
54
|
|
|
25
|
|
|
|
|
5452
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub load { |
8
|
0
|
|
|
0
|
0
|
|
my ($class, $c) = (shift, shift); |
9
|
0
|
0
|
|
|
|
|
my %conf = @_ == 1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
0
|
|
0
|
|
|
|
my $env = $conf{environment} || $c->mode_name || 'development'; |
12
|
0
|
|
|
|
|
|
my $fname = File::Spec->catfile($c->base_dir, 'config', "${env}.pl"); |
13
|
0
|
|
|
|
|
|
my $config = do $fname; |
14
|
0
|
0
|
|
|
|
|
Carp::croak("$fname: $@") if $@; |
15
|
0
|
0
|
|
|
|
|
Carp::croak("$fname: $!") unless defined $config; |
16
|
0
|
0
|
|
|
|
|
unless ( ref($config) eq 'HASH' ) { |
17
|
0
|
|
|
|
|
|
Carp::croak("$fname does not return HashRef."); |
18
|
|
|
|
|
|
|
} |
19
|
0
|
|
|
|
|
|
return $config; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
1; |
23
|
|
|
|
|
|
|
__END__ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=encoding utf-8 |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 NAME |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Amon2::Config::Simple - Default configuration file loader |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SYNOPSIS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
package MyApp2; |
34
|
|
|
|
|
|
|
# do "config/@{{ $c->mode_name ]}.pl" |
35
|
|
|
|
|
|
|
use Amon2::Config::Simple; |
36
|
|
|
|
|
|
|
sub load_config { Amon2::Config::Simple->load(shift) } |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 DESCRIPTION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
This is a default configuration file loader for L<Amon2>. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This module loads the configuration by C<< do >> function. Yes, it's just plain perl code structure. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Amon2 using configuration file in C<< "config/@{[ $c->mode_name ]}.pl" >>. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 HOW DO YOU USE YOUR OWN ENVIRONMENT VARIABLE FOR DETECTING CONFIGURATION FILE? |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
If you want to use C<< config/$ENV{RUN_MODE}.pl >> for the configuration file, you can write code as following: |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
package MyApp; |
51
|
|
|
|
|
|
|
use Amon2::Config::Simple; |
52
|
|
|
|
|
|
|
sub load_config { Amon2::Config::Simple->load(shift, +{ environment => $ENV{RUN_MODE} } ) } |
53
|
|
|
|
|
|
|
|