[Catalyst-commits] r9861 - in trunk/Catalyst-Controller-WrapCGI: lib/Catalyst/Controller t t/lib/TestCGIBin/Controller t/lib/TestCGIBin/root/cgi-bin/path

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Sun Apr 26 19:48:24 GMT 2009


Author: caelum
Date: 2009-04-26 20:48:24 +0100 (Sun, 26 Apr 2009)
New Revision: 9861

Added:
   trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin/root/cgi-bin/path/testdata.pl
Modified:
   trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm
   trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm
   trunk/Catalyst-Controller-WrapCGI/t/cgibin.t
   trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin/Controller/CGIHandler.pm
Log:
C::C::CGIBin - added test for __DATA__ (failing for some reaosn)

Modified: trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm	2009-04-26 14:22:28 UTC (rev 9860)
+++ trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm	2009-04-26 19:48:24 UTC (rev 9861)
@@ -24,11 +24,11 @@
 
 =head1 VERSION
 
-Version 0.006
+Version 0.007
 
 =cut
 
-our $VERSION = '0.006';
+our $VERSION = '0.007';
 
 =head1 SYNOPSIS
 
@@ -64,12 +64,6 @@
 
 CGI paths are converted into action names using cgi_action (below.)
 
-A path such as C<root/cgi-bin/hlagh/bar.cgi> will get the private path
-C<foo/CGI_hlagh_bar_cgi>, for controller Foo, with the C</>s converted to C<_>s
-and prepended with C<CGI_>, as well as all non-word characters converted to
-C<_>s. This is because L<Catalyst> action names can't have non-word characters
-in them.
-
 Inherits from L<Catalyst::Controller::WrapCGI>, see the documentation for that
 module for configuration information.
 
@@ -141,12 +135,21 @@
 the action name it is registered as. See L</DESCRIPTION> for a discussion on how
 CGI actions are named.
 
+A path such as C<root/cgi-bin/hlagh/bar.cgi> will get the private path
+C<foo/CGI_hlagh__bar_cgi>, for controller Foo, with the C</>s converted to C<__>
+and prepended with C<CGI_>, as well as all non-word characters converted to
+C<_>s. This is because L<Catalyst> action names can't have non-word characters
+in them.
+
+This means that C<foo/bar.cgi> and C<foo__bar.cgi> for example will both map to
+the action C<CGI_foo__bar_cgi> so B<DON'T DO THAT>.
+
 =cut
 
 sub cgi_action {
     my ($self, $cgi) = @_;
 
-    my $action_name = 'CGI_' . join '_' => split '/' => $cgi;
+    my $action_name = 'CGI_' . join '__' => split '/' => $cgi;
     $action_name    =~ s/\W/_/g;
 
     $action_name
@@ -200,12 +203,15 @@
 Takes the path to a Perl CGI and returns a coderef suitable for passing to
 cgi_to_response (from L<Catalyst::Controller::WrapCGI>.)
 
-C<$action_name> is the generated name for the action representing the CGI file.
+C<$action_name> is the generated name for the action representing the CGI file
+from C<cgi_action>.
 
 This is similar to how L<ModPerl::Registry> works, but will only work for
 well-written CGIs. Otherwise, you may have to override this method to do
 something more involved (see L<ModPerl::PerlRun>.)
 
+Scripts with C<__DATA__> sections now work too.
+
 =cut
 
 sub wrap_perl_cgi {
@@ -213,7 +219,7 @@
 
     my $code = slurp $cgi;
 
-    $code =~ s/^__DATA__\r?\n(.*)//ms;
+    $code =~ s/^__DATA__(?:\r?\n|\r\n?)(.*)//ms;
     my $data = $1;
 
     my $coderef = do {

Modified: trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm	2009-04-26 14:22:28 UTC (rev 9860)
+++ trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm	2009-04-26 19:48:24 UTC (rev 9861)
@@ -15,11 +15,11 @@
 
 =head1 VERSION
 
-Version 0.0028
+Version 0.0029
 
 =cut
 
-our $VERSION = '0.0028';
+our $VERSION = '0.0029';
 
 =head1 SYNOPSIS
 

Modified: trunk/Catalyst-Controller-WrapCGI/t/cgibin.t
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/cgibin.t	2009-04-26 14:22:28 UTC (rev 9860)
+++ trunk/Catalyst-Controller-WrapCGI/t/cgibin.t	2009-04-26 19:48:24 UTC (rev 9861)
@@ -6,7 +6,7 @@
 use FindBin '$Bin';
 use lib "$Bin/lib";
 
-use Test::More tests => 6;
+use Test::More tests => 7;
 
 use Catalyst::Test 'TestCGIBin';
 use HTTP::Request::Common;
@@ -50,6 +50,10 @@
 is($response->content, 'foo:bar bar:baz',
     'POST to Perl CGI File through a forward via cgi_action');
 
+$response = request '/cgi-bin/path/testdata.pl';
+is($response->content, "testing\n",
+    'scripts with __DATA__ sections work');
+
 SKIP: {
     skip "Can't run shell scripts on non-*nix", 1
         if $^O eq 'MSWin32' || $^O eq 'VMS';

Modified: trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin/Controller/CGIHandler.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin/Controller/CGIHandler.pm	2009-04-26 14:22:28 UTC (rev 9860)
+++ trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin/Controller/CGIHandler.pm	2009-04-26 19:48:24 UTC (rev 9861)
@@ -10,7 +10,7 @@
 # try out a forward
 sub dongs : Local Args(0) {
     my ($self, $c) = @_;
-    $c->forward('/cgihandler/CGI_path_test_pl');
+    $c->forward('/cgihandler/CGI_path__test_pl');
 }
 
 # try resolved forward

Added: trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin/root/cgi-bin/path/testdata.pl
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin/root/cgi-bin/path/testdata.pl	                        (rev 0)
+++ trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin/root/cgi-bin/path/testdata.pl	2009-04-26 19:48:24 UTC (rev 9861)
@@ -0,0 +1,12 @@
+#!/usr/bin/perl 
+
+use strict;
+use warnings;
+
+use CGI ':standard';
+
+print header;
+print do { local $/; <DATA> };
+
+__DATA__
+testing


Property changes on: trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin/root/cgi-bin/path/testdata.pl
___________________________________________________________________
Name: svn:executable
   + *




More information about the Catalyst-commits mailing list