X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=0e15f5b67f2255b0e520d43c8e009c5b4db22314;hp=eb44a14920c01583373aa057e0858d77c8f51f77;hb=89ba65d5fb85ab30fa5d8109cd0d22860608605b;hpb=80267996ccba9e9c1cad4fe10f4ecef33c1b1d4b diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index eb44a14..0e15f5b 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -4,7 +4,7 @@ use Moose; use Moose::Meta::Class (); extends 'Catalyst::Component'; use Moose::Util qw/find_meta/; -use B::Hooks::EndOfScope (); +use namespace::clean -except => 'meta'; use Catalyst::Exception; use Catalyst::Exception::Detach; use Catalyst::Exception::Go; @@ -38,7 +38,7 @@ use Plack::Middleware::ReverseProxy; use Plack::Middleware::IIS6ScriptNameFix; use Plack::Middleware::LighttpdScriptNameFix; -BEGIN { require 5.008004; } +BEGIN { require 5.008003; } has stack => (is => 'ro', default => sub { [] }); has stash => (is => 'rw', default => sub { {} }); @@ -100,7 +100,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.90008'; +our $VERSION = '5.90014'; sub import { my ( $class, @arguments ) = @_; @@ -1184,29 +1184,6 @@ EOF $class->log->info("$name powered by Catalyst $Catalyst::VERSION"); } - # Make sure that the application class becomes immutable at this point, - B::Hooks::EndOfScope::on_scope_end { - return if $@; - my $meta = Class::MOP::get_metaclass_by_name($class); - if ( - $meta->is_immutable - && ! { $meta->immutable_options }->{replace_constructor} - && ( - $class->isa('Class::Accessor::Fast') - || $class->isa('Class::Accessor') - ) - ) { - warn "You made your application class ($class) immutable, " - . "but did not inline the\nconstructor. " - . "This will break catalyst, as your app \@ISA " - . "Class::Accessor(::Fast)?\nPlease pass " - . "(replace_constructor => 1)\nwhen making your class immutable.\n"; - } - $meta->make_immutable( - replace_constructor => 1, - ) unless $meta->is_immutable; - }; - if ($class->config->{case_sensitive}) { $class->log->warn($class . "->config->{case_sensitive} is set."); $class->log->warn("This setting is deprecated and planned to be removed in Catalyst 5.81."); @@ -1811,7 +1788,7 @@ sub finalize { $c->finalize_error; } - $c->finalize_headers; + $c->finalize_headers unless $c->response->finalized_headers; # HEAD request if ( $c->request->method eq 'HEAD' ) { @@ -1921,7 +1898,7 @@ EOF $c->finalize_cookies; - $c->engine->finalize_headers( $c, @_ ); + $c->response->finalize_headers(); # Done $response->finalized_headers(1); @@ -2023,6 +2000,8 @@ sub prepare { my $uploadtmp = $class->config->{uploadtmp}; my $c = $class->context_class->new({ $uploadtmp ? (_uploadtmp => $uploadtmp) : ()}); + $c->response->_context($c); + #surely this is not the most efficient way to do things... $c->stats($class->stats_class->new)->enable($c->use_stats); if ( $c->debug || $c->config->{enable_catalyst_header} ) { @@ -2446,11 +2425,35 @@ Starts the engine. sub run { my $app = shift; + $app->_make_immutable_if_needed; $app->engine_loader->needs_psgi_engine_compat_hack ? $app->engine->run($app, @_) : $app->engine->run( $app, $app->_finalized_psgi_app, @_ ); } +sub _make_immutable_if_needed { + my $class = shift; + my $meta = Class::MOP::get_metaclass_by_name($class); + my $isa_ca = $class->isa('Class::Accessor::Fast') || $class->isa('Class::Accessor'); + if ( + $meta->is_immutable + && ! { $meta->immutable_options }->{replace_constructor} + && $isa_ca + ) { + warn("You made your application class ($class) immutable, " + . "but did not inline the\nconstructor. " + . "This will break catalyst, as your app \@ISA " + . "Class::Accessor(::Fast)?\nPlease pass " + . "(replace_constructor => 1)\nwhen making your class immutable.\n"); + } + unless ($meta->is_immutable) { + # XXX - FIXME warning here as you should make your app immutable yourself. + $meta->make_immutable( + replace_constructor => 1, + ); + } +} + =head2 $c->set_action( $action, $code, $namespace, $attrs ) Sets an action in a given namespace. @@ -2928,11 +2931,16 @@ the plugin name does not begin with C. Class::MOP::load_class( $plugin ); $class->log->warn( "$plugin inherits from 'Catalyst::Component' - this is deprecated and will not work in 5.81" ) if $plugin->isa( 'Catalyst::Component' ); - $proto->_plugins->{$plugin} = 1; - unless ($instant) { + my $plugin_meta = Moose::Meta::Class->create($plugin); + if (!$plugin_meta->has_method('new') + && ( $plugin->isa('Class::Accessor::Fast') || $plugin->isa('Class::Accessor') ) ) { + $plugin_meta->add_method('new', Moose::Object->meta->get_method('new')) + } + if (!$instant && !$proto->_plugins->{$plugin}) { my $meta = Class::MOP::get_metaclass_by_name($class); $meta->superclasses($plugin, $meta->superclasses); } + $proto->_plugins->{$plugin} = 1; return $class; }