Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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:

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.

Comment on Modulino trick for cgi scripts
Select or Download Code
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 "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
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? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2014-09-23 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (219 votes), past polls