[Rt-commit] r2482 - in HTTP-Server-Simple-Mason: . lib/HTTP/Server/Simple t

jesse at bestpractical.com jesse at bestpractical.com
Mon Mar 21 07:23:25 EST 2005


Author: jesse
Date: Mon Mar 21 07:23:25 2005
New Revision: 2482

Modified:
   HTTP-Server-Simple-Mason/   (props changed)
   HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm
   HTTP-Server-Simple-Mason/t/01live.t
Log:
 r9490 at hualien:  jesse | 2005-03-21 17:08:20 +0800
 * Updated to be API compatible with newer HTTP::Server::Simple


Modified: HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm
==============================================================================
--- HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm	(original)
+++ HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm	Mon Mar 21 07:23:25 2005
@@ -1,7 +1,7 @@
 package HTTP::Server::Simple::Mason;
-use base qw/HTTP::Server::Simple/;
+use base qw/HTTP::Server::Simple::CGI/;
 use strict;
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 NAME
 
@@ -10,7 +10,7 @@
 
 =head1 VERSION
 
-This document describes HTTP::Server:Simple::Mason version 0.0.1
+This document describes HTTP::Server:Simple::Mason version 0.02
 
 
 =head1 SYNOPSIS
@@ -43,19 +43,26 @@
 
 use HTML::Mason::CGIHandler;
 
-sub handler {
+sub mason_handler {
     my $self = shift;
-    $self->{'handler'} ||= $self->new_handler;
-    return $self->{'handler'};
+    $self->{'mason_handler'} ||= $self->new_handler;
+    return $self->{'mason_handler'};
 }
 
+=head2 handle_request CGI
+
+Called with a CGI object. Invokes mason and runs the request
+
+=cut
+
 sub handle_request {
     my $self = shift;
     my $cgi  = shift;
+
     if (
-        ( !$self->handler->interp->comp_exists( $cgi->path_info ) )
+        ( !$self->mason_handler->interp->comp_exists( $cgi->path_info ) )
         && (
-            $self->handler->interp->comp_exists(
+            $self->mason_handler->interp->comp_exists(
                 $cgi->path_info . "/index.html"
             )
         )
@@ -69,13 +76,16 @@
 Content-Type: text/html
 EOF
 
-    eval { $self->handler->handle_cgi_object($cgi); };
-
+    eval { $self->mason_handler->handle_cgi_object($cgi); };
 }
 
 sub new_handler {
     my $self    = shift;
-    my $handler = HTML::Mason::CGIHandler->new( $self->handler_config, @_ );
+    my $handler = HTML::Mason::CGIHandler->new(
+        $self->default_mason_config,
+        $self->mason_config,
+        @_
+    );
 
     $handler->interp->set_escape(
         h => \&HTTP::Server::Simple::Mason::escape_utf8 );
@@ -84,7 +94,23 @@
     return ($handler);
 }
 
-sub handler_config {
+=head2 mason_config
+
+Subclass-defined mason handler configuration
+
+=cut
+
+sub mason_config {
+    (); # user-defined
+}
+
+=head2 default_mason_config
+
+Default mason handler configuration
+
+=cut
+
+sub default_mason_config {
     (
         default_escape_flags => 'h',
 

Modified: HTTP-Server-Simple-Mason/t/01live.t
==============================================================================
--- HTTP-Server-Simple-Mason/t/01live.t	(original)
+++ HTTP-Server-Simple-Mason/t/01live.t	Mon Mar 21 07:23:25 2005
@@ -12,7 +12,8 @@
 my $s=MyApp::Server->new(13432);
 is($s->port(),13432,"Constructor set port correctly");
 my $pid=$s->background();
-like($pid, qr/^\d+$/,'pid is numeric');
+like($pid, qr/^-?\d+$/,'pid is numeric');
+sleep(1);
 my $content=LWP::Simple::get("http://localhost:13432");
 like($content,qr/2$/,"Returns a page containing only 2");
 is(kill(9,$pid),1,'Signaled 1 process successfully');
@@ -24,15 +25,13 @@
 use base qw/HTTP::Server::Simple::Mason/;
 use File::Spec;
 
-mkdir( File::Spec->tmpdir.'/mason-pages' );
-open (PAGE, ">". File::Spec->tmpdir.'/mason-pages/index.html'); 
-print PAGE "<%1+1%>";
-close (PAGE);
-
-sub handler_config {
-    my $self = shift;
-     
-    return ( $self->SUPER::handler_config, comp_root => File::Spec->tmpdir.'/mason-pages/' );
+sub mason_config {
+    my $root = File::Spec->catdir(File::Spec->tmpdir, "mason-pages-$$");
+    mkdir( $root ) or die $!;
+    open (PAGE, '>', File::Spec->catfile($root, 'index.html')) or die $!;
+    print PAGE '<%1+1%>';
+    close (PAGE);
+    return ( comp_root => $root );
 }
 
 1;


More information about the Rt-commit mailing list