[Catalyst-commits] r13143 - in trunk/Catalyst-Controller-WrapCGI: .
lib/Catalyst/Controller t t/lib t/lib/TestCGIBinChainRoot
t/lib/TestCGIBinChainRoot/Controller t/lib/TestCGIBinChainRoot/root
t/lib/TestCGIBinChainRoot/root/cgi
t/lib/TestCGIBinChainRoot/root/cgi/path
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Wed Apr 7 16:26:24 GMT 2010
Author: caelum
Date: 2010-04-07 17:26:24 +0100 (Wed, 07 Apr 2010)
New Revision: 13143
Added:
trunk/Catalyst-Controller-WrapCGI/t/cgibin_chain_root.t
trunk/Catalyst-Controller-WrapCGI/t/cgibin_root_path.t
trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot.pm
trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/
trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/Controller/
trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/Controller/CGIHandler.pm
trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/root/
trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/root/cgi/
trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/root/cgi/path/
trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/root/cgi/path/test.pl
Removed:
trunk/Catalyst-Controller-WrapCGI/t/cgibin_root.t
Modified:
trunk/Catalyst-Controller-WrapCGI/Changes
trunk/Catalyst-Controller-WrapCGI/Makefile.PL
trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm
Log:
added cgi_chain_root
Modified: trunk/Catalyst-Controller-WrapCGI/Changes
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/Changes 2010-04-07 13:04:27 UTC (rev 13142)
+++ trunk/Catalyst-Controller-WrapCGI/Changes 2010-04-07 16:26:24 UTC (rev 13143)
@@ -1,5 +1,7 @@
Revision history for Catalyst-Controller-WrapCGI
+ - added cgi_chain_root option for CGIBin
+
0.027 2010-02-19 04:34:50
- fix tests for Perl < 5.8.9
- fix for HTTP::Request::AsCGI 1.2
Modified: trunk/Catalyst-Controller-WrapCGI/Makefile.PL
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/Makefile.PL 2010-04-07 13:04:27 UTC (rev 13142)
+++ trunk/Catalyst-Controller-WrapCGI/Makefile.PL 2010-04-07 16:26:24 UTC (rev 13143)
@@ -4,6 +4,9 @@
all_from 'lib/Catalyst/Controller/WrapCGI.pm';
author 'Matt S. Trout <mst at shadowcat.co.uk>';
+test_requires 'Catalyst::Plugin::Static::Simple';
+test_requires 'CGI';
+
requires 'Catalyst' => '5.80015';
requires 'HTTP::Request::AsCGI' => '1.2';
requires 'CGI::Compile' => '0.07';
@@ -17,9 +20,6 @@
requires 'LWP';
requires 'Moose';
-test_requires 'Catalyst::Plugin::Static::Simple';
-test_requires 'CGI';
-
build_requires 'Test::More' => '0.92';
auto_provides;
Modified: trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm 2010-04-07 13:04:27 UTC (rev 13142)
+++ trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm 2010-04-07 16:26:24 UTC (rev 13143)
@@ -41,8 +41,9 @@
In your .conf:
<Controller::Foo>
- cgi_root_path cgi-bin
- cgi_dir cgi-bin
+ cgi_root_path cgi-bin
+ cgi_dir cgi-bin
+ cgi_chain_root /optional/private/path/to/Chained/root
<CGI>
username_field username # used for REMOTE_USER env var
pass_env PERL5LIB
@@ -69,6 +70,19 @@
The global URI path prefix for CGIs, defaults to C<cgi-bin>.
+=head2 cgi_chain_root
+
+By default L<Path|Catalyst::DispatchType::Path> actions are created for CGIs,
+but if you specify this option, the actions will be created as
+L<Chained|Catalyst::DispatchType::Chained> end-points, chaining off the
+specified private path.
+
+If this option is used, the L</cgi_root_path> option is ignored. The root path
+will be determined by your chain.
+
+The L<PathPart|Catalyst::DispatchType::Chained/PathPart> of the action will be
+the path to the CGI file.
+
=head2 cgi_dir
Path from which to read CGI files. Can be relative to C<$MYAPP_HOME/root> or
@@ -76,8 +90,9 @@
=cut
-has cgi_root_path => (is => 'ro', isa => 'Str', default => 'cgi-bin');
-has cgi_dir => (is => 'ro', isa => 'Str', default => 'cgi-bin');
+has cgi_root_path => (is => 'ro', isa => 'Str', default => 'cgi-bin');
+has cgi_chain_root => (is => 'ro', isa => 'Str');
+has cgi_dir => (is => 'ro', isa => 'Str', default => 'cgi-bin');
sub register_actions {
my ($self, $app) = @_;
@@ -98,10 +113,17 @@
my $path = join '/' => splitdir($cgi_path);
my $action_name = $self->cgi_action($path);
- my $public_path = $self->cgi_path($path);
my $reverse = $namespace ? "$namespace/$action_name" : $action_name;
- my $attrs = { Path => [ $public_path ] };
+ my $attrs = do {
+ if (my $chain_root = $self->cgi_chain_root) {
+ { Chained => [ $chain_root ], PathPart => [ $path ], Args => [] };
+ }
+ else {
+ { Path => [ $self->cgi_path($path) ] };
+ }
+ };
+
my ($cgi, $type);
if ($self->is_perl_cgi($file)) { # syntax check passed
Added: trunk/Catalyst-Controller-WrapCGI/t/cgibin_chain_root.t
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/cgibin_chain_root.t (rev 0)
+++ trunk/Catalyst-Controller-WrapCGI/t/cgibin_chain_root.t 2010-04-07 16:26:24 UTC (rev 13143)
@@ -0,0 +1,21 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin '$Bin';
+use lib "$Bin/lib";
+
+use Test::More tests => 1;
+
+use Catalyst::Test 'TestCGIBinChainRoot';
+use HTTP::Request::Common;
+
+# Test configurable path root and dir, and Chained root
+
+my $response = request POST '/cgi/path/test.pl', [
+ foo => 'bar',
+ bar => 'baz',
+];
+
+is($response->content, 'foo:bar bar:baz from_chain:from_chain', 'POST to Perl CGI File');
Deleted: trunk/Catalyst-Controller-WrapCGI/t/cgibin_root.t
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/cgibin_root.t 2010-04-07 13:04:27 UTC (rev 13142)
+++ trunk/Catalyst-Controller-WrapCGI/t/cgibin_root.t 2010-04-07 16:26:24 UTC (rev 13143)
@@ -1,21 +0,0 @@
-#!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 configurable path root and dir
-
-my $response = request POST '/cgi/path/test.pl', [
- foo => 'bar',
- bar => 'baz'
-];
-
-is($response->content, 'foo:bar bar:baz', 'POST to Perl CGI File');
Copied: trunk/Catalyst-Controller-WrapCGI/t/cgibin_root_path.t (from rev 12935, trunk/Catalyst-Controller-WrapCGI/t/cgibin_root.t)
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/cgibin_root_path.t (rev 0)
+++ trunk/Catalyst-Controller-WrapCGI/t/cgibin_root_path.t 2010-04-07 16:26:24 UTC (rev 13143)
@@ -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 configurable path root and dir
+
+my $response = request POST '/cgi/path/test.pl', [
+ foo => 'bar',
+ bar => 'baz'
+];
+
+is($response->content, 'foo:bar bar:baz', 'POST to Perl CGI File');
Added: trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/Controller/CGIHandler.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/Controller/CGIHandler.pm (rev 0)
+++ trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/Controller/CGIHandler.pm 2010-04-07 16:26:24 UTC (rev 13143)
@@ -0,0 +1,11 @@
+package TestCGIBinChainRoot::Controller::CGIHandler;
+
+use parent 'Catalyst::Controller::CGIBin';
+
+sub chain_root : Chained('/') PathPart('cgi') CaptureArgs(0) {
+ my ($self, $c) = @_;
+
+ $c->req->body_parameters->{from_chain} = 'from_chain';
+}
+
+1;
Added: trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/root/cgi/path/test.pl
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/root/cgi/path/test.pl (rev 0)
+++ trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/root/cgi/path/test.pl 2010-04-07 16:26:24 UTC (rev 13143)
@@ -0,0 +1,12 @@
+#!/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')
+ ,' from_chain:',param('from_chain');
Property changes on: trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot/root/cgi/path/test.pl
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot.pm (rev 0)
+++ trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBinChainRoot.pm 2010-04-07 16:26:24 UTC (rev 13143)
@@ -0,0 +1,15 @@
+package TestCGIBinChainRoot;
+
+use Catalyst::Runtime '5.70';
+use parent 'Catalyst';
+
+__PACKAGE__->config({
+ Controller::CGIHandler => {
+ cgi_chain_root => '/cgihandler/chain_root',
+ cgi_dir => 'cgi',
+ }
+});
+
+__PACKAGE__->setup(qw/Static::Simple/);
+
+1;
More information about the Catalyst-commits
mailing list