[Jifty-commit] r568 - in jifty/trunk: lib/Jifty
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Feb 10 05:12:22 EST 2006
Author: alexmv
Date: Fri Feb 10 05:12:21 2006
New Revision: 568
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Handler.pm
jifty/trunk/lib/Jifty/MasonHandler.pm
jifty/trunk/lib/Jifty/Web.pm
Log:
r9036 at zoq-fot-pik: chmrr | 2006-02-10 05:11:43 -0500
* One FakeApache object per handle_request
* Trap calls to CGI->new
Modified: jifty/trunk/lib/Jifty/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handler.pm (original)
+++ jifty/trunk/lib/Jifty/Handler.pm Fri Feb 10 05:12:21 2006
@@ -25,7 +25,7 @@
=cut
use base qw/Class::Accessor/;
-__PACKAGE__->mk_accessors(qw(mason dispatcher cgi));
+__PACKAGE__->mk_accessors(qw(mason dispatcher cgi apache));
=head2 new
@@ -63,6 +63,15 @@
);
}
+=head2 cgi
+
+Returns the L<CGI> object for the current request, or C<undef> if
+there is none.
+
+=head2 apache
+
+Returns the L<HTML::Mason::FakeApache> or L<Apache> objecvt for the
+current request, ot C<undef> if there is none.
=head2 handle_request
@@ -89,6 +98,14 @@
Module::Refresh->refresh;
$self->cgi($args{cgi});
+ $self->apache(HTML::Mason::FakeApache->new(cgi => $self->cgi));
+
+ # Creating a new CGI object breaks FastCGI in all sorts of painful
+ # ways. So wrap the call and preempt it if we already have one
+ use Hook::LexWrap;
+ wrap 'CGI::new', pre => sub {
+ $_[-1] = Jifty->handler->cgi if Jifty->handler->cgi;
+ };
local $HTML::Mason::Commands::JiftyWeb = Jifty::Web->new();
Jifty->web->request(Jifty::Request->new()->fill($self->cgi));
@@ -97,7 +114,6 @@
$self->mason(Jifty::MasonHandler->new(
$self->mason_config,
- cgi => $args{cgi},
));
$self->dispatcher(Jifty->config->framework('ApplicationClass')."::Dispatcher");
@@ -122,6 +138,7 @@
Jifty->web->session->unload();
Jifty::Record->flush_cache;
$self->cgi(undef);
+ $self->apache(undef);
}
1;
Modified: jifty/trunk/lib/Jifty/MasonHandler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/MasonHandler.pm (original)
+++ jifty/trunk/lib/Jifty/MasonHandler.pm Fri Feb 10 05:12:21 2006
@@ -33,14 +33,11 @@
__PACKAGE__->valid_params
(
interp => { isa => 'HTML::Mason::Interp' },
- cgi => { isa => 'CGI' },
);
__PACKAGE__->contained_objects
(
interp => 'HTML::Mason::Interp',
- fake_apache => { class => 'HTML::Mason::FakeApache', # $r
- delayed => 1 },
);
@@ -79,7 +76,7 @@
sub out_method {
my $m = HTML::Mason::Request->instance;
- my $r = $m->fake_apache;
+ my $r = Jifty->handler->apache;
$r->content_type || $r->content_type('text/html; charset=utf-8'); # Set up a default
@@ -138,7 +135,7 @@
=head2 handle_comp COMPONENT
-Takes a component path to render. Deals with setting up a
+Takes a component path to render. Deals with setting up a global
L<HTML::Mason::FakeApache> and Request object, and calling the
component.
@@ -147,10 +144,9 @@
sub handle_comp {
my ($self, $comp) = (shift, shift);
- # Create a new HTML::Mason::FakeApache object. But we don't really use it.
- my $r = $self->create_delayed_object('fake_apache', cgi => $self->{cgi});
+ # Set up the global
+ my $r = Jifty->handler->apache;
$self->interp->set_global('$r', $r);
- $self->interp->delayed_object_params('request', fake_apache => $r);
my %args = $self->request_args($r);
@@ -205,15 +201,6 @@
use HTML::Mason::Request;
use base qw(HTML::Mason::Request);
-use Params::Validate qw(BOOLEAN);
-Params::Validate::validation_options( on_fail => sub { param_error( join '', @_ ) } );
-
-__PACKAGE__->valid_params
- ( fake_apache => { isa => 'HTML::Mason::FakeApache' } );
-
-use HTML::Mason::MethodMaker
- ( read_only => [ 'fake_apache' ] );
-
=head2 auto_send_headers
Doesn't send headers if this is a subrequest (according to the current
@@ -235,7 +222,7 @@
sub exec
{
my $self = shift;
- my $r = $self->fake_apache;
+ my $r = Jifty->handler->apache;
my $retval;
eval { $retval = $self->SUPER::exec(@_) };
Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm (original)
+++ jifty/trunk/lib/Jifty/Web.pm Fri Feb 10 05:12:21 2006
@@ -616,18 +616,7 @@
# Clear out the mason output, if any
$self->mason->clear_buffer if $self->mason;
- # Now, we need to get out hands on a HTML::Mason::FakeApache --
- # but *carefully*. FakeApache wants a CGI object, and if it
- # doesn't get one, it makes one for itself. The difficulty is
- # that under FastCGI, if you ever create a second CGI object, it
- # wedges all future requests with the state of that request.
-
- # Hence, we use the FakeApache that HTTP::Mason::Request::Jifty
- # held onto, or we make one by hand, passing it the cgi object
- # that the handler is still holding onto
- my $apache = $self->mason ?
- $self->mason->fake_apache :
- HTML::Mason::FakeApache->new( cgi => Jifty->handler->cgi );
+ my $apache = Jifty->handler->apache;
# Headers..
$apache->header_out( Location => $page );
@@ -1082,7 +1071,7 @@
$self->response->add_header("Content-Type" => 'text/xml; charset=utf-8');
# Print a header and the content, and then bail
- my $apache = HTML::Mason::FakeApache->new( cgi => Jifty->handler->cgi );
+ my $apache = Jifty->handler->apache;
$apache->send_http_header();
# Wide characters at this point should be harmlessly treated as UTF-8 octets.
More information about the Jifty-commit
mailing list