debiandude has asked for the wisdom of the Perl Monks concerning the following question:
Hello Everyone:
I have recently been updating my CGI::Application program and it has grown enormous (for me at least), coming in at just shy of 3000 lines. Since it is just one file it is becoming a PITA to maintain. I am using around 20 perl modules (a lot of them are CGI::App::Plugins) and have a lot of various run modes.
I would like to break up the script into several parts so that I am not loading a lot of unnecssary modules and reading all those functions each time a webpage is loaded. However, I have not written a program this large that I need to break it up before. What my idea would be to have a main file with all the various run modes. Then in the run mode function it would load the modules that contains all that functionality (via require?). In pseudo code I want to do this:
package MyCGIApp; use base 'CGI::Application'; use CGI::Application::Plugin::AutoRunmode; sub setup { ... load database ... ... load session ... ... other setup stuff... } sub runmode1 : Runmode { my $html_output = ''; $html_output .= $q->start_html(-title=>'petnuch.com', -style=>{-src=>'/css/layout.css'}); $html_output .= $self->banner; $html_output .= $self->menu; require 'MyCGIApp::Runmode1'; # do_runmode1 is defined in MyCGIApp::Runmode1 $html_output .= $self->do_runmode1; $html_ouput .= $self->footer; return $html_output; } /* Common functions to every web page */ sub banner { ... } sub menu { ... } sub footer { ... } 1;
But what do I need to put in Runmode1.pm? Specifically what do need to do with ISA. Is it a CGI::Application or a MyCGIApp. Do I need to export do_runmode1? Do I need to have a 'use CGI::Application::Plugin::Session' in each runmode modules, or will it automatically be loaded? This is what I have in pseudocode (that does not work):
package MyCGIApp::Runmode1; use strict; use Runmode1specficmodules; sub do_runmode1 { my $self = shift; my $session = $self->session; my $q = $self->query(); my $id = $q->param('n'); unless( somecondition ) return $self->error; ...do stuff... return $html_output; } sub error { ...runmode1 error stuff... } 1;
All help will be greatly appreciated!
|
|---|