fixes for Win32
Rafael Kitover [Sun, 22 May 2011 09:16:16 +0000 (05:16 -0400)]
Changes
Makefile.PL
lib/Catalyst/Controller/CGIBin.pm
t/lib/TestCGIBin/root/cgi-bin/sigs.pl

diff --git a/Changes b/Changes
index a993876..ee33b2a 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for Catalyst-Controller-WrapCGI
 
+    - now works on Win32
+
 0.031  2011-05-20 23:28:23
     - fix CGIBin.pm bug hardcoding 'root' as the site root
 
index 241cbeb..76cc7aa 100644 (file)
@@ -19,6 +19,8 @@ requires 'Task::Weaken';
 requires 'LWP';
 requires 'Moose';
 
+requires 'Class::Unload' if $^O eq 'MSWin32';
+
 test_requires 'Test::More' => '0.92';
 test_requires 'Catalyst::Plugin::Static::Simple';
 test_requires 'CGI';
index 8edab57..f9a42dc 100644 (file)
@@ -186,7 +186,7 @@ sub register_actions {
     $self->next::method($app, @_);
 
 # Tell Static::Simple to ignore cgi_dir
-    if ($cgi_bin =~ /^@{[ $app->path_to('root') ]}/) {
+    if ($cgi_bin =~ /^\Q@{[ $app->path_to('root') ]}\E/) {
         my $rel = File::Spec->abs2rel($cgi_bin, $app->path_to('root'));
 
         if (!any { $_ eq $rel }
@@ -250,6 +250,15 @@ L</wrap_perl_cgi>.
 sub is_perl_cgi {
     my ($self, $cgi) = @_;
 
+    if ($^O eq 'MSWin32') {
+        # the fork code fails on Win32
+        eval { $self->wrap_perl_cgi($cgi, '__DUMMY__') };
+        my $success = $@ ? 0 : 1;
+        require Class::Unload;
+        Class::Unload->unload($self->cgi_package('__DUMMY__'));
+        return $success;
+    }
+
     my (undef, $tempfile) = tempfile;
 
     my $pid = fork;
@@ -298,8 +307,22 @@ C<exit()>.
 sub wrap_perl_cgi {
     my ($self, $cgi, $action_name) = @_;
 
-    return CGI::Compile->compile($cgi,
-        "Catalyst::Controller::CGIBin::_CGIs_::$action_name");
+    return CGI::Compile->compile($cgi, $self->cgi_package($action_name));
+}
+
+=head2 cgi_package
+
+C<< $self->cgi_package($action_name) >>
+
+Returns the package name a Perl CGI is compiled into for a given
+C<$action_name>.
+
+=cut
+
+sub cgi_package {
+    my ($self, $action_name) = @_;
+
+    return "Catalyst::Controller::CGIBin::_CGIs_::$action_name";
 }
 
 =head2 wrap_nonperl_cgi
index d7e89c1..b1a98fc 100755 (executable)
@@ -5,8 +5,8 @@ use warnings;
 
 use CGI ':standard';
 
-BEGIN { $SIG{USR1} = 'IGNORE'; }
+BEGIN { $SIG{INT} = 'IGNORE'; }
 
-$SIG{USR1} = 'IGNORE';
+$SIG{INT} = 'IGNORE';
 
 print header;