YASRQ (yet another style related question)

I am in the process of cleaning up some crud I wrote -- taking a large web-app script and breaking it up into modules, one for each "component" (or 'run-mode') of the app. I have the following layout --

use CGI related modules; use HTML::Template; use DBI; use Myapp::Authenticate qw(authenticate); use Myapp::View qw(view); use Myapp::Update qw(update); # # you get the picture

There are many ways I can schlep the variables around.

# 1. create objects in the main script and pass them around my $cgi = new CGI::Simple; # unpack $cgi minimally to determine what to do my $action = $cgi->param('action'); my $dbh = DBI->connect(dbi stuff); my $template = HTML::Template->new(logic to determine template); # dispatch if ($action eq 'view') { view($cgi, $dbh, $template); } elsif ($action eq 'save') { save($cgi, $dbh, $template); } yadda yadda # then unpack the objects in the respective modules as needed #-------------------------------------- # 2. don't schlep the objects, but refer to them via fully # qualified names as needed # # create objects as above. unpack $cgi minimally to determine action # dispatch if ($action eq 'view') { view(); } elsif ($action eq 'save') { save(); } yadda yadda # then, in my modules package Myapp::View; sub view { my $target = $main::cgi->param('target'); my $this = $main::cgi->param('this'); my $that = $main::cgi->param('that'); my $sth = $main::dbh->prepare(...); $sth->execute; $main::template->param(RESULTS => $sth->fetchall_arrayref({}),); } #-------------------------------------- # 3. another variation # besides any mix of the above, don't import/export anything. # Refer to everything using their long names.

Since Perl gives me so many ways to hang myself, are there any caveats with any of the above, with respect to platforms, operating systems, long-term code maintenance, best-practices, etc.?

Or, am I just agonizing needlessly and should just jump in and do what I fancy today.

Is it just 6 of one and sqrt(36) of another?

--

when small people start casting long shadows, it is time to go to bed

In reply to Passing variables between packages by punkish

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.