Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Wise siblings,

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.


In reply to Yet another "why CGI-Application" question by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-19 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found