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

jesse at bestpractical.com jesse at bestpractical.com
Tue Jan 11 16:17:30 EST 2005


Author: jesse
Date: Tue Jan 11 16:17:28 2005
New Revision: 2068

Added:
   HTTP-Server-Simple-Mason/MANIFEST
   HTTP-Server-Simple-Mason/Makefile.PL
   HTTP-Server-Simple-Mason/SIGNATURE
   HTTP-Server-Simple-Mason/ex/
   HTTP-Server-Simple-Mason/ex/sample_server.pl
   HTTP-Server-Simple-Mason/lib/
   HTTP-Server-Simple-Mason/lib/HTTP/
   HTTP-Server-Simple-Mason/lib/HTTP/Server/
   HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/
   HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm
   HTTP-Server-Simple-Mason/t/
   HTTP-Server-Simple-Mason/t/00smoke.t
   HTTP-Server-Simple-Mason/t/01live.t
   HTTP-Server-Simple-Mason/t/02pod.t
   HTTP-Server-Simple-Mason/t/03podcoverage.t
Modified:
   HTTP-Server-Simple-Mason/   (props changed)
Log:
 r2684 at hualien:  jesse | 2005-01-11T22:53:22.169228Z
 Initial version


Added: HTTP-Server-Simple-Mason/MANIFEST
==============================================================================
--- (empty file)
+++ HTTP-Server-Simple-Mason/MANIFEST	Tue Jan 11 16:17:28 2005
@@ -0,0 +1,18 @@
+ex/sample_server.pl
+inc/Module/Install.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+lib/HTTP/Server/Simple/Mason.pm
+Makefile.PL
+MANIFEST			This list of files
+META.yml
+SIGNATURE
+t/00smoke.t
+t/01live.t
+t/02pod.t
+t/03podcoverage.t

Added: HTTP-Server-Simple-Mason/Makefile.PL
==============================================================================
--- (empty file)
+++ HTTP-Server-Simple-Mason/Makefile.PL	Tue Jan 11 16:17:28 2005
@@ -0,0 +1,12 @@
+use inc::Module::Install;
+
+name('HTTP-Server-Simple-Mason');
+version_from('lib/HTTP/Server/Simple/Mason.pm');
+author('Jesse Vincent <jesse at bestpractical.com>');
+license('perl');
+abstract('A simple mason server');
+requires( HTTP::Server::Simple => 0,
+          HTML::Mason => 1.25
+      );
+
+&WriteAll;

Added: HTTP-Server-Simple-Mason/SIGNATURE
==============================================================================
--- (empty file)
+++ HTTP-Server-Simple-Mason/SIGNATURE	Tue Jan 11 16:17:28 2005
@@ -0,0 +1,40 @@
+This file contains message digests of all files listed in MANIFEST,
+signed via the Module::Signature module, version 0.41.
+
+To verify the content in this distribution, first make sure you have
+Module::Signature installed, then type:
+
+    % cpansign -v
+
+It would check each file's integrity, as well as the signature's
+validity.  If "==> Signature verified OK! <==" is not displayed,
+the distribution may already have been compromised, and you should
+not run its Makefile.PL or Build.PL.
+
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+SHA1 19ea34ac62391979ff472becd17a788678c2693f MANIFEST
+SHA1 7775ca9389085c641d0a25a23822851c7c21fdd3 META.yml
+SHA1 5f5e8638d25b9b31c6c6e856f4e6a10ab3794c3f Makefile.PL
+SHA1 1841b7bebace8741cbc7e5157f7e845200a60cc0 ex/sample_server.pl
+SHA1 05d89e1fe6d49cd518b5a3e6694cc313e655fb02 inc/Module/Install.pm
+SHA1 2e300b145ee61eea9dfd71624b17b0bc9218aa4f inc/Module/Install/Base.pm
+SHA1 29ce36027266c1839b496bf660396e0a91ab53cf inc/Module/Install/Can.pm
+SHA1 c0f347c388074beb42aad080661c7e3552110c71 inc/Module/Install/Fetch.pm
+SHA1 e094fe96aef06c68d7a424818c12e52b11f1ccdd inc/Module/Install/Makefile.pm
+SHA1 e448c6dc5351ef425e3f8bdbeb642409120bc3ca inc/Module/Install/Metadata.pm
+SHA1 134de6ff2f762873b6a1af950dd53f8e0a801d73 inc/Module/Install/Win32.pm
+SHA1 1ec06df292af7f652d33db6129e9e4c7cc8b5095 inc/Module/Install/WriteAll.pm
+SHA1 2c908ac5fbac643fde68e29e54bd21d7468706f0 lib/HTTP/Server/Simple/Mason.pm
+SHA1 c465222b356e9f0af0721ac0e6473eb534f2d90c t/00smoke.t
+SHA1 458212ae35371955b7045c6c22fe798a0c25c4b3 t/01live.t
+SHA1 aca95653cfce68912e08c57b3a4566207e2f99b3 t/02pod.t
+SHA1 2bb1170c8af4a70c4997ca2805c376d4c94c444e t/03podcoverage.t
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.2.5 (GNU/Linux)
+
+iD8DBQFB5FhHEi9d9xCOQEYRAqExAJ9l2gwuLNdMxhnoIFVv6PDWipIwpwCfQM/H
+Sw1u6SAHP4HdSgojK6zjFEk=
+=aazj
+-----END PGP SIGNATURE-----

Added: HTTP-Server-Simple-Mason/ex/sample_server.pl
==============================================================================
--- (empty file)
+++ HTTP-Server-Simple-Mason/ex/sample_server.pl	Tue Jan 11 16:17:28 2005
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+my $server = MyApp::Server->new();
+
+$server->run;
+
+package MyApp::Server;
+use base qw/HTTP::Server::Simple::Mason/;
+
+sub handler_config {
+    my $self = shift;
+    return ( $self->SUPER::handler_config, comp_root => '/tmp/mason-pages' );
+}
+
+1;

Added: HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm
==============================================================================
--- (empty file)
+++ HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm	Tue Jan 11 16:17:28 2005
@@ -0,0 +1,213 @@
+package HTTP::Server::Simple::Mason;
+use base qw/HTTP::Server::Simple/;
+use strict;
+our $VERSION = '0.01';
+
+=head1 NAME
+
+HTTP::Server::Simple::Mason - An abstract baseclass for a standalone mason server
+
+
+=head1 VERSION
+
+This document describes HTTP::Server:Simple::Mason version 0.0.1
+
+
+=head1 SYNOPSIS
+
+
+	my $server = MyApp::Server->new();
+	
+	$server->run;
+	
+	package MyApp::Server;
+	use base qw/HTTP::Server::Simple::Mason/;
+	
+	sub handler_config {
+	    my $self = shift;
+	    return ( $self->SUPER::handler_config, comp_root => '/tmp/mason-pages' );
+	}
+
+    1;
+
+=head1 DESCRIPTION
+
+
+=head1 INTERFACE
+
+See L<HTTP::Server::Simple> and the documentation below.
+
+=cut
+
+
+
+use HTML::Mason::CGIHandler;
+
+sub handler {
+    my $self = shift;
+    $self->{'handler'} ||= $self->new_handler;
+    return $self->{'handler'};
+}
+
+sub handle_request {
+    my $self = shift;
+    my $cgi  = shift;
+    if (
+        ( !$self->handler->interp->comp_exists( $cgi->path_info ) )
+        && (
+            $self->handler->interp->comp_exists(
+                $cgi->path_info . "/index.html"
+            )
+        )
+      )
+    {
+        $cgi->path_info( $cgi->path_info . "/index.html" );
+    }
+
+            print <<EOF;
+HTTP/1.0 200 OK
+Content-Type: text/html
+EOF
+
+    eval { $self->handler->handle_cgi_object($cgi); };
+
+}
+
+sub new_handler {
+    my $self    = shift;
+    my $handler = HTML::Mason::CGIHandler->new( $self->handler_config, @_ );
+
+    $handler->interp->set_escape(
+        h => \&HTTP::Server::Simple::Mason::escape_utf8 );
+    $handler->interp->set_escape(
+        u => \&HTTP::Server::Simple::Mason::escape_uri );
+    return ($handler);
+}
+
+sub handler_config {
+    (
+        default_escape_flags => 'h',
+
+        # Turn off static source if we're in developer mode.
+        autoflush => 0
+    );
+}
+
+# {{{ escape_utf8
+
+=head2 escape_utf8 SCALARREF
+
+does a css-busting but minimalist escaping of whatever html you're passing in.
+
+=cut
+
+sub escape_utf8 {
+    my $ref = shift;
+    my $val = $$ref;
+    use bytes;
+    $val =~ s/&/&#38;/g;
+    $val =~ s/</&lt;/g;
+    $val =~ s/>/&gt;/g;
+    $val =~ s/\(/&#40;/g;
+    $val =~ s/\)/&#41;/g;
+    $val =~ s/"/&#34;/g;
+    $val =~ s/'/&#39;/g;
+    $$ref = $val;
+    Encode::_utf8_on($$ref);
+
+}
+
+# }}}
+
+# {{{ escape_uri
+
+=head2 escape_uri SCALARREF
+
+Escapes URI component according to RFC2396
+
+=cut
+
+use Encode qw();
+
+sub escape_uri {
+    my $ref = shift;
+    $$ref = Encode::encode_utf8($$ref);
+    $$ref =~ s/([^a-zA-Z0-9_.!~*'()-])/uc sprintf("%%%02X", ord($1))/eg;
+    Encode::_utf8_on($$ref);
+}
+
+# }}}
+
+
+
+=head1 CONFIGURATION AND ENVIRONMENT
+
+For most configuration, see L<HTTP::Server::Simple>.
+
+You can (and must) configure your mason CGI handler by subclassing this module and overriding
+the subroutine 'handler_config'. It's most important that you set a component root (where your pages live)
+by adding 
+
+    comp_root => '/some/absolute/path'
+
+
+
+=head1 DEPENDENCIES
+
+
+L<HTTP::Server::Simple>
+L<HTML::Mason>
+
+=head1 INCOMPATIBILITIES
+
+None reported.
+
+
+=head1 BUGS AND LIMITATIONS
+
+
+Please report any bugs or feature requests to
+C<bug-http-server-simple-mason at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org>.
+
+
+=head1 AUTHOR
+
+Jesse Vincent C<< <jesse at bestpractical.com> >>
+
+
+=head1 LICENCE AND COPYRIGHT
+
+Copyright (c) 2001-2005, Jesse Vincent  C<< <jesse at bestpractical.com> >>. All rights reserved.
+
+This module is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+
+=head1 DISCLAIMER OF WARRANTY
+
+BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
+EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
+ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
+YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
+NECESSARY SERVICING, REPAIR, OR CORRECTION.
+
+IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
+LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
+OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
+THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+=cut
+
+
+1;

Added: HTTP-Server-Simple-Mason/t/00smoke.t
==============================================================================
--- (empty file)
+++ HTTP-Server-Simple-Mason/t/00smoke.t	Tue Jan 11 16:17:28 2005
@@ -0,0 +1,11 @@
+use Test::More tests=>8;
+
+use_ok(HTTP::Server::Simple::Mason);
+ok(HTTP::Server::Simple::Mason->can('new'), 'can new()');
+my $s= HTTP::Server::Simple::Mason->new();
+isa_ok($s,'HTTP::Server::Simple::Mason');
+is($s->port(),8080,'Defaults to 8080');
+is($s->port(13432),13432,'Can change port');
+is($s->port(),13432,'Change persists');
+ok($s->can('print_banner'), 'can print_banner()');
+ok($s->can('run'), 'can run()');

Added: HTTP-Server-Simple-Mason/t/01live.t
==============================================================================
--- (empty file)
+++ HTTP-Server-Simple-Mason/t/01live.t	Tue Jan 11 16:17:28 2005
@@ -0,0 +1,38 @@
+use Test::More;
+BEGIN {
+    if (eval { require LWP::Simple }) {
+	plan tests => 5;
+    } else {
+	Test::More->import(skip_all =>"LWP::Simple not installed: $@");
+    }
+}
+
+use_ok( HTTP::Server::Simple::Mason);
+
+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');
+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');
+
+
+
+
+package MyApp::Server;
+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/' );
+}
+
+1;

Added: HTTP-Server-Simple-Mason/t/02pod.t
==============================================================================
--- (empty file)
+++ HTTP-Server-Simple-Mason/t/02pod.t	Tue Jan 11 16:17:28 2005
@@ -0,0 +1,9 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More;
+
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+all_pod_files_ok();
+

Added: HTTP-Server-Simple-Mason/t/03podcoverage.t
==============================================================================
--- (empty file)
+++ HTTP-Server-Simple-Mason/t/03podcoverage.t	Tue Jan 11 16:17:28 2005
@@ -0,0 +1,9 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More;
+
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" ;#if $@;
+all_pod_coverage_ok({  also_private => [ qr/^[A-Z_]+$/ ], });
+


More information about the Rt-commit mailing list