From: Rafael Kitover Date: Sun, 26 Apr 2009 20:56:27 +0000 (+0000) Subject: C::C::CGIBin - new release X-Git-Tag: 0.030~45 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-WrapCGI.git;a=commitdiff_plain;h=9cd473644d9076cfc98c97e72731d5492e9ff7e2 C::C::CGIBin - new release --- diff --git a/Changes b/Changes index d402922..b05f4b8 100644 --- a/Changes +++ b/Changes @@ -1,33 +1,34 @@ Revision history for Catalyst-Controller-WrapCGI -0.001 2008-06-28 15:28:46 - First complete dist. +0.0029 2009-04-26 20:54:28 + - Allow more control over public paths to CGIBin actions. (confound) + - Override exit() in CGIBin-wrapped Perl cgis to avoid terminating the + Catalyst process. (confound) + - Set (temporarily) $0 to the filename of the Perl cgi being executed. + (confound) + - cgi_root_path accessor, convert to Moose (caelum) + - slight rewrite of docs and a test for __DATA__ (caelum) -0.002 2008-07-02 23:02:20 - First release. +0.0028 2009-04-24 04:40:39 + - Add support for __DATA__ sections in cgis for C::CGIBin (caelum) -0.0022 2008-07-04 02:52:52 - Fixed test shell script portability and missing dep on Class::C3 +0.0027 2009-04-03 14:55:34 + - Add 'kill_env' and default to killing 'MOD_PERL' from environment. + (confound) -0.0024 2008-11-19 16:00:54 - Fixed for Catalyst 5.8 +0.0026 2009-02-02 + - Stop storing generated files in SVN and add svn:ignore. + - Remove taint from tests as this breaks in a local::lib environment + as PERL5LIB is stripped. 0.0025 2009-01-09 14:59:20 - Tell Static::Simple to ignore root/cgi-bin for C::C::CGIBin + - Tell Static::Simple to ignore root/cgi-bin for C::C::CGIBin (caelum) -0.0026 2009-02-02 - Stop storing generated files in SVN and add svn:ignore. - Remove taint from tests as this breaks in a local::lib environment - as PERL5LIB is stripped. - -0.0027 2009-04-03 14:55:34 - Add 'kill_env' and default to killing 'MOD_PERL' from environment. +0.0024 2008-11-19 16:00:54 + - Fixed for Catalyst 5.8 (caelum) -0.0028 2009-04-24 04:40:39 - Add support for __DATA__ sections in cgis for C::CGIBin +0.002 2008-07-02 23:02:20 + - First release. -0.0029 - Allow more control over public paths to CGIBin actions. - Override exit() in CGIBin-wrapped Perl cgis to avoid terminating the - Catalyst process. - Set (temporarily) $0 to the filename of the Perl cgi being executed. +0.001 2008-06-28 15:28:46 + - First complete dist. diff --git a/Makefile.PL b/Makefile.PL index 2d8a215..869f036 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -15,7 +15,7 @@ requires 'List::MoreUtils'; requires 'File::Slurp'; requires 'namespace::clean'; -requires 'MRO::Compat'; +requires 'Moose'; if($] < 5.009_005) { requires 'Class::C3::XS' => '0.08'; diff --git a/lib/Catalyst/Controller/CGIBin.pm b/lib/Catalyst/Controller/CGIBin.pm index 773d52e..b31b0da 100644 --- a/lib/Catalyst/Controller/CGIBin.pm +++ b/lib/Catalyst/Controller/CGIBin.pm @@ -1,10 +1,10 @@ package Catalyst::Controller::CGIBin; -use strict; -use warnings; - -use MRO::Compat; +use Moose; use mro 'c3'; + +extends 'Catalyst::Controller::WrapCGI'; + use File::Slurp 'slurp'; use File::Find::Rule (); use Catalyst::Exception (); @@ -16,8 +16,6 @@ use IO::File (); use Carp; use namespace::clean -except => 'meta'; -use parent 'Catalyst::Controller::WrapCGI'; - =head1 NAME Catalyst::Controller::CGIBin - Serve CGIs from root/cgi-bin @@ -39,7 +37,7 @@ In your controller: use parent qw/Catalyst::Controller::CGIBin/; # example of a forward to /cgi-bin/hlagh/mtfnpy.cgi - sub dongs : Local Args(0) { + sub serve_cgi : Local Args(0) { my ($self, $c) = @_; $c->forward($self->cgi_action('hlagh/mtfnpy.cgi')); } @@ -47,6 +45,7 @@ In your controller: In your .conf: + cgi_root_path cgi-bin username_field username # used for REMOTE_USER env var pass_env PERL5LIB @@ -69,6 +68,8 @@ module for configuration information. =cut +has cgi_root_path => (is => 'ro', isa => 'Str', default => 'cgi-bin'); + sub register_actions { my ($self, $app) = @_; @@ -160,13 +161,17 @@ sub cgi_action { Takes a path to a CGI from C such as C and returns the public path it should be registered under. -The default is C. +The default is to prefix with the C config setting, or if not set +uses C. =cut sub cgi_path { my ($self, $cgi) = @_; - return "cgi-bin/$cgi"; + + my $root = $self->cgi_root_path; + $root =~ s{/*$}{}; + return "$root/$cgi"; } =head2 $self->is_perl_cgi($path) diff --git a/lib/Catalyst/Controller/WrapCGI.pm b/lib/Catalyst/Controller/WrapCGI.pm index 5a05241..e119f5b 100644 --- a/lib/Catalyst/Controller/WrapCGI.pm +++ b/lib/Catalyst/Controller/WrapCGI.pm @@ -1,8 +1,9 @@ package Catalyst::Controller::WrapCGI; -use strict; -use warnings; -use parent 'Catalyst::Controller'; +use Moose; +use mro 'c3'; + +extends 'Catalyst::Controller'; use HTTP::Request::AsCGI; use HTTP::Request; diff --git a/t/cgibin_root.t b/t/cgibin_root.t new file mode 100644 index 0000000..d112e28 --- /dev/null +++ b/t/cgibin_root.t @@ -0,0 +1,21 @@ +#!perl + +use strict; +use warnings; + +use FindBin '$Bin'; +use lib "$Bin/lib"; + +use Test::More tests => 1; + +use Catalyst::Test 'TestCGIBinRoot'; +use HTTP::Request::Common; + +# test default root of "cgi-bin" + +my $response = request POST '/cgi-bin/path/test.pl', [ + foo => 'bar', + bar => 'baz' +]; + +is($response->content, 'foo:bar bar:baz', 'POST to Perl CGI File'); diff --git a/t/lib/TestCGIBin/Controller/CGIHandler.pm b/t/lib/TestCGIBin/Controller/CGIHandler.pm index 3a7409f..3092f40 100644 --- a/t/lib/TestCGIBin/Controller/CGIHandler.pm +++ b/t/lib/TestCGIBin/Controller/CGIHandler.pm @@ -2,6 +2,13 @@ package TestCGIBin::Controller::CGIHandler; use parent 'Catalyst::Controller::CGIBin'; +# Turn off log for the non-zero exit test +sub auto : Private { + my ($self, $c) = @_; + $c->log->levels() unless $c->debug; + 1; +} + sub cgi_path { my ($self, $cgi) = @_; return "my-bin/$cgi"; diff --git a/t/lib/TestCGIBinRoot.pm b/t/lib/TestCGIBinRoot.pm new file mode 100644 index 0000000..cea069e --- /dev/null +++ b/t/lib/TestCGIBinRoot.pm @@ -0,0 +1,8 @@ +package TestCGIBinRoot; + +use Catalyst::Runtime '5.70'; +use parent 'Catalyst'; + +__PACKAGE__->setup(qw/Static::Simple/); + +1; diff --git a/t/lib/TestCGIBinRoot/Controller/CGIHandler.pm b/t/lib/TestCGIBinRoot/Controller/CGIHandler.pm new file mode 100644 index 0000000..0b86175 --- /dev/null +++ b/t/lib/TestCGIBinRoot/Controller/CGIHandler.pm @@ -0,0 +1,5 @@ +package TestCGIBinRoot::Controller::CGIHandler; + +use parent 'Catalyst::Controller::CGIBin'; + +1; diff --git a/t/lib/TestCGIBinRoot/root/cgi-bin/path/test.pl b/t/lib/TestCGIBinRoot/root/cgi-bin/path/test.pl new file mode 100755 index 0000000..0486369 --- /dev/null +++ b/t/lib/TestCGIBinRoot/root/cgi-bin/path/test.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use CGI ':standard'; + +die '$ENV{MOD_PERL} must not be set' if $ENV{MOD_PERL}; + +print header; +print 'foo:',param('foo'),' bar:',param('bar')