The idea is to refactor the portions of your code that can be shared by A.cgi and B.cgi. Consider the following:
For this example, sometimes we want to decorate our data one way for one kind of client and another way for another kind of client. Rather than use one file for producing/publishing the data to be displayed as well as decorating that for a Unix command line AND a CGI "web page" ... why not refactor into one module that any number of formatters can consume?my $data = 'pretend this is a complex data structure'; my $is_web_browser = 1; if ($is_web_browser) { print qq(<span color="red">$data</span>\n); } else { print qq(\e[0;31m$data\e[0m\n); }
file: SomeModule.pm
package SomeModule; use strict; use warnings; sub get_data { return 'pretend this is a complex data structure'; } 1;
file: app.cgi
use strict; use warnings; use SomeModule; my $data = SomeModule::get_data(); print qq(<span color="red">$data</span>\n);
file: app.pl
use strict; use warnings; use SomeModule; my $data = SomeModule::get_data(); print qq(\e[0;31m$data\e[0m\n);
This is a very simple and distilled example, but hopefully you see how different apps can reuse the same modules without actually executing each other as a script.
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: cgi page calling another cgi when submitting form but does not returns error only to web server log and not to browser.
by chidori (Novice) on Jul 01, 2014 at 17:03 UTC | |