32 |
=cut |
=cut |
33 |
|
|
34 |
our %config; |
our %config; |
35 |
|
our $debug; |
36 |
|
|
37 |
sub load_config { |
sub load_config { |
38 |
my $self = shift; |
my $self = shift; |
39 |
|
$debug = $self->debug if $self->can('debug'); |
40 |
foreach my $name ( 'config', 'site_config', ref($self), @_ ) { |
foreach my $name ( 'config', 'site_config', ref($self), @_ ) { |
41 |
my $path = "etc/$name.yml"; |
my $path = "etc/$name.yml"; |
42 |
if ( $path =~ s{::}{/}g ) { |
if ( $path =~ s{::}{/}g ) { |
45 |
} else { |
} else { |
46 |
%config = %{ merge( LoadFile($path) , \%config ) } if -e $path; |
%config = %{ merge( LoadFile($path) , \%config ) } if -e $path; |
47 |
} |
} |
48 |
warn "## $path current config = ",dump( %config ) if $self->debug; |
warn "## load_config $path current config = ",dump( %config ) if $debug; |
49 |
} |
} |
50 |
} |
} |
51 |
|
|
52 |
sub config { |
sub config { |
53 |
my $self = shift; |
my ( $self, $key ) = @_; |
54 |
my $key = shift || ref($self); |
$key ||= ref($self); |
55 |
warn "## config $key" if $self->debug; |
warn "## config $key" if $self->debug; |
56 |
$self->load_config unless defined %config; |
$self->load_config unless defined %config; |
57 |
confess "$key doesn't exist in config" unless defined $config{ $key }; |
#confess "$key doesn't exist in config" unless defined $config{ $key }; |
58 |
|
return unless defined $config{ $key }; |
59 |
return $config{ $key }; |
return $config{ $key }; |
60 |
} |
} |
61 |
|
|