Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

"Therefore, I am quite puzzled by your other suggested use for it. I don’t quite understand you on that point"

The use of plackup in a shebang line for CGI scripts is documented in Plack::Handler::CGI. If you're interested in how/why it works, read on.

plackup's normal behaviour is to run a server which listens on a TCP port, and handles multiple HTTP requests, and keeps going until it gets killed. You can observe this behaviour by running:

plackup -e'sub { [200,[],[q/ok/]] }'

It will print out a URL; you can paste that into your browser, and it will serve up a small text file containing the word "ok". And you can hit "reload" and it will do it again and again. Awesome. But, of course, not what you want from a CGI script! So how is plackup any good in a shebang line?

Hit Ctrl+C to kill plackup, and then set the following environment variables:

GATEWAY_INTERFACE=1 SERVER_NAME=localhost SERVER_PORT=8080 REQUEST_METHOD=GET SCRIPT_NAME=-e

Now run this again:

plackup -e'sub { [200,[],[q/ok/]] }'

And you'll see that instead of spawning an HTTP server and printing out its address for you, plackup now behaves like a CGI script, printing out the response headers and body to STDOUT.

plackup (or rather the guess sub defined in Plack::Loader) detects that it's running in a CGI environment and behaves appropriately.


In reply to Re^3: Change cgi script to PSGI app by tobyink
in thread Change cgi script to PSGI app by mohan2monks

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-29 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found