You can use the following as a webserver to test your scripts locally (don't use other than for that). I didn't write it (I forget where it came from, but I've used it to test scripts, and it seems to work well.)
use HTTP::Daemon; use IPC::Open2; $|=1; my $server=HTTP::Daemon->new(LocalPort=>80,LocalAddr=>'localhost'); print "Please contact me at <URL:", $server->url, ">\n"; while($client=$server->accept){ while(my $answer=$client->get_request){ $ans=$answer->as_string; @ans=split /\n/,$ans; $client->autoflush; if($answer->method eq 'GET'){ $path=$answer->url->path; (error,last) unless $path=~s#^/##; if($path=~/html$/i){ $client->send_file_response($path); last; } if($path=~/cgi$/i){ $ENV{REQUEST_METHOD}=$answer->method; $query=$answer->url->query; $ENV{CONTENT_LENGTH}=length($query); $ENV{QUERY_STRING}=$query; $out=`perl $path`; $out=~s/.*?\n\n//s; #remove HTTP header print $client $out; last; } } if($answer->method eq 'POST'){ $path=$answer->url->path; (error,last) unless $path=~s#^/##; if($path=~/cgi$/i){ $query=$answer->url->query; $ENV{REQUEST_METHOD}=$answer->method; for(@ans){ $ENV{CONTENT_LENGTH}=$1 if /Content-Length: (\d+)/; $ENV{HTTP_REFERRER}=$1 if /Referer: (.*)/; } $query=$ans[-1]; undef $CGI;undef $OUT; $pid=open2($CGI,$OUT,"perl","$path") or error; print $OUT $query; close $OUT; @out=<$CGI>; waitpid $pid,0; $out=join "\n",@out; $out=~s/.*?\n\n//s; #remove HTTP header print $client $out; last; } } last; } print "CLOSE: ", $client->reason, "\n" if $client->reason; undef $client; } sub error{ $client->error(RC_FORBIDDEN); print "An error occurred in $ans\n"; }

chas

In reply to Re: Testing ActivePerl scripts locally by chas
in thread Testing ActivePerl scripts locally by tomgracey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.