# This allows you to capture all inputs that a CGI script runs with, within a webserver, # and allows you to "replay" the captured info, so that you can run your CGI script # from the command-line. # # To use this, temporarily put this at the very top of your script: # BEGIN {$^C or do "/home/yourself/src/pl/capture_CGI_inputs.pm"} # and then run your script via the web. use strict; use warnings; use Cwd; use Data::Dumper; sub capture_CGI_inputs { my ($filename) = @_; local $Data::Dumper::Terse = 1; my %substitute = ( ENV_CONTENTS => Dumper(\%ENV), CURDIR => Cwd::getcwd(), STDIN => Dumper(do {local $/=undef; }), ); my $out = <<'EOF'; %ENV = %{ <> }; chdir("<>"); if (!open STDIN, '-|') { print STDOUT <>; exit; } EOF $out =~ s/<<(\w+)>>/$substitute{$1}/eg; open CAPTURED, ">$filename" or die $!; print CAPTURED $out; print "Content-type: text/html\n\ncapture_CGI_inputs() has run, and has generated a file. Include this at the top of your CGI script, and it should run happily from the command line.
    BEGIN{\$^C or do \"$filename\"}
\n"; exit; } capture_CGI_inputs("/tmp/cgi_inputs." . time()); 1;