[Rt-commit] rt branch, psgi, updated. rt-3.9.4-139-geca2962
Chia-liang Kao
clkao at bestpractical.com
Fri Oct 8 03:43:33 EDT 2010
The branch, psgi has been updated
via eca296250d96f95d5d75a6bf3604c06e0336c5e6 (commit)
via 776cee27d89a7b4b040c92d0d2b910d94793000e (commit)
via 883198ad6cc47dd34da0eec0eb3567428bd65c84 (commit)
from 26dda7259da745995780d75f530af2ae9803993e (commit)
Summary of changes:
app.psgi | 28 ++++++++++++---
bin/webmux.pl.in | 6 ++--
lib/RT/Interface/Web/Handler.pm | 72 ++++++++++++++++++++++++++++++---------
3 files changed, 81 insertions(+), 25 deletions(-)
- Log -----------------------------------------------------------------
commit 883198ad6cc47dd34da0eec0eb3567428bd65c84
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Fri Oct 8 14:03:41 2010 +0800
common bits of mason dir index.
diff --git a/lib/RT/Interface/Web/Handler.pm b/lib/RT/Interface/Web/Handler.pm
index d839a52..83cc7c6 100644
--- a/lib/RT/Interface/Web/Handler.pm
+++ b/lib/RT/Interface/Web/Handler.pm
@@ -165,6 +165,20 @@ sub NewHandler {
return($handler);
}
+=head2 _mason_dir_index
+
+=cut
+
+sub _mason_dir_index {
+ my ($self, $interp, $path) = @_;
+ if ( !$interp->comp_exists( $path )
+ && $interp->comp_exists( $path . "/index.html" ) )
+ {
+ return $path . "/index.html";
+ }
+
+ return $path;
+}
=head2 HandleRequest
@@ -179,11 +193,7 @@ sub HandleRequest {
RT::ConnectToDatabase() unless RT->InstallMode;
my $interp = $RT::Mason::Handler->interp;
- if ( !$interp->comp_exists( $cgi->path_info )
- && $interp->comp_exists( $cgi->path_info . "/index.html" ) )
- {
- $cgi->path_info( $cgi->path_info . "/index.html" );
- }
+ $cgi->path_info( $self->_mason_dir_index($interp, $cgi->path_info));
local $@;
eval { $RT::Mason::Handler->handle_cgi_object($cgi); };
@@ -267,6 +277,8 @@ use Plack::Request;
use Encode qw(is_utf8 encode_utf8);
sub PSGIApp {
+ my $self = shift;
+
require HTML::Mason::CGIHandler;
require HTML::Mason::PSGIHandler;
my $h = RT::Interface::Web::Handler::NewHandler('HTML::Mason::PSGIHandler');
@@ -276,13 +288,7 @@ sub PSGIApp {
my $req = Plack::Request->new($env);
- unless ( $h->interp->comp_exists( $req->path_info ) ) {
- my $path = $req->path_info;
- $path .= '/' unless $path =~ m{/$};
- $path .= 'index.html';
- $env->{PATH_INFO} = $path
- if $h->interp->comp_exists( $path );
- }
+ $env->{PATH_INFO} = $self->_mason_dir_index( $h->interp, $req->path_info);
my $ret;
{
commit 776cee27d89a7b4b040c92d0d2b910d94793000e
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Fri Oct 8 15:25:48 2010 +0800
Avoid the $RT::Mason::Handler global variable in RT::Interface::Web::Handler
diff --git a/bin/webmux.pl.in b/bin/webmux.pl.in
index f49777f..7fef7db 100755
--- a/bin/webmux.pl.in
+++ b/bin/webmux.pl.in
@@ -146,9 +146,9 @@ RT::Init();
}
require RT::Interface::Web::Handler;
-$RT::Mason::Handler = RT::Interface::Web::Handler->new(
- RT->Config->Get('MasonParameters')
-);
+# XXX: this is for the maybe-used package variable of the modperl handler: RT::Mason
+$RT::Mason::Handler = RT::Interface::Web::Handler->Init(undef,
+ RT->Config->Get('MasonParameters'));
# load more for mod_perl before forking
RT::InitClasses( Heavy => 1 ) if $ENV{'MOD_PERL'} || $ENV{RT_WEBMUX_HEAVY_LOAD};
diff --git a/lib/RT/Interface/Web/Handler.pm b/lib/RT/Interface/Web/Handler.pm
index 83cc7c6..145eedd 100644
--- a/lib/RT/Interface/Web/Handler.pm
+++ b/lib/RT/Interface/Web/Handler.pm
@@ -85,12 +85,15 @@ sub DefaultHandlerArgs { (
=head2 new
+DEPRECATED: this method is to be removed as it's not the constructor of the class which is confusing
+
Constructs a web handler of the appropriate class.
Takes options to pass to the constructor.
=cut
sub new {
+ Carp::carp "DEPRECATED: call RT::Interface::Handler->Init instead";
my $class = shift;
$class->InitSessionDir;
@@ -102,6 +105,34 @@ sub new {
}
}
+=head2 Init
+
+ Initialize and return the mason web handler for current environment.
+
+=cut
+
+my $_handler;
+
+sub Init {
+ my $class = shift;
+ my $handler_class = shift;
+ my @handler_args = @_;
+
+ $class->InitSessionDir;
+
+ unless ($handler_class) {
+ if ( ($mod_perl::VERSION && $mod_perl::VERSION >= 1.9908) || $CGI::MOD_PERL) {
+ $handler_class = 'HTML::Mason::ApacheHandler';
+ unshift @handler_args, args_method => "CGI";
+ }
+ else {
+ $handler_class = 'HTML::Mason::CGIHandler';
+ }
+ }
+
+ $_handler = NewHandler($handler_class, @handler_args);
+}
+
sub InitSessionDir {
# Activate the following if running httpd as root (the normal case).
# Resets ownership of all files created by Mason at startup.
@@ -153,8 +184,10 @@ sub NewCGIHandler {
return NewHandler('HTML::Mason::CGIHandler', @_);
}
+use UNIVERSAL::require;
sub NewHandler {
my $class = shift;
+ $class->require or die $!;
my $handler = $class->new(
DefaultHandlerArgs(),
@_
@@ -192,11 +225,11 @@ sub HandleRequest {
Module::Refresh->refresh if RT->Config->Get('DevelMode');
RT::ConnectToDatabase() unless RT->InstallMode;
- my $interp = $RT::Mason::Handler->interp;
+ my $interp = $_handler->interp;
$cgi->path_info( $self->_mason_dir_index($interp, $cgi->path_info));
local $@;
- eval { $RT::Mason::Handler->handle_cgi_object($cgi); };
+ eval { $_handler->handle_cgi_object($cgi); };
if ($@) {
$RT::Logger->crit($@);
}
@@ -280,8 +313,8 @@ sub PSGIApp {
my $self = shift;
require HTML::Mason::CGIHandler;
- require HTML::Mason::PSGIHandler;
my $h = RT::Interface::Web::Handler::NewHandler('HTML::Mason::PSGIHandler');
+
return sub {
my $env = shift;
RT::ConnectToDatabase() unless RT->InstallMode;
@@ -297,9 +330,10 @@ sub PSGIApp {
$ret = $h->handle_psgi($env);
}
+
$RT::Logger->crit($@) if $@ && $RT::Logger;
warn $@ if $@ && !$RT::Logger;
- RT::Interface::Web::Handler->CleanupRequest();
+ $self->CleanupRequest();
if ($ret->[2] ) {
# XXX: for now. the out_method for mason can be more careful
# and perhaps even streamy. this should also check for
commit eca296250d96f95d5d75a6bf3604c06e0336c5e6
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Fri Oct 8 15:26:17 2010 +0800
do our own init in .psgi
diff --git a/app.psgi b/app.psgi
index 3e447db..1e7cfdd 100644
--- a/app.psgi
+++ b/app.psgi
@@ -47,14 +47,30 @@
# END BPS TAGGED BLOCK }}}
use warnings;
use strict;
+require RT;
-use File::Basename;
-eval {
- require (dirname(__FILE__) .'/bin/webmux.pl');
-};
-if ($@) {
- die "failed to load bin/webmux.pl: $@";
+RT::LoadConfig();
+if ( RT->Config->Get('DevelMode') ) {
+ # XXX: hint to use plack -r
}
+RT::Init();
+
+# check compatibility of the DB
+{
+ my $dbh = $RT::Handle->dbh;
+ if ( $dbh ) {
+ my ($status, $msg) = $RT::Handle->CheckCompatibility( $dbh, 'post' );
+ die $msg unless $status;
+ }
+}
+
+require RT::Interface::Web::Handler;
+RT::Interface::Web::Handler->InitSessionDir;
+
+RT::InitClasses( Heavy => 1 );
+
+$RT::Handle->dbh(undef);
+undef $RT::Handle;
RT::Interface::Web::Handler->PSGIApp;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list