punkish has asked for the wisdom of the Perl Monks concerning the following question:
Forgive me in advance for flogging a moribund equine, but as long as there are us n00bs (and may there be many, because that means new users of an old language are still emerging), we will continue to want light shed on old darkness. I have read the following --
To my relief, I have discovered that I already have been doing much of what CGI-App preaches --I have a "run mode" param -- I typically call it "do" or "action". I also use a "target," as in "do" something to "target". This is based on my premise that all imperative sentences require at least a verb ("do") and an object ("target").
I have a "dispatch table" which maps a run mode to a sub-routine.
I separate the code from the display by using my much-loved HTML-Template.
Herein lies the problem -- CGI-App does the same things as above, and yet, I find my method cumbersome. The reason is -- I really, really want to break up my code into "one file for one run mode" because I find it very difficult to work with one, very large file -- be it a single index.cgi, or a CGI-App style Perl module.
Why don't I want to use CGI-App? Many reasons --
- I don't understand how it works
- I have tried a hundred times to understand OO programming, and I still don't get it
- I don't want to use yet another external module -- frankly, I don't even want to use CGI because I don't like using any of CGI.pm's methods for creating html. I already know html, and besides, I am using HTML-Template. External modules add countless lines of code to my script, and besides, I want my script to be completely portable and as simple as possible.
- Seems like most of what I am already doing is what CGI-App does. And I don't like the fact that all my code gets lumped into one single file
I would like to create a mix between what dragonchild calls "clannish" and "socialist" (see Re: Re: Why CGI::Application?). One directory per functional area, and within that, one script per run mode.
What I can't figure out is how to migrate all the common stuff to one-single external file. For example, some CGI params are common to all the scripts, so I would like to grab them all in just one place. However, most scripts will have CGI params specific to just themselves. Of course, I would like those to remain within the respective scripts. Similarly, some H-T params are common to all display screens, and I would like those to be set in one place, and then have the scripts add to the table of template params as and where needed. This is the portion I can't figure out. In other words, how to set some of the CGI and H-T params in one file, and then just use them or add to them in another file.
So, to summarize , I would like --
- one directory for one functional area. If the entire website has only one functional area, well, then it will have only one directory.
- one script for one run mode. Each script could be titled $do_$target.cgi (show_record.cgi, or verify_user.cgi, etc.)
- using as few external modules as possible -- the very minimum would be DBI and HTML-Template. I might create a simple session mechanism using Storable. I do like CGI-Session, but I really don't want to use CGI.pm (unless necessary) just because I use it for nothing more than grabbing the params -- it just seems so excessive
- one common script to do the common stuff -- grab the common cgi params, determine which template to use, set the common template params, etc.
I don't know how to proceed. I guess, it would be really helpful to see actual applications that work similarly to above (if there are any) and learn from them.
Much appreciation awaits all advice.