Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

no webserver(apache)? no problem! test .cgi with Plack/plackup

by Anonymous Monk
on Mar 14, 2011 at 14:01 UTC ( #893089=CUFP: print w/ replies, xml ) Need Help??

If you're developing for CGI/CGI::Simple (or testing snippets from perlmonks), this starts a webserver accessible through http://localhost/ and operates much like mod_cgi for apache (fork + execute)

long options

plackup --listen localhost:80 --loader Shotgun -MPlack::App::WrapCGI - +e " Plack::App::WrapCGI->new( script => q{test.cgi} ) "
same command using short options
plackup -l localhost:80 -L Shotgun -MPlack::App::WrapCGI -e " Plack::A +pp::WrapCGI->new( script => q{test.cgi} ) "
You develop test.cgi like normal, the only exception being that you either use my or our where appropriate ( see mod_perl: CGI to mod_perl Porting. mod_perl Coding guidelines. The First mystery)
See also
plackup
Plack::App::WrapCGI
Plack::Loader::Shotgun
http://plackperl.org/ PSGI/Plack - Perl Superglue for Web Frameworks and Web Servers
Plack Advent Calendar

Comment on no webserver(apache)? no problem! test .cgi with Plack/plackup
Select or Download Code
Re: no webserver(apache)? no problem! test .cgi with Plack/plackup
by Your Mother (Chancellor) on Apr 04, 2011 at 17:29 UTC

    ++ I'm commenting mostly just to bump this excellent piece of advice.

    Since port is rarely important and I like to use this idiom in addition to running a traditional webserver on port 80, I'd shorten it to use the default port 5000–

    plackup -L Shotgun -MPlack::App::WrapCGI -e "Plack::App::WrapCGI->new(script => shift)" [cgi]

    –which lends itself to an alias–

    alias pcgi='plackup -Ilib -L Shotgun -MPlack::App::WrapCGI -e "Plack:: +App::WrapCGI->new(script => shift)"'

    Update: anonymous monk that replied is quite correct. The code, as is, is broken.

    Update: And a million years later... alias works in bash, at least.

    alias pcgi='plackup -L Shotgun -MPlack::App::WrapCGI -e "Plack::App::W +rapCGI->new(script => \$ARGV[0])"' pcgi some.cgi HTTP::Server::PSGI: Accepting connections at http://0:5000/ ...
      FWIW, that doesn't work for me
      Magic number checking on storable string failed at blib\lib\Storable.p +m (autosplit into blib\lib\auto\Storable\thaw.al) line 421, at c:/per +l/site/5.12.2/lib/Plack/Loader/Shotgun.pm line 25
      $ pmvers Plack Storable Plack: 0.9976 Storable: 2.25
      It has to do with string-eval and @ARGV being emptied

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://893089]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2015-07-04 19:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls