package Catalyst;
use strict;
-use base 'Catalyst::Base';
+use base 'Catalyst::Component';
use bytes;
use UNIVERSAL::require;
use Catalyst::Exception;
use Catalyst::Request::Upload;
use Catalyst::Response;
use Catalyst::Utils;
+use Catalyst::Controller;
use File::stat;
use NEXT;
use Text::SimpleTable;
use Tree::Simple qw/use_weak_refs/;
use Tree::Simple::Visitor::FindByUID;
use attributes;
-use YAML ();
+use JSON;
+use File::Slurp;
__PACKAGE__->mk_accessors(
qw/counter request response state action stack namespace/
__PACKAGE__->request_class('Catalyst::Request');
__PACKAGE__->response_class('Catalyst::Response');
-our $VERSION = '5.62';
+our $VERSION = '5.64';
sub import {
my ( $class, @arguments ) = @_;
unless ( $caller->isa('Catalyst') ) {
no strict 'refs';
- push @{"$caller\::ISA"}, $class;
+ push @{"$caller\::ISA"}, $class, 'Catalyst::Controller';
}
$caller->arguments( [@arguments] );
C<$c-E<gt>req-E<gt>args>. Upon returning from the function,
C<$c-E<gt>req-E<gt>args> will be restored to the previous values.
- $c->forward('/foo');
+Any data C<return>ed from the action forwarded to, will be returned by the
+call to forward.
+
+ my $foodata = $c->forward('/foo');
$c->forward('index');
$c->forward(qw/MyApp::Model::CDBI::Foo do_stuff/);
$c->forward('MyApp::View::TT');
__PACKAGE__->config({ db => 'dsn:SQLite:foo.db' });
+You can also use a L<JSON> config file like myapp.json in your
+applications home directory.
+
+ {
+ "db": "dsn:SQLite:foo.db"
+ }
+
=head2 $c->debug
Overload to enable debug messages (same as -Debug option).
=head2 $c->log
-Returns the logging object instance. Unless it is already set, Catalyst
-sets this up with a L<Catalyst::Log> object. To use your own log class:
+Returns the logging object instance. Unless it is already set, Catalyst sets
+this up with a L<Catalyst::Log> 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
$class->setup_home( delete $flags->{home} );
- # YAML config support
- my $confpath =
- $class->path_to(
- Catalyst::Utils::appprefix( ref $class || $class ) . '.yml' );
+ # JSON config support
+ my $confpath = $class->config->{file}
+ || $class->path_to(
+ ( Catalyst::Utils::appprefix( ref $class || $class ) . '.json' ) );
my $conf = {};
- $conf = YAML::LoadFile($confpath) if -f $confpath;
+ if ( -f $confpath ) {
+ my $content = read_file("$confpath");
+ $conf = jsonToObj($content);
+ }
my $oldconf = $class->config;
$class->config( { %$oldconf, %$conf } );
<p>If you want to jump right into web development with Catalyst
you might want to check out the documentation.</p>
<pre><code>perldoc <a href="http://cpansearch.perl.org/dist/Catalyst/lib/Catalyst/Manual/Intro.pod">Catalyst::Manual::Intro</a>
+perldoc <a href="http://cpansearch.perl.org/dist/Catalyst/lib/Catalyst/Manual/Tutorial.pod">Catalyst::Manual::Tutorial</a></code>
perldoc <a href="http://cpansearch.perl.org/dist/Catalyst/lib/Catalyst/Manual.pod">Catalyst::Manual</a></code></pre>
<h2>What to do next?</h2>
<p>Next it's time to write an actual application. Use the
sub execute {
my ( $c, $class, $code ) = @_;
- $class = $c->components->{$class} || $class;
+ $class = $c->component($class) || $class;
$c->state(0);
if ( $c->debug ) {
}
# 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(
{
my $callback = sub {
my ( $component, $context ) = @_;
- unless ( $component->isa('Catalyst::Component') ) {
+ unless ( $component->can('COMPONENT') ) {
return $component;
}