Added global config for components
Sebastian Riedel [Sun, 17 Apr 2005 15:26:20 +0000 (15:26 +0000)]
Changes
lib/Catalyst.pm
lib/Catalyst/Base.pm
lib/Catalyst/Utils.pm

diff --git a/Changes b/Changes
index c8cb29d..94b538b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -10,6 +10,7 @@ This file documents the revision history for Perl extension Catalyst.
         - Read AUTHOR from passwd or $ENV{AUTHOR} when 
           generating code.
         - extended attribute handling
+        - added global config for components
 
 5.00  Fri Apr 15 18:00:00 2005
         - new core to support inheritance trees
index f1aef7e..f4c6678 100644 (file)
@@ -307,7 +307,7 @@ Sebastian Riedel, C<sri@oook.de>
 
 =head1 THANK YOU
 
-Andy Grundman, Andrew Ford, Andrew Ruthven, Christian Hansen,
+Andy Grundman, Andrew Ford, Andrew Ruthven, Autrijus Tang, Christian Hansen,
 Christopher Hicks, Dan Sully, Danijel Milicevic, David Naughton,
 Gary Ashton Jones, Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg,
 Tatsuhiko Miyagawa and all the others who've helped.
index 597bca7..04a2153 100644 (file)
@@ -2,6 +2,7 @@ package Catalyst::Base;
 
 use strict;
 use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
+use Catalyst::Utils;
 use NEXT;
 
 __PACKAGE__->mk_classdata($_) for qw/_attrcache _cache _config/;
@@ -69,7 +70,12 @@ component loader with config() support and a process() method placeholder.
 
 sub new {
     my ( $self, $c ) = @_;
-    return $self->NEXT::new( $self->config );
+    my $class     = ref $self || $self;
+    my $appname   = Catalyst::Utils::class2appclass($class);
+    my $suffix    = Catalyst::Utils::class2classsuffix($class);
+    my $appconfig = $appname->config->{$suffix} || {};
+    my $config    = { %{ $self->config }, %{$appconfig} };
+    return $self->NEXT::new($config);
 }
 
 # remember to leave blank lines between the consecutive =item's
index 6d21f2b..3f44898 100644 (file)
@@ -38,6 +38,21 @@ sub prefix {
     return $name;
 }
 
+=item class2appclass($class);
+
+Returns the appclass for class.
+
+=cut
+
+sub class2appclass {
+    my $class = shift || '';
+    my $appname = '';
+    if ( $class =~ /^(.*)::([MVC]|Model|View|Controller)?::.*$/ ) {
+        $appname = $1;
+    }
+    return $appname;
+}
+
 =item class2classprefix($class);
 
 Returns the classprefix for class.
@@ -53,6 +68,19 @@ sub class2classprefix {
     return $prefix;
 }
 
+=item class2classsuffix($class);
+
+Returns the classsuffix for class.
+
+=cut
+
+sub class2classsuffix {
+    my $class = shift || '';
+    my $prefix = class2appclass($class) || '';
+    $class =~ s/$prefix\:\://;
+    return $class;
+}
+
 =item class2prefix($class);
 
 Returns the prefix for class.