Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Modulino trick for cgi scripts

by skazat (Chaplain)
on Sep 21, 2008 at 01:43 UTC ( [id://712794]=perlquestion: print w/replies, xml ) Need Help??

skazat has asked for the wisdom of the Perl Monks concerning the following question:

Heya,

I'm trying to use the awesome Modulino trick for a CGI script of mine. The Modulino trick :

* http://www.ddj.com/184416165
* http://www.perlmonks.org/index.pl?node_id=396759

(Thanks to the powers that be that got TPJ stuff online - it's quite a nerdy treat and thanks to brian d foy for writing both those up!)

It seems like a good idea, as CGI scripts have a tendency to grow a little too bigger than they should and start looking somewhat like modules, but there may be reasons you don't want to break them up into them.

The problem is, I can't get it to work, without renaming the script from, "something.cgi" to, "something.pm". Currently, my testing server is setup to run ".pm" file ending files in the cgi-bin as a cgi script, so it doesn't seem like that big of a problem, but is there any way to keep the filename as is (something.cgi), for now?

For example, if I try to call my cgi script named, "something.cgi" as a module, via the command line, I'll get something like this:

prompt$ perl -e 'use lib qw(./); use something; something->run()'

It'll fail.

Obviously, perl is looking for, "something.pm" in the working directory, and not, "something.cgi"

Trying,

prompt$ perl -e 'use lib qw(./); use "something.cgi"; something->run() +'

Won't do what's expected - and it's probably illegal to have a module name with a, "." in it.

Although it would be really really cool to subclass this script in another script, it's not necessarily my goal.

My goal is to get some TAP tests for subroutines living in the CGI script for my own internal testing.

I may just leave the Modulino scaffolding in the script and, just before I run the tests, rename the cgi script from, "something.cgi" to, "something.pm", require() in the script and run tests on the subroutines directly. This seems like a way better plan that attempt to capture the output of... STDOUT? from the script by passing arguments.

Replies are listed 'Best First'.
Re: Modulino trick for cgi scripts
by ikegami (Patriarch) on Sep 21, 2008 at 02:46 UTC
    perl -e'use lib qw( . ); do "something.cgi"; something->run()'

    But in this case, the following will do:

    perl -I. something.cgi

    Update: Added missing something->run().

      That did it!

Re: Modulino trick for cgi scripts
by karavelov (Monk) on Sep 21, 2008 at 23:04 UTC

    If your scripts live on some kind of UNIX-like system you could use symbolic links. Write your CGI in "something.pm" than in the cgi-bin directory "ln -s /path/to/something.pm ./something.cgi"

    I am using similar approach with CGI::Application scripts I am writing in order not to write separate instance scripts

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (9)
As of 2024-04-23 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found