X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst.pm;h=8ac41a8268fc79aa8ecc23dcc50e98241fa5e020;hb=55c388c1c0fc13e0c8aae18f7957ab942cc28797;hp=328a3582c8bdff955ba9a9cf18c4f5135dc18b34;hpb=d96e14c21fb544597f459aaaad969c34af7f2d1f;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 328a358..8ac41a8 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1,11 +1,13 @@ package Catalyst; use strict; -use base 'Class::Data::Inheritable'; +use base 'Catalyst::Base'; use UNIVERSAL::require; use Catalyst::Log; +use Text::ASCIITable; +use Text::ASCIITable::Wrap 'wrap'; -__PACKAGE__->mk_classdata($_) for qw/_config engine log/; +__PACKAGE__->mk_classdata($_) for qw/engine log/; our $VERSION = '5.00'; our @ISA; @@ -40,23 +42,19 @@ Catalyst - The Elegant MVC Web Application Framework use Catalyst qw/-Debug -Engine=CGI/; - __PACKAGE__->action( '!default' => sub { $_[1]->res->output('Hello') } ); + sub default : Private { $_[1]->res->output('Hello') } ); - __PACKAGE__->action( - 'index.html' => sub { - my ( $self, $c ) = @_; - $c->res->output('Hello'); - $c->forward('_foo'); - } - ); + sub index : Path('/index.html') { + my ( $self, $c ) = @_; + $c->res->output('Hello'); + $c->forward('_foo'); + } - __PACKAGE__->action( - '/^product[_]*(\d*).html$/' => sub { - my ( $self, $c ) = @_; - $c->stash->{template} = 'product.tt'; - $c->stash->{product} = $c->req->snippets->[0]; - } - ); + sub product : Regex('/^product[_]*(\d*).html$/') { + my ( $self, $c ) = @_; + $c->stash->{template} = 'product.tt'; + $c->stash->{product} = $c->req->snippets->[0]; + } See also L @@ -125,18 +123,6 @@ Returns a hashref containing your applications settings. =cut -sub config { - my $self = shift; - $self->_config( {} ) unless $self->_config; - if ( $_[0] ) { - my $config = $_[1] ? {@_} : $_[0]; - while ( my ( $key, $val ) = each %$config ) { - $self->_config->{$key} = $val; - } - } - return $self->_config; -} - sub import { my ( $self, @options ) = @_; my $caller = caller(0); @@ -147,7 +133,7 @@ sub import { } if ( $caller->engine ) { - return; # Catalyst is allready initialized + return; # Catalyst is allready initialized } unless ( $caller->log ) { @@ -160,11 +146,21 @@ sub import { $caller->log->debug('Debug messages enabled'); } - # Options - my $engine = $ENV{MOD_PERL} - ? 'Catalyst::Engine::Apache' - : 'Catalyst::Engine::CGI'; + my $engine = 'Catalyst::Engine::CGI'; + + if ( $ENV{MOD_PERL} ) { + require mod_perl; + + if ( $mod_perl::VERSION >= 1.99 ) { + $engine = 'Catalyst::Engine::Apache::MP2'; + } + else { + $engine = 'Catalyst::Engine::Apache::MP1'; + } + } + + my @plugins; foreach (@options) { if (/^\-Debug$/) { next if $caller->debug; @@ -177,30 +173,29 @@ sub import { else { my $plugin = "Catalyst::Plugin::$_"; - # Plugin caller should be our application class - eval "package $caller; require $plugin"; + $plugin->require; + if ($@) { $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/); } else { - $caller->log->debug(qq/Loaded plugin "$plugin"/) - if $caller->debug; + push @plugins, $plugin; no strict 'refs'; push @{"$caller\::ISA"}, $plugin; } } } + my $t = Text::ASCIITable->new; + $t->setCols('Class'); + $t->setColWidth( 'Class', 75, 1 ); + $t->addRow( wrap( $_, 75 ) ) for @plugins; + $caller->log->debug( 'Loaded plugins', $t->draw ) + if ( @plugins && $caller->debug ); # Engine $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}" if $ENV{CATALYST_ENGINE}; - if ( $engine eq 'Catalyst::Engine::Server' ) { - $engine = 'Catalyst::Engine::HTTP::Daemon'; - $caller->log->warn( "Catalyst::Engine::Server is deprecated, " - . "using Catalyst::Engine::HTTP::Daemon." ); - } - $engine->require; die qq/Couldn't load engine "$engine", "$@"/ if $@; {