1 |
package Frey::Config; |
package Frey::Config; |
2 |
use Moose::Role; |
use Moose::Role; |
3 |
|
|
4 |
|
#requires 'debug'; |
5 |
|
|
6 |
use YAML qw/LoadFile/; |
use YAML qw/LoadFile/; |
7 |
use Hash::Merge qw/merge/; |
use Hash::Merge qw/merge/; |
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
34 |
=cut |
=cut |
35 |
|
|
36 |
our %config; |
our %config; |
|
our $debug; |
|
37 |
|
|
38 |
sub load_config { |
sub load_config { |
39 |
my $self = shift; |
my $self = shift; |
|
$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 "## load_config $path current config = ",dump( %config ) if $debug; |
warn "## load_config $path current config = ",dump( %config ) if $self->debug; |
49 |
} |
} |
50 |
} |
} |
51 |
|
|