allow MyApp->foo methods in CGIs, release
Rafael Kitover [Fri, 4 Dec 2009 21:10:55 +0000 (21:10 +0000)]
Changes
Makefile.PL
README
lib/Catalyst/Controller/CGIBin.pm
lib/Catalyst/Controller/WrapCGI.pm
lib/CatalystX/GlobalContext.pm

diff --git a/Changes b/Changes
index 3cb467e..f136330 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Catalyst-Controller-WrapCGI
 
+0.021  2009-12-04 21:05:14
+    - better is_perl_cgi determination that also allows using MyApp->foo
+      methods
+
 0.020  2009-06-30 22:59:56
     - fix AUTHOR pod sections
 
index d0146e8..9993ef9 100644 (file)
@@ -1,10 +1,10 @@
-use inc::Module::Install 0.87;
+use inc::Module::Install 0.91;
 
 name     'Catalyst-Controller-WrapCGI';
 all_from 'lib/Catalyst/Controller/WrapCGI.pm';
 author   'Matt S. Trout <mst@shadowcat.co.uk>';
 
-requires 'Catalyst' => '5.80002';
+requires 'Catalyst' => '5.80015';
 requires 'HTTP::Request::AsCGI' => '0.8';;
 requires 'File::Find::Rule';
 requires 'List::MoreUtils';
diff --git a/README b/README
index b5d1a5f..36b7a5a 100644 (file)
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
 Catalyst-Controller-WrapCGI
 
-Some modules to help you port mod_perl/CGI code to Catalyst.
+Some modules to help you port CGI/mod_perl code to Catalyst.
 
 INSTALLATION
 
index 48eaae0..e332ef4 100644 (file)
@@ -14,6 +14,7 @@ use Symbol 'gensym';
 use List::MoreUtils 'any';
 use IO::File ();
 use Carp;
+use File::Temp 'tempfile';
  
 use namespace::clean -except => 'meta';
 
@@ -23,11 +24,11 @@ Catalyst::Controller::CGIBin - Serve CGIs from root/cgi-bin
 
 =head1 VERSION
 
-Version 0.020
+Version 0.021
 
 =cut
 
-our $VERSION = '0.020';
+our $VERSION = '0.021';
 
 =head1 SYNOPSIS
 
@@ -208,18 +209,28 @@ L</wrap_perl_cgi>.
 sub is_perl_cgi {
     my ($self, $cgi) = @_;
 
-    my $shebang = IO::File->new($cgi)->getline;
+    my (undef, $tempfile) = tempfile;
 
-    return 0 if $shebang !~ /perl/ && $cgi !~ /\.pl\z/;
+    my $pid = fork;
+    die "Cannot fork: $!" unless defined $pid;
 
-    my $taint_check = $shebang =~ /-T/ ?  '-T' : '';
+    if ($pid) {
+        waitpid $pid, 0;
+        my $errors = IO::File->new($tempfile)->getline;
+        unlink $tempfile;
+        return $errors ? 0 : 1;
+    }
 
+    # child
+    local *NULL;
     open NULL, '>', File::Spec->devnull;
-    my $pid = open3(gensym, '&>NULL', '&>NULL', "$^X $taint_check -c $cgi");
-    close NULL;
-    waitpid $pid, 0;
+    open STDOUT, '>&', \*NULL;
+    open STDERR, '>&', \*NULL;
+    close STDIN;
 
-    $? >> 8 == 0
+    do $cgi;
+    IO::File->new(">$tempfile")->print($@);
+    exit;
 }
 
 =head2 wrap_perl_cgi
index a9446db..a51afea 100644 (file)
@@ -20,11 +20,11 @@ Catalyst::Controller::WrapCGI - Run CGIs in Catalyst
 
 =head1 VERSION
 
-Version 0.020
+Version 0.021
 
 =cut
 
-our $VERSION = '0.020';
+our $VERSION = '0.021';
 
 =head1 SYNOPSIS
 
index 9a061ea..792a746 100644 (file)
@@ -15,11 +15,11 @@ CatalystX::GlobalContext - Export Catalyst Context
 
 =head1 VERSION
 
-Version 0.020
+Version 0.021
 
 =cut
 
-our $VERSION = '0.020';
+our $VERSION = '0.021';
 
 =head1 SYNOPSIS