punkish has asked for the wisdom of the Perl Monks concerning the following question:
In the begining, I had one long index.cgi. Then I read a Simple Module Tutorial and got the following --
## index.cgi use strict; use CGI::Simple; use HTML::Template; use MyPackage; # The following are imported from the .conf file below use vars qw( $WIKI_TITLE $CGIURL $DB $TEMPLATE_PATH $TEMPLATE_URL $DEFAULT_TARGET $DEFAULT_ACTION $DEBUGGING $PAGENAME_PATTERN $EMAIL_PATTERN $CGIPATH ); # A set_message handler allows creation of a nice looking, # custom error page. This is based on the example # provided in CGI::Carp docs BEGIN { require 'home.conf'; sub handleErrors { my ($err) = @_; my $t = HTML::Template->new( filename => "$TEMPLATE_PATH/error.tmpl", ); $err =~ s/$CGIPATH //g; $t->param( CGIURL => $CGIURL, TEMPLATE_URL => $TEMPLATE_URL, WIKI_TITLE => $WIKI_TITLE, PAGENAME => 'Error', ERROR => $err, ); print $t->output; } set_message(\&handleErrors); } yadda yadda # grab the cgi vars my $cgi_action = $cgi->param('action'); yadda yadda ## dispatch table follows # Dispatch logic SWITCH: { ($cgi_action eq 'edit') && do { edit($cgi_target, $cgi_searchterm); last SWITCH; }; ($cgi_action eq 'find') && do { find($cgi_target, $cgi_searchterm); last SWITCH; }; yadda yadda # default action view($cgi_target, $cgi_searchterm); }
Now I want to move code for each "run mode" (to borrow CGI::Application's terminology, into its own separate Package like below --
## index.cgi use strict; use CGI::Simple; use HTML::Template; use MyPackage; ## and then, in MyPackage use MyPackage::View; use MyPackage::Edit; use MyPackage::Find; yadda yadda
Things that trip me up are --
To many of the wise monks here, this SoPW entry might seem beginner stuff. But for me, it is the land of the unknown. I guess I am looking for a "Intermediate|Advanced Module(s) Tutorial."
Update: 465945 seems to hit tangentially on what I am asking above, but not quite.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Packaging up my code sensibly
by biosysadmin (Deacon) on Jun 12, 2005 at 16:11 UTC | |
by punkish (Priest) on Jun 12, 2005 at 16:23 UTC | |
by wazoox (Prior) on Jun 13, 2005 at 10:19 UTC | |
|
Re: Packaging up my code sensibly
by tlm (Prior) on Jun 12, 2005 at 19:53 UTC | |
by punkish (Priest) on Jun 12, 2005 at 20:43 UTC | |
by tlm (Prior) on Jun 13, 2005 at 13:22 UTC |