X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=8896db6535c2f69bbec27ca217f332f5ae8b57ea;hp=c5c315ee4bedcd0f48e3eb9cdf3ace0d991fb861;hb=3b984c64196cb49250fa2d2b52033eb20245d948;hpb=99f187d63f41e5d1fe740ab280192c3d42c28690 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index c5c315e..8896db6 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -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; @@ -71,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] ); @@ -245,7 +246,10 @@ in an arrayref. The action will receive the arguments in C<@_> and C<$c-Ereq-Eargs>. Upon returning from the function, C<$c-Ereq-Eargs> will be restored to the previous values. - $c->forward('/foo'); +Any data Ced from the action forwarded to, will be returned by the +call to to forward. + + my $foodata = $c->forward('/foo'); $c->forward('index'); $c->forward(qw/MyApp::Model::CDBI::Foo do_stuff/); $c->forward('MyApp::View::TT'); @@ -444,6 +448,12 @@ Returns or takes a hashref containing the application's configuration. __PACKAGE__->config({ db => 'dsn:SQLite:foo.db' }); +You can also use a L 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). @@ -464,10 +474,16 @@ L. =head2 $c->log -Returns the logging object instance. Unless it is already set, Catalyst -sets this up with a L object. To use your own log class: +Returns the logging object instance. Unless it is already set, Catalyst sets +this up with a L object. To use your own log class, set the +logger with the C<< __PACKAGE__->log >> method prior to calling +C<< __PACKAGE__->setup >>. + + __PACKAGE__->log( MyLogger->new ); + __PACKAGE__->setup; + +And later: - $c->log( MyLogger->new ); $c->log->info( 'Now logging with my own logger!' ); Your log class should implement the methods described in the @@ -575,9 +591,9 @@ sub setup { $class->setup_home( delete $flags->{home} ); # YAML config support - my $confpath = - $class->path_to( - Catalyst::Utils::appprefix( ref $class || $class ) . '.yml' ); + 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; @@ -927,15 +943,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( { @@ -1538,7 +1559,7 @@ sub setup_components { my $callback = sub { my ( $component, $context ) = @_; - unless ( $component->isa('Catalyst::Component') ) { + unless ( $component->can('COMPONENT') ) { return $component; }