[Catalyst-commits] r11895 -
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned-appnotcomponent/lib/Catalyst
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Wed Nov 18 22:25:36 GMT 2009
Author: t0m
Date: 2009-11-18 22:25:36 +0000 (Wed, 18 Nov 2009)
New Revision: 11895
Added:
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned-appnotcomponent/lib/Catalyst/Config.pm
Log:
Forgot to commit - ripped the config bits of ::Component out into a role so that I could apply to the app class to get the basic stuff
Added: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned-appnotcomponent/lib/Catalyst/Config.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned-appnotcomponent/lib/Catalyst/Config.pm (rev 0)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned-appnotcomponent/lib/Catalyst/Config.pm 2009-11-18 22:25:36 UTC (rev 11895)
@@ -0,0 +1,40 @@
+package Catalyst::Config;
+use Moose::Role;
+use Class::MOP ();
+use Catalyst::Utils ();
+use namespace::autoclean;
+
+sub config {
+ my $self = shift;
+ # Uncomment once sane to do so
+ #Carp::cluck("config method called on instance") if ref $self;
+ my $config = $self->_config || {};
+ if (@_) {
+ my $newconfig = { %{@_ > 1 ? {@_} : $_[0]} };
+ $self->_config(
+ $self->merge_config_hashes( $config, $newconfig )
+ );
+ } else {
+ # this is a bit of a kludge, required to make
+ # __PACKAGE__->config->{foo} = 'bar';
+ # work in a subclass.
+ # TODO maybe this should be a ClassData option?
+ my $class = blessed($self) || $self;
+ my $meta = Class::MOP::get_metaclass_by_name($class);
+ unless ($meta->has_package_symbol('$_config')) {
+ # Call merge_hashes to ensure we deep copy the parent
+ # config onto the subclass
+ $self->_config( Catalyst::Utils::merge_hashes($config, {}) );
+ }
+ }
+ return $self->_config;
+}
+
+sub merge_config_hashes {
+ my ( $self, $lefthash, $righthash ) = @_;
+
+ return Catalyst::Utils::merge_hashes( $lefthash, $righthash );
+}
+
+1;
+
More information about the Catalyst-commits
mailing list