From: Rafael Kitover Date: Fri, 4 Dec 2009 21:10:55 +0000 (+0000) Subject: allow MyApp->foo methods in CGIs, release X-Git-Tag: 0.030~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-WrapCGI.git;a=commitdiff_plain;h=e889d52612ce3eaa1fb64150f76543aa03cc6253;hp=2e6f9c85d869a3fd48134c5990ed654ad272fd12 allow MyApp->foo methods in CGIs, release --- diff --git a/Changes b/Changes index 3cb467e..f136330 100644 --- 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 diff --git a/Makefile.PL b/Makefile.PL index d0146e8..9993ef9 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -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 '; -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 --- 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 diff --git a/lib/Catalyst/Controller/CGIBin.pm b/lib/Catalyst/Controller/CGIBin.pm index 48eaae0..e332ef4 100644 --- a/lib/Catalyst/Controller/CGIBin.pm +++ b/lib/Catalyst/Controller/CGIBin.pm @@ -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. 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 diff --git a/lib/Catalyst/Controller/WrapCGI.pm b/lib/Catalyst/Controller/WrapCGI.pm index a9446db..a51afea 100644 --- a/lib/Catalyst/Controller/WrapCGI.pm +++ b/lib/Catalyst/Controller/WrapCGI.pm @@ -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 diff --git a/lib/CatalystX/GlobalContext.pm b/lib/CatalystX/GlobalContext.pm index 9a061ea..792a746 100644 --- a/lib/CatalystX/GlobalContext.pm +++ b/lib/CatalystX/GlobalContext.pm @@ -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