X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst.pm;h=cef7ac7be4989384fcde50e97e808fce8304230d;hb=76721d3c6f8660effa365b8c1574b1e87f4973cb;hp=2bbe8d6eb8f2db14e4344b8e14757ef62c6e8a4a;hpb=e9e51b8f5b806e77bb66f8528a831b291bcd7295;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 2bbe8d6..cef7ac7 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -5,8 +5,10 @@ package Catalyst; use Class::C3; use Moose; +use Class::MOP::Object (); extends 'Catalyst::Component'; use bytes; +use Scope::Upper (); use Catalyst::Exception; use Catalyst::Log; use Catalyst::Request; @@ -33,7 +35,7 @@ use Carp qw/croak carp/; BEGIN { require 5.008001; } -has stack => (is => 'rw', default => sub { [] }); +has stack => (is => 'ro', default => sub { [] }); has stash => (is => 'rw', default => sub { {} }); has state => (is => 'rw', default => 0); has stats => (is => 'rw'); @@ -80,7 +82,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.8000_03'; +our $VERSION = '5.8000_04'; sub import { my ( $class, @arguments ) = @_; @@ -261,7 +263,9 @@ MYAPP_WEB_HOME. If both variables are set, the MYAPP_HOME one will be used. =head2 -Log -Specifies log level. + use Catalyst '-Log=warn,fatal,error'; + +Specifies a comma-delimited list of log levels. =head2 -Stats @@ -969,8 +973,8 @@ EOF my $engine = $class->engine; my $home = $class->config->{home}; - $class->log->debug(qq/Loaded dispatcher "$dispatcher"/); - $class->log->debug(qq/Loaded engine "$engine"/); + $class->log->debug(sprintf(q/Loaded dispatcher "%s"/, blessed($dispatcher))); + $class->log->debug(sprintf(q/Loaded engine "%s"/, blessed($engine))); $home ? ( -d $home ) @@ -979,7 +983,7 @@ EOF : $class->log->debug(q/Couldn't find home/); } - # Call plugins setup + # Call plugins setup, this is stupid and evil. { no warnings qw/redefine/; local *setup = sub { }; @@ -1014,6 +1018,17 @@ EOF } $class->log->_flush() if $class->log->can('_flush'); + # Make sure that the application class becomes immutable at this point, + # which ensures that it gets an inlined constructor. This means that it + # works even if the user has added a plugin which contains a new method. + # Note however that we have to do the work on scope end, so that method + # modifiers work correctly in MyApp (as you have to call setup _before_ + # applying modifiers). + Scope::Upper::reap(sub { + my $meta = $class->Moose::Object::meta(); + $meta->make_immutable unless $meta->is_immutable; + }, 1); + $class->setup_finished(1); } @@ -1077,7 +1092,7 @@ sub uri_for { # join args with '/', or a blank string my $args = join('/', grep { defined($_) } @args); $args =~ s/\?/%3F/g; # STUPID STUPID SPECIAL CASE - $args =~ s!^/!!; + $args =~ s!^/+!!; my $base = $c->req->base; my $class = ref($base); $base =~ s{(?log->debug(qq/Redirecting to "$location"/) if $c->debug; $response->header( Location => $location ); - #Moose TODO: we should probably be using a predicate method here ? - if ( !$response->body ) { + if ( !$response->has_body ) { # Add a default body if none is already present $response->body( qq{
This item has moved here.
} @@ -1733,9 +1747,7 @@ Prepares message body. sub prepare_body { my $c = shift; - #Moose TODO: what is _body ?? - # Do we run for the first time? - return if defined $c->request->{_body}; + return if $c->request->_has_body; # Initialize on-demand data $c->engine->prepare_body( $c, @_ ); @@ -2082,9 +2094,10 @@ sub setup_engine { } if ( $ENV{MOD_PERL} ) { - + my $meta = $class->Class::MOP::Object::meta(); + # create the apache method - $class->meta->add_method('apache' => sub { shift->engine->apache }); + $meta->add_method('apache' => sub { shift->engine->apache }); my ( $software, $version ) = $ENV{MOD_PERL} =~ /^(\S+)\/(\d+(?:[\.\_]\d+)+)/; @@ -2203,20 +2216,35 @@ sub setup_home { =head2 $c->setup_log -Sets up log. +Sets up log by instantiating a L