Context for TestAppPluginWithConstructor
[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
ec1a2358 41__END__
42
43=head1 NAME
44
45Catalyst::Config - Catalyst config role
46
47=head1 METHODS
48
49=head2 $app->config
50
51=head2 $app->merge_config_hashes
52
53=head1 SEE ALSO
54
55L<Catalyst>,
56
57=head1 AUTHORS
58
59Catalyst Contributors, see Catalyst.pm
60
61=head1 COPYRIGHT
62
63This library is free software. You can redistribute it and/or modify it under
64the same terms as Perl itself.
65
66=cut
67
68