On Wed, 26 Mar 2003 08:05:06 -0800 (PST), Arkady Grudzinsky <[EMAIL PROTECTED]> spoke
gently:
> Hi, everyone.
>
> Assuming my application consists of several independent
> "sub-applications", is it possible to initialize and run CGI::App objects
> for these sub-applications from within the MainCGIApp.pm or do I have
> to create independent applications and link them including 'redirect'
> statement in the MainCGIApp.pm? If I run another
> object inside one of the methods, the output, of course, is doubled.
>
> What is the best way to deal with this?
>
> Thanks.
>
> Arkady.
I encountered a similar dilemma. I wanted to create 'sub-applications',
or 'modules' of a larger application framework. This as you know is
easily solved by subclassing C::A, putting system-wide methods into your
subclass, and then building sub-app modules that inherit from it. You're
already doing this, if I'm not mistaken.
However, I also didn't like all the nearly empty initialization CGIs
sitting around, and having to link around between them. I do, in some
cases, use a single-file approach to C::A apps:
package MyCGIApp;
use base CGI::Application;
# some code...
# ...
# at the end...
package main;
my $app = new MyCGIApp;
$app->run();
But for this system, I wanted wanted just one URL to access the system,
regardless of what component/module the user needed.
My solution involves one index.cgi that knows what 'modules' there are
in the system, and loads one depending on a CGI parameter that is passed
around. In this simplified example, I have a directory structure...
./MyApp.pm (master package, inherits C::A)
./index.cgi (loader)
(sub-app packages, each is a 'standard' C::A, inheriting from MyApp.pm:)
./MyApp/Main.pm
./MyApp/Jobs.pm
./MyApp/Parts.pm
./MyApp/Reports.pm
And index.cgi looks something like this:
#!/usr/bin/perl
use CGI;
my $q = new CGI;
# $modules contains the list of params that are accepted for 'mod'
my $modules = {
main => 'Main',
job => 'Jobs',
part => 'Parts',
report => 'Reports',
};
# Get the needed module, if any
my $mod = $q->param('mod');
# Sanity check and set default
unless ($modules->{$mod}) {
$mod = 'main';
}
# Load the module
require "MyApp/$modules->{$mod}.pm";
# Make/run an app object
my $app = "MyApp::$modules->{$mod}"->new($q);
$app->run();
__END__
I think it works rather nicely.
-Sebastian
What draws us into the desert is the search for something intimate in the remote. -Ed
Abbey
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]