- Added *_class methods to Catalyst
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index 781736c..89a77b2 100644 (file)
@@ -22,7 +22,7 @@ __PACKAGE__->mk_accessors(
     qw/counter depth request response state action namespace/
 );
 
-attributes->import(__PACKAGE__, \&namespace, 'lvalue');
+attributes->import( __PACKAGE__, \&namespace, 'lvalue' );
 
 # Laziness++
 *comp = \&component;
@@ -44,7 +44,28 @@ require Module::Pluggable::Fast;
 our $CATALYST_SCRIPT_GEN = 10;
 
 __PACKAGE__->mk_classdata($_)
-  for qw/components arguments dispatcher engine log/;
+  for qw/components arguments dispatcher engine log _dispatcher_class
+    _engine_class _context_class _request_class _response_class/;
+
+sub dispatcher_class {
+    return $_[0]->_dispatcher_class(@_[1..$#_]) || 'Catalyst::Dispatcher';
+}
+
+sub engine_class {
+    return $_[0]->_engine_class(@_[1..$#_]) || 'Catalyst::Engine::CGI';
+}
+
+sub context_class {
+    return $_[0]->_context_class(@_[1..$#_]) || ref $_[0] || $_[0];
+}
+
+sub request_class {
+    return $_[0]->_request_class(@_[1..$#_]) || 'Catalyst::Request';
+}
+
+sub response_class {
+    return $_[0]->_response_class(@_[1..$#_]) || 'Catalyst::Response';
+}
 
 our $VERSION = '5.49_03';
 
@@ -415,8 +436,11 @@ sub setup {
     $class->setup_components;
 
     if ( $class->debug ) {
-        my $t = Text::SimpleTable->new(76);
-        $t->row($_) for sort keys %{ $class->components };
+        my $t = Text::SimpleTable->new( [ 65, 'Class' ], [ 8, 'Type' ] );
+        for my $comp ( sort keys %{ $class->components } ) {
+            my $type = ref $class->components->{$comp} ? 'instance' : 'class';
+            $t->row( $comp, $type );
+        }
         $class->log->debug( "Loaded components:\n" . $t->draw )
           if ( keys %{ $class->components } );
     }
@@ -991,7 +1015,7 @@ Get an action in a given namespace.
 
 =cut
 
-sub get_action { my $c = shift; $c->dispatcher->get_action( @_ ) }
+sub get_action { my $c = shift; $c->dispatcher->get_action(@_) }
 
 =item $c->get_actions( $action, $namespace )
 
@@ -1058,10 +1082,10 @@ into a Catalyst context .
 sub prepare {
     my ( $class, @arguments ) = @_;
 
-    my $c = bless {
+    my $c = $class->context_class->new({
         counter => {},
         depth   => 0,
-        request => Catalyst::Request->new(
+        request => $class->request_class->new(
             {
                 arguments        => [],
                 body_parameters  => {},
@@ -1074,7 +1098,7 @@ sub prepare {
                 uploads          => {}
             }
         ),
-        response => Catalyst::Response->new(
+        response => $class->response_class->new(
             {
                 body    => '',
                 cookies => {},
@@ -1084,7 +1108,7 @@ sub prepare {
         ),
         stash => {},
         state => 0
-    }, $class;
+    });
 
     # For on-demand data
     $c->request->{_context}  = $c;
@@ -1423,7 +1447,7 @@ sub setup_dispatcher {
     }
 
     unless ($dispatcher) {
-        $dispatcher = 'Catalyst::Dispatcher';
+        $dispatcher = $class->dispatcher_class;
     }
 
     $dispatcher->require;
@@ -1512,7 +1536,7 @@ sub setup_engine {
     }
 
     unless ($engine) {
-        $engine = 'Catalyst::Engine::CGI';
+        $engine = $class->engine_class;
     }
 
     $engine->require;