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
-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';
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
use List::MoreUtils 'any';
use IO::File ();
use Carp;
+use File::Temp 'tempfile';
use namespace::clean -except => 'meta';
=head1 VERSION
-Version 0.020
+Version 0.021
=cut
-our $VERSION = '0.020';
+our $VERSION = '0.021';
=head1 SYNOPSIS
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