Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Dancer + cgi

by slatibart (Acolyte)
on Mar 20, 2012 at 15:33 UTC ( #960595=perlquestion: print w/ replies, xml ) Need Help??
slatibart has asked for the wisdom of the Perl Monks concerning the following question:

This code should be the usual hello world example. Binds to its own port. But that doesn't work on a shared hosting machine. What do I need to change so that it uses Apaches CGI or plack ? I'm just overwhelmed by documentation and don't find an answer easily.
use Dancer;

use Plack::Server::CGI;

get '/' => sub {
      return 'Hello World!';
};

start;

Comment on Dancer + cgi
Re: Dancer + cgi
by Anonymous Monk on Mar 20, 2012 at 15:49 UTC
Re: Dancer + cgi
by druthb (Beadle) on Mar 20, 2012 at 16:18 UTC
    You shouldn't need the second use there. For fairly-simple Dancer apps, the cgi/fastcgi deployment method described in Dancer::Deployment works like a charm!
    D Ruth Bavousett
Re: Dancer + cgi
by druthb (Beadle) on Mar 20, 2012 at 16:21 UTC

    Wups! Forgot something!

    Instead of start;, you probably want to dance;. See Dancer::Cookbook.

    Good luck Dancing!
    D Ruth Bavousett
Re: Dancer + cgi
by slatibart (Acolyte) on Mar 20, 2012 at 17:56 UTC
    I did the minor fix. But still wants to bind to

    [Tue Mar 20 18:49:32 2012] [error] [client ..] bind to 0.0.0.0:3000: A +ddress already in use at
    So do I ultimately need to do change the apache config ? Which is a bit complicated on a shared host.
Re: Dancer + cgi
by onelesd (Pilgrim) on Mar 20, 2012 at 18:16 UTC

    Take a look at plackup - it's painless:

    plackup -E deployment -s Starman --workers=10 -p 80 -a bin/app.pl
      I don't get it. Dancer::Deployment says:

      In providing ultimate flexibility in terms of deployment, your Dancer app can be run as a simple cgi-script out-of-the-box. No additional web-server configuration needed. Your web server should recognize .cgi files and be able to serve Perl scripts.

      but
      use Dancer; get '/' => sub { return 'Hello World!'; }; dance;
      still binds to Port 3000.
      print "Content-type: text/html\n\n"; print "hello";

      but this perl script is working.

      Still clueless after reading a lot of documentation.

        In that same paragraph, Dancer::Deployment asserts that you have to have Plack::Runner installed. (Not, mind, that you have to use it) It *sounds* like it might not be, maybe. I've not had the problem you're describing, so I'm kinda feeling around here. And yeah, you'll need to at least set up a rewrite rule in .htaccess, even if you can't monkey with the server Apache config.

        The only time I've seen a Dancer script bind on its' own, is when you run it from the command line, so what you're describing seems very peculiar to me.

        D Ruth Bavousett

        When you run a Dancer app as a CGI, you don't run your script that has 'dance' in it. You use the httpd.conf or .htaccess rewrite rules in the first section of Dancer::Deployment, which redirects all URLs through the dispatch.cgi (or dispatch.fcgi for FastCGI) that is created when you create your Dancer app with the 'dancer' program. That dispatch program takes the URLs and passes them to your routes, after which point it works like it'd work as a standalone server or using any other deployment method.

        Aaron B.
        My Woefully Neglected Blog, where I occasionally mention Perl.

Re: Dancer + cgi
by dsheroh (Parson) on Mar 21, 2012 at 09:44 UTC
    I surprised that nobody has directly mentioned this yet,1 but the default code generated by dancer -a includes a dispatch.cgi in the public/ directory. Execute that like any other CGI script and you should be set.

    1 it's covered in Dancer::Deployment, but that adds a lot of additional boilerplate that isn't actually relevant to Just Making It Work

      You made my day. In the end it is as simple as it should be. Now the comment to Plack::Runner in Dancer::Deployment makes sense to me.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://960595]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-12-27 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls