X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=0e0130530177644755de3b04a4d9585a7780da4b;hp=7a0317797113c17f43b7b9e56e6062c5dac8bd8b;hb=1a5adaee236dda2152a9d0fb1ca27d08f3f92777;hpb=cefe060084f265addd60effada65a2e4e8661163 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 7a03177..0e01305 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; @@ -37,7 +37,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 { {} }); @@ -99,7 +99,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.90007'; +our $VERSION = '5.90015'; sub import { my ( $class, @arguments ) = @_; @@ -131,6 +131,13 @@ sub import { } $caller->arguments( [@arguments] ); + + # FIXME + # what is this for? + # we call setup_home on import AND on ->setup + # is there a reason for it? + # anyway there is no point for setup_home without setup_config() so... + $caller->setup_config; $caller->setup_home; } @@ -145,6 +152,8 @@ sub MODIFY_CODE_ATTRIBUTES { sub _application { $_[0] } +=encoding utf8 + =head1 NAME Catalyst - The Elegant MVC Web Application Framework @@ -1015,29 +1024,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."); @@ -1384,18 +1370,18 @@ sub welcome_message { We do, however, provide you with a few starting points.

If you want to jump right into web development with Catalyst you might want to start with a tutorial.

-
perldoc Catalyst::Manual::Tutorial
+
perldoc Catalyst::Manual::Tutorial
 

Afterwards you can go on to check out a more complete look at our features.

-perldoc Catalyst::Manual::Intro
+perldoc Catalyst::Manual::Intro
 
 

What to do next?

Next it's time to write an actual application. Use the - helper scripts to generate controllers, - models, and - views; + helper scripts to generate controllers, + models, and + views; they can save you a lot of work.

script/${prefix}_create.pl --help

Also, be sure to check out the vast and growing @@ -1659,7 +1645,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' ) { @@ -1769,7 +1755,7 @@ EOF $c->finalize_cookies; - $c->engine->finalize_headers( $c, @_ ); + $c->response->finalize_headers(); # Done $response->finalized_headers(1); @@ -1871,6 +1857,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} ) { @@ -2294,11 +2282,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. @@ -2334,7 +2346,7 @@ sub setup_config { $container_class = Class::MOP::load_first_existing_class("${class}::Container", 'Catalyst::IOC::Container'); } - my $container = $container_class->new( %args, application_name => "$class", name => "$class" ); + my $container = $container_class->new( %args, name => $class ); $class->container($container); my $config = $container->resolve( service => 'config' ); @@ -2594,18 +2606,19 @@ Sets up the home directory. =cut sub setup_home { - my ( $class, $home ) = @_; - - if ( my $env = Catalyst::Utils::env_value( $class, 'HOME' ) ) { - $home = $env; - } + my ( $class, $home_flag ) = @_; - $home ||= Catalyst::Utils::home($class); + my $home = $class->container->resolve( + service => 'home', + parameters => { + home_flag => $home_flag + }, + ); if ($home) { #I remember recently being scolded for assigning config values like this $class->config->{home} ||= $home; - $class->config->{root} ||= Path::Class::Dir->new($home)->subdir('root'); + $class->config->{root} ||= $class->container->resolve(service => 'root_dir'); } } @@ -2706,11 +2719,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; }