From: Zbigniew Łukasiak Date: Tue, 17 Nov 2009 07:54:04 +0000 (+0000) Subject: live serving page in minimal app, plus a new test for that X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=48603b3047914297d7bf3751ba9bffe6992a1301 live serving page in minimal app, plus a new test for that --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 25673f8..9dc38d7 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -9,6 +9,7 @@ use Catalyst::Exception; use Catalyst::Log; use Catalyst::Utils; use Catalyst::Controller; +use Catalyst::Context; use Devel::InnerPackage (); use Module::Pluggable::Object (); use Text::SimpleTable (); @@ -31,6 +32,7 @@ __PACKAGE__->mk_classdata($_) engine_class context_class request_class response_class stats_class setup_finished/; +__PACKAGE__->context_class('Catalyst::Context'); __PACKAGE__->dispatcher_class('Catalyst::Dispatcher'); __PACKAGE__->engine_class('Catalyst::Engine::CGI'); __PACKAGE__->request_class('Catalyst::Request'); @@ -1019,7 +1021,8 @@ sub prepare { # into the application. $class->context_class( ref $class || $class ) unless $class->context_class; - my $c = $class->context_class->new({}); + my $app = $class->new({}); + my $c = $class->context_class->new( application => $app ); # For on-demand data $c->request->_context($c); @@ -1049,7 +1052,7 @@ sub prepare { $c->prepare_read; # Parse the body unless the user wants it on-demand - unless ( ref($c)->config->{parse_on_demand} ) { + unless ( $app->config->{parse_on_demand} ) { $c->prepare_body; } } diff --git a/lib/Catalyst/Context.pm b/lib/Catalyst/Context.pm index 40e8545..32b9221 100644 --- a/lib/Catalyst/Context.pm +++ b/lib/Catalyst/Context.pm @@ -3,6 +3,7 @@ package Catalyst::Context; use Moose; use bytes; use B::Hooks::EndOfScope (); +use Catalyst; use Catalyst::Exception::Detach; use Catalyst::Exception::Go; use Catalyst::Request; @@ -42,6 +43,7 @@ has 'application' => ( debug dispatcher_class request_class + response_class dispatcher prepare engine_class @@ -51,7 +53,8 @@ has 'application' => ( setup_finalize welcome_message components - context_class setup_actions + context_class + setup_actions search_extra root parse_on_demand diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 443975e..32cac01 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -112,7 +112,7 @@ sub finalize_error { my ( $self, $c ) = @_; $c->res->content_type('text/html; charset=utf-8'); - my $name = ref($c)->config->{name} || join(' ', split('::', ref $c)); + my $name = $c->config->{name} || join(' ', split('::', ref $c)); my ( $title, $error, $infos ); if ( $c->debug ) { @@ -317,14 +317,13 @@ sets up the L object body using L sub prepare_body { my ( $self, $c ) = @_; - my $appclass = ref($c) || $c; if ( my $length = $self->read_length ) { my $request = $c->request; unless ( $request->_body ) { my $type = $request->header('Content-Type'); $request->_body(HTTP::Body->new( $type, $length )); - $request->_body->tmpdir( $appclass->config->{uploadtmp} ) - if exists $appclass->config->{uploadtmp}; + $request->_body->tmpdir( $c->config->{uploadtmp} ) + if exists $c->config->{uploadtmp}; } while ( my $buffer = $self->read($c) ) { diff --git a/lib/Catalyst/Engine/CGI.pm b/lib/Catalyst/Engine/CGI.pm index 8416e09..ef8aa2a 100644 --- a/lib/Catalyst/Engine/CGI.pm +++ b/lib/Catalyst/Engine/CGI.pm @@ -57,9 +57,9 @@ sub prepare_connection { PROXY_CHECK: { - unless ( ref($c)->config->{using_frontend_proxy} ) { + unless ( $c->config->{using_frontend_proxy} ) { last PROXY_CHECK if $ENV{REMOTE_ADDR} ne '127.0.0.1'; - last PROXY_CHECK if ref($c)->config->{ignore_frontend_proxy}; + last PROXY_CHECK if $c->config->{ignore_frontend_proxy}; } last PROXY_CHECK unless $ENV{HTTP_X_FORWARDED_FOR}; @@ -126,9 +126,9 @@ sub prepare_path { # If we are running as a backend proxy, get the true hostname PROXY_CHECK: { - unless ( ref($c)->config->{using_frontend_proxy} ) { + unless ( $c->config->{using_frontend_proxy} ) { last PROXY_CHECK if $host !~ /localhost|127.0.0.1/; - last PROXY_CHECK if ref($c)->config->{ignore_frontend_proxy}; + last PROXY_CHECK if $c->config->{ignore_frontend_proxy}; } last PROXY_CHECK unless $ENV{HTTP_X_FORWARDED_HOST}; diff --git a/t/lib/TestAppSimple.pm b/t/lib/TestAppSimple.pm new file mode 100644 index 0000000..0b774bc --- /dev/null +++ b/t/lib/TestAppSimple.pm @@ -0,0 +1,21 @@ +use strict; +use warnings; + +package TestAppSimple; + +use Catalyst qw/ + Test::MangleDollarUnderScore + Test::Errors + Test::Headers + Test::Plugin +/; + +our $VERSION = '0.01'; + +__PACKAGE__->config( name => 'TestAppStats', root => '/some/dir' ); + +__PACKAGE__->setup; + +1; + + diff --git a/t/lib/TestAppSimple/Controller/Root.pm b/t/lib/TestAppSimple/Controller/Root.pm new file mode 100644 index 0000000..84b641b --- /dev/null +++ b/t/lib/TestAppSimple/Controller/Root.pm @@ -0,0 +1,18 @@ +package TestAppSimple::Controller::Root; +use base 'Catalyst::Controller'; +use Scalar::Util (); + +__PACKAGE__->config->{namespace} = ''; + +sub index : Private { + my ( $self, $c ) = @_; + $c->res->body('root index'); +} + +sub some_action : Local { + my ( $self, $c ) = @_; + $c->res->body('some_action'); +} + + +1; diff --git a/t/live_simple_app.t b/t/live_simple_app.t new file mode 100644 index 0000000..c8d7226 --- /dev/null +++ b/t/live_simple_app.t @@ -0,0 +1,12 @@ +use FindBin; +use lib "$FindBin::Bin/lib"; +use Catalyst::Test 'TestAppSimple', {default_host => 'default.com'}; +use Catalyst::Request; + +use Test::More; + +content_like('/',qr/root/,'root check'); +#content_like('/some_action',qr/some_action/,'some_action check'); + +done_testing; +