[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] CAP Application Design suggestion



Giannis Economou wrote:
> Hi...
> 
> I came up with the a specific design about an application I'm writing
> using CGI::Application. Here is an example:
> 
> MyBaseApp    is-a         CGI:App
> MyApp            is-a         MyBaseApp

You don't need an intermediar MyApp. Just have MyBaseApp and have Cars
and Airplanes inherity from that.

> Cars                is-a          MyApp
> Airplanes         is-a          MyApp
> 
> Both Cars and Airplanes implement a runmode named: 'registration'
> 
> I want to be able to call the right 'registration' runmode, according to
> one query param (for example, 'type') that user requests. Example the
> "http://www.example.com/app.pl?rm=registration&type=car"; to be handled
> by the Cars 'registration' runmode.
> 
> I thought to do that in app.pl script (the instantiation script):
> 1. Use plain CGI to check for the 'type' query parameter
> 2. Do a simple dispatch like:
>   my $app = undef;
>   $app = Cars->new() if $type eq "car";
>   $app = Planes->new() if $type eq "planes";
>   $app->run();
> 
> I'm wondering if they are better ways to do the above (maybe inside a
> CAP, without using the plain CGI for checking the 'type' param).
> Any suggestions or ideas (always for a persistent environment like
> mod_perl) are welcome...

Use CGI::Application::Dispatch (use the 2.0 version which is still
labled 'development' but which I've been using in production just fine)
so that your URLs can look something like (under normal CGI)

  /app.pl/car/registration
  /app.pl/airplane/registration

This kind of mapping is so common in CGI::Application::Dispatch that you
wouldn't even need your own custom dispatch table to deal with it.


-- 
Michael Peters
Developer
Plus Three, LP


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.