[Rt-commit] [svn] r1213 - in rt: . branches/rt-3.1/bin branches/rt-3.1/lib/RT/Interface branches/rt-3.1/lib/RT/Interface/Web

autrijus at pallas.eruditorum.org autrijus at pallas.eruditorum.org
Mon Jul 12 21:03:09 EDT 2004


Author: autrijus
Date: Mon Jul 12 21:03:09 2004
New Revision: 1213

Added:
   rt/branches/rt-3.1/lib/RT/Interface/Web/
   rt/branches/rt-3.1/lib/RT/Interface/Web/Handler.pm
Modified:
   rt/   (props changed)
   rt/branches/rt-3.1/bin/mason_handler.fcgi.in
   rt/branches/rt-3.1/bin/mason_handler.scgi.in
   rt/branches/rt-3.1/bin/mason_handler.svc.in
   rt/branches/rt-3.1/bin/webmux.pl.in
   rt/branches/rt-3.1/lib/RT/Interface/Web.pm
Log:
 ----------------------------------------------------------------------
 r5999:  autrijus | 2004-07-13T00:35:02.795788Z

 * Refactor all web handler creation and initialization logic away from
   RT::Interface::Web, webmux and mason_handle scripts, into a new module
   "RT::Interface::Web::Handler".
 ----------------------------------------------------------------------


Modified: rt/branches/rt-3.1/bin/mason_handler.fcgi.in
==============================================================================
--- rt/branches/rt-3.1/bin/mason_handler.fcgi.in	(original)
+++ rt/branches/rt-3.1/bin/mason_handler.fcgi.in	Mon Jul 12 21:03:09 2004
@@ -23,12 +23,13 @@
 # 
 # END LICENSE BLOCK
 
+package RT::Mason;
+
 use strict;
+use vars '$Handler';
 use File::Basename;
 require ('@RT_BIN_PATH@/webmux.pl');
 
-my $h = &RT::Interface::Web::NewCGIHandler(@RT::MasonParameters);
-
 # Enter CGI::Fast mode, which should also work as a vanilla CGI script.
 require CGI::Fast;
 
@@ -45,12 +46,12 @@
 
     RT::ConnectToDatabase();
 
-    if ( ( !$h->interp->comp_exists( $cgi->path_info ) )
-        && ( $h->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) {
+    if ( ( !$Handler->interp->comp_exists( $cgi->path_info ) )
+        && ( $Handler->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) {
         $cgi->path_info( $cgi->path_info . "/index.html" );
     }
 
-    eval { $h->handle_cgi_object($cgi); };
+    eval { $Handler->handle_cgi_object($cgi); };
     if ($@) {
         $RT::Logger->crit($@);
     }

Modified: rt/branches/rt-3.1/bin/mason_handler.scgi.in
==============================================================================
--- rt/branches/rt-3.1/bin/mason_handler.scgi.in	(original)
+++ rt/branches/rt-3.1/bin/mason_handler.scgi.in	Mon Jul 12 21:03:09 2004
@@ -23,21 +23,22 @@
 # 
 # END LICENSE BLOCK
 
+package RT::Mason;
+
 use strict;
+use vars '$Handler';
 require ('@RT_BIN_PATH@/webmux.pl');
 
-my $h = &RT::Interface::Web::NewCGIHandler(@RT::MasonParameters);
-
 require CGI;
 
 RT::Init();
 
 my $cgi = CGI->new;
-if ( ( !$h->interp->comp_exists( $cgi->path_info ) )
-    && ( $h->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) {
+if ( ( !$Handler->interp->comp_exists( $cgi->path_info ) )
+    && ( $Handler->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) {
     $cgi->path_info( $cgi->path_info . "/index.html" );
 }
 
-$h->handle_cgi_object($cgi);
+$Handler->handle_cgi_object($cgi);
 
 1;

Modified: rt/branches/rt-3.1/bin/mason_handler.svc.in
==============================================================================
--- rt/branches/rt-3.1/bin/mason_handler.svc.in	(original)
+++ rt/branches/rt-3.1/bin/mason_handler.svc.in	Mon Jul 12 21:03:09 2004
@@ -55,8 +55,11 @@
 
 =cut
 
+package RT::Mason;
+
 use strict;
 use File::Basename;
+use vars '$Handler';
 require (dirname(__FILE__) . '/webmux.pl');
 
 use Cwd;
@@ -197,7 +200,6 @@
 warn "Begin listening on $ENV{'FCGI_SOCKET_PATH'}\n";
 
 require CGI::Fast;
-my $h = &RT::Interface::Web::NewCGIHandler(@RT::MasonParameters);
 
 RT::Init();
 
@@ -212,7 +214,7 @@
     
     warn "Serving $comp\n";
 
-    $h->handle_cgi($comp);
+    $Handler->handle_cgi($comp);
     # _should_ always be tied
 }
 

Modified: rt/branches/rt-3.1/bin/webmux.pl.in
==============================================================================
--- rt/branches/rt-3.1/bin/webmux.pl.in	(original)
+++ rt/branches/rt-3.1/bin/webmux.pl.in	Mon Jul 12 21:03:09 2004
@@ -32,7 +32,8 @@
     $ENV{'ENV'}    = '' if defined $ENV{'ENV'};
     $ENV{'IFS'}    = '' if defined $ENV{'IFS'};
 
-    eval { require Apache2; require Apache::compat }
+    eval { require Apache2; require APR::Table; require MasonX::Apache2Handler; 1 } or
+    eval { require Apache2; require Apache::compat; 1 } or die $@
       if $ENV{'MOD_PERL'}
       and $ENV{'MOD_PERL'} =~ m{mod_perl/(?:2|1\.9)};
 
@@ -46,30 +47,9 @@
 use CGI qw(-private_tempfiles);    #bring this in before mason, to make sure we
                                    #set private_tempfiles
 
-BEGIN {
-    if ( $mod_perl::VERSION && ( $mod_perl::VERSION >= 1.9908 ) ) {
-        require Apache::RequestUtil;
-        no warnings 'redefine';
-        my $sub = *Apache::request{CODE};
-        *Apache::request = sub {
-            my $r;
-            eval { $r = $sub->('Apache'); };
-
-            # warn $@ if $@;
-            return $r;
-        };
-    }
-    if ($CGI::MOD_PERL) {
-        require HTML::Mason::ApacheHandler;
-    }
-    else {
-        require HTML::Mason::CGIHandler;
-    }
-}
-
 use HTML::Mason;    # brings in subpackages: Parser, Interp, etc.
 
-use vars qw($Nobody $SystemUser $r);
+use vars qw($Nobody $SystemUser $Handler $r);
 
 #This drags in RT's config.pm
 RT::LoadConfig();
@@ -106,28 +86,7 @@
     use Text::Quoted;
 }
 
-# Activate the following if running httpd as root (the normal case).
-# Resets ownership of all files created by Mason at startup.
-# Note that mysql uses DB for sessions, so there's no need to do this.
-unless ( $RT::DatabaseType =~ /(mysql|Pg)/ ) {
-
-    # Clean up our umask to protect session files
-    umask(0077);
-
-    if ($CGI::MOD_PERL) {
-        chown( Apache->server->uid, Apache->server->gid,
-            [$RT::MasonSessionDir] )
-          if Apache->server->can('uid');
-    }
-
-    # Die if WebSessionDir doesn't exist or we can't write to it
-    stat($RT::MasonSessionDir);
-    die "Can't read and write $RT::MasonSessionDir"
-      unless ( ( -d _ ) and ( -r _ ) and ( -w _ ) );
-}
-
-my $ah = &RT::Interface::Web::NewApacheHandler(@RT::MasonParameters)
-  if $CGI::MOD_PERL;
+$Handler = RT::Interface::Web::Handler->new(@RT::MasonParameters);
 
 sub handler {
     ($r) = @_;
@@ -142,7 +101,7 @@
 
     my %session;
     my $status;
-    eval { $status = $ah->handle_request($r) };
+    eval { $status = $Handler->handle_request($r) };
     if ($@) {
         $RT::Logger->crit($@);
     }

Modified: rt/branches/rt-3.1/lib/RT/Interface/Web.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Interface/Web.pm	(original)
+++ rt/branches/rt-3.1/lib/RT/Interface/Web.pm	Mon Jul 12 21:03:09 2004
@@ -45,63 +45,6 @@
 
 
 
-my @DefaultHandlerArgs = (
-
-    comp_root => [
-        [ local    => $RT::MasonLocalComponentRoot ],
-        [ standard => $RT::MasonComponentRoot ]
-    ],
-    default_escape_flags => 'h',
-    data_dir             => "$RT::MasonDataDir",
-    allow_globals        => [qw(%session)],
-    autoflush            => 1
-
-);
-
-# {{{ sub NewApacheHandler 
-
-=head2 NewApacheHandler
-
-  Takes extra options to pass to HTML::Mason::ApacheHandler->new
-  Returns a new Mason::ApacheHandler object
-
-=cut
-
-sub NewApacheHandler {
-    require HTML::Mason::ApacheHandler;
-    return RT::Interface::Web::NewHandler('HTML::Mason::ApacheHandler',
-                                            args_method => "CGI",
-                                            @_);
-}
-
-# }}}
-
-# {{{ sub NewCGIHandler 
-
-=head2 NewCGIHandler
-
-  Returns a new Mason::CGIHandler object
-
-=cut
-
-sub NewCGIHandler {
-    return RT::Interface::Web::NewHandler('HTML::Mason::CGIHandler', at _);
-}
-
-sub NewHandler {
-    my $class = shift;
-    my $handler = $class->new(
-        @DefaultHandlerArgs,
-        @_
-    );
-  
-    $handler->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
-    return($handler);
-}
-
-# }}}
-
-
 # {{{ EscapeUTF8
 
 =head2 EscapeUTF8 SCALARREF

Added: rt/branches/rt-3.1/lib/RT/Interface/Web/Handler.pm
==============================================================================
--- (empty file)
+++ rt/branches/rt-3.1/lib/RT/Interface/Web/Handler.pm	Mon Jul 12 21:03:09 2004
@@ -0,0 +1,133 @@
+package RT::Interface::Web::Handler;
+
+my @DefaultHandlerArgs = (
+    comp_root => [
+        [ local    => $RT::MasonLocalComponentRoot ],
+        [ standard => $RT::MasonComponentRoot ]
+    ],
+    default_escape_flags => 'h',
+    data_dir             => "$RT::MasonDataDir",
+    allow_globals        => [qw(%session)],
+    autoflush            => 1
+);
+
+# {{{ sub new 
+
+=head2 new
+
+  Constructs a web handler of the appropriate class.
+  Takes options to pass to the constructor.
+
+=cut
+
+sub new {
+    my $class = shift;
+    $class->InitSessionDir;
+
+    if ($MasonX::Apache2Handler::VERSION) {
+        goto &NewApache2Handler;
+    }
+    elsif ($mod_perl::VERSION >= 1.9908) {
+	require Apache::RequestUtil;
+	no warnings 'redefine';
+	my $sub = *Apache::request{CODE};
+	*Apache::request = sub {
+	    my $r;
+	    eval { $r = $sub->('Apache'); };
+	    # warn $@ if $@;
+	    return $r;
+	};
+        goto &NewApacheHandler;
+    }
+    elsif ($CGI::MOD_PERL) {
+        goto &NewApacheHandler;
+    }
+    else {
+        goto &NewCGIHandler;
+    }
+}
+
+sub InitSessionDir {
+    # Activate the following if running httpd as root (the normal case).
+    # Resets ownership of all files created by Mason at startup.
+    # Note that mysql uses DB for sessions, so there's no need to do this.
+    unless ( $RT::DatabaseType =~ /(mysql|Pg)/ ) {
+
+        # Clean up our umask to protect session files
+        umask(0077);
+
+        if ($CGI::MOD_PERL) {
+            chown( Apache->server->uid, Apache->server->gid,
+                [$RT::MasonSessionDir] )
+            if Apache->server->can('uid');
+        }
+
+        # Die if WebSessionDir doesn't exist or we can't write to it
+        stat($RT::MasonSessionDir);
+        die "Can't read and write $RT::MasonSessionDir"
+        unless ( ( -d _ ) and ( -r _ ) and ( -w _ ) );
+    }
+
+}
+
+# }}}
+
+# {{{ sub NewApacheHandler 
+
+=head2 NewApacheHandler
+
+  Takes extra options to pass to HTML::Mason::ApacheHandler->new
+  Returns a new Mason::ApacheHandler object
+
+=cut
+
+sub NewApacheHandler {
+    require HTML::Mason::ApacheHandler;
+    return NewHandler('HTML::Mason::ApacheHandler', args_method => "CGI", @_);
+}
+
+# }}}
+
+# {{{ sub NewApache2Handler 
+
+=head2 NewApache2Handler
+
+  Takes extra options to pass to MasonX::Apache2Handler->new
+  Returns a new MasonX::Apache2Handler object
+
+=cut
+
+sub NewApache2Handler {
+    require MasonX::Apache2Handler;
+    return NewHandler('MasonX::Apache2Handler', @_);
+}
+
+# }}}
+
+# {{{ sub NewCGIHandler 
+
+=head2 NewCGIHandler
+
+  Returns a new Mason::CGIHandler object
+
+=cut
+
+sub NewCGIHandler {
+    require HTML::Mason::CGIHandler;
+    return NewHandler('HTML::Mason::CGIHandler', @_);
+}
+
+sub NewHandler {
+    my $class = shift;
+    my $handler = $class->new(
+        @DefaultHandlerArgs,
+        @_
+    );
+  
+    $handler->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
+    return($handler);
+}
+
+# }}}
+
+1;


More information about the Rt-commit mailing list