Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Modulino trick for cgi scripts

by skazat (Hermit)
on Sep 21, 2008 at 01:43 UTC ( #712794=perlquestion: print w/replies, xml ) Need Help??
skazat has asked for the wisdom of the Perl Monks concerning the following question:


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


(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, "". 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, "" in the working directory, and not, "something.cgi"


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, "", 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 (Pope) 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 "" than in the cgi-bin directory "ln -s /path/to/ ./something.cgi"

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://712794]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2017-10-22 07:36 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (272 votes). Check out past polls.