Modified Catalyst::Log to make it a bit easier to control logging output.
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index 42cbe8f..461ac6d 100644 (file)
@@ -1,7 +1,7 @@
 package Catalyst;
 
 use strict;
-use base 'Catalyst::Base';
+use base 'Catalyst::Component';
 use bytes;
 use UNIVERSAL::require;
 use Catalyst::Exception;
@@ -10,6 +10,7 @@ use Catalyst::Request;
 use Catalyst::Request::Upload;
 use Catalyst::Response;
 use Catalyst::Utils;
+use Catalyst::Controller;
 use File::stat;
 use NEXT;
 use Text::SimpleTable;
@@ -20,6 +21,7 @@ use Scalar::Util qw/weaken/;
 use Tree::Simple qw/use_weak_refs/;
 use Tree::Simple::Visitor::FindByUID;
 use attributes;
+use YAML ();
 
 __PACKAGE__->mk_accessors(
     qw/counter request response state action stack namespace/
@@ -70,7 +72,7 @@ sub import {
 
     unless ( $caller->isa('Catalyst') ) {
         no strict 'refs';
-        push @{"$caller\::ISA"}, $class;
+        push @{"$caller\::ISA"}, $class, 'Catalyst::Controller';
     }
 
     $caller->arguments( [@arguments] );
@@ -443,6 +445,12 @@ Returns or takes a hashref containing the application's configuration.
 
     __PACKAGE__->config({ db => 'dsn:SQLite:foo.db' });
 
+You can also use a L<YAML> config file like myapp.yml in your
+applications home directory.
+
+    ---
+    db: dsn:SQLite:foo.db
+
 =head2 $c->debug
 
 Overload to enable debug messages (same as -Debug option).
@@ -571,11 +579,21 @@ sub setup {
         }
     }
 
+    $class->setup_home( delete $flags->{home} );
+
+    # YAML config support
+    my $confpath = $class->config->{file}
+      || $class->path_to(
+        ( Catalyst::Utils::appprefix( ref $class || $class ) . '.yml' ) );
+    my $conf = {};
+    $conf = YAML::LoadFile($confpath) if -f $confpath;
+    my $oldconf = $class->config;
+    $class->config( { %$oldconf, %$conf } );
+
     $class->setup_log( delete $flags->{log} );
     $class->setup_plugins( delete $flags->{plugins} );
     $class->setup_dispatcher( delete $flags->{dispatcher} );
     $class->setup_engine( delete $flags->{engine} );
-    $class->setup_home( delete $flags->{home} );
 
     for my $flag ( sort keys %{$flags} ) {
 
@@ -916,15 +934,20 @@ sub execute {
         }
 
         # determine if the call was the result of a forward
-        my $callsub_index = ( caller(0) )[0]->isa('Catalyst::Action') ? 2 : 1;
-        if ( ( caller($callsub_index) )[3] =~ /^NEXT/ ) {
-
-            # work around NEXT if execute was extended by a plugin
-            $callsub_index += 3;
+        # this is done by walking up the call stack and looking for a calling
+        # sub of Catalyst::forward before the eval
+        my $callsub = q{};
+        for my $index ( 1 .. 10 ) {
+            last
+              if ( ( caller($index) )[0] eq 'Catalyst'
+                && ( caller($index) )[3] eq '(eval)' );
+
+            if ( ( caller($index) )[3] =~ /forward$/ ) {
+                $callsub = ( caller($index) )[3];
+                $action  = "-> $action";
+                last;
+            }
         }
-        my $callsub = ( caller($callsub_index) )[3];
-
-        $action = "-> $action" if $callsub =~ /forward$/;
 
         my $node = Tree::Simple->new(
             {
@@ -1527,7 +1550,7 @@ sub setup_components {
     my $callback = sub {
         my ( $component, $context ) = @_;
 
-        unless ( $component->isa('Catalyst::Component') ) {
+        unless ( $component->can('COMPONENT') ) {
             return $component;
         }