views:

340

answers:

3

Is it possible to auto-discover parameters to shell/Perl scripts in order to "meta" program WEB UIs for them?


I have a bunch of "legacy" scripts that I'd like to "web wrap". So far I have created a CGI-BIN web app with about 3 parameters that can call a bash/Perl reporting script.

But it now occurs to me maybe there is quicker or automatic way to wrap these 100s of scripts.

So basically I'd like to find out about techniques for metaprogramming where I'd discover what input parameters a particular bash or Perl script takes and then generate corresponding HTML FORM elements with those input parameters as TEXT INPUT or SELECT dropt down boxes etc.

Any ideas or links to examples?

A: 

Aside from Catalyst, CGI has a standard way to send in parameters via GET or POST, and CGI.pm makes it easy.


You've added the requirement "I'd like to find out about techniques for metaprogramming where I'd discover what input parameters a particular bash or perl script takes and then generate corresponding HTML FORM elements with those input parameters as TEXT INPUT or SELECT drop down boxes etc."

There isn't a standard way to "discover what input parameters a particular bash or perl script takes" because there isn't a standard way for these scripts to report this information. There are close-to-standard possibilities (parsing the troff source of the corresponding man page, calling the script with "--help" and parsing the output), or you could keep this information in a database of some sort.

There is a standard way to determine which parameters were sent to a CGI script, and then display those parameters as settable form elements. CGI.pm will bring them in as a hash, which you can loop through (displaying the key as the label for your text box and the value as the text in the corresponding text box).

Max Lybbert
"calling the script with "--help" " Scripts don't have man pages, but some do have help, so this looks like a fruitful approach to explore in addition to advice below as well(getopts etc). thanks
Ville M
Good point. Most scripts don't have much documentation of any kind.
Max Lybbert
+3  A: 

There isn't a way to look at random Perl source code to determine what arguments it takes, what those arguments mean, or how they are constrained.

If the Perl scripts you deal with all use a common library to process arguments, such as GetOpt::Long, then you could use the information the script passes to the argument processor to get most of the information.

Other than that, you're out of luck.

brian d foy
Very good idea, some of the scripts in fact do use GetOpt::Long so will definitely explore this approach. The ones that don't I will try the table approach by Len.
Ville M
A: 

To expand on what brian said, if you can provide us a few code samples, we can maybe help a little more. If the scripts use the same (or similar) methods for parsing their parameters, then we have a chance to write some code.

It may well be that you can write a meta-programming solution for the portion of your legacy scripts that are "regular", and write a table-based solution for the "irregular" ones.

Len Jaffe