Forgot to commit - ripped the config bits of ::Component out into a role so that...
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Config.pm
CommitLineData
3ca85b85 1package Catalyst::Config;
2use Moose::Role;
3use Class::MOP ();
4use Catalyst::Utils ();
5use namespace::autoclean;
6
7sub config {
8 my $self = shift;
9 # Uncomment once sane to do so
10 #Carp::cluck("config method called on instance") if ref $self;
11 my $config = $self->_config || {};
12 if (@_) {
13 my $newconfig = { %{@_ > 1 ? {@_} : $_[0]} };
14 $self->_config(
15 $self->merge_config_hashes( $config, $newconfig )
16 );
17 } else {
18 # this is a bit of a kludge, required to make
19 # __PACKAGE__->config->{foo} = 'bar';
20 # work in a subclass.
21 # TODO maybe this should be a ClassData option?
22 my $class = blessed($self) || $self;
23 my $meta = Class::MOP::get_metaclass_by_name($class);
24 unless ($meta->has_package_symbol('$_config')) {
25 # Call merge_hashes to ensure we deep copy the parent
26 # config onto the subclass
27 $self->_config( Catalyst::Utils::merge_hashes($config, {}) );
28 }
29 }
30 return $self->_config;
31}
32
33sub merge_config_hashes {
34 my ( $self, $lefthash, $righthash ) = @_;
35
36 return Catalyst::Utils::merge_hashes( $lefthash, $righthash );
37}
38
391;
40