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

Re: [cgiapp] Q: CGI::Application::Dispatch V 2.00_03



Ron Savage wrote:
> Hi Michael
> 
> I'm beginning to understand this neat module, and have a couple of comments:
> 
> (1)
> Line 330:
>     $app->mode_param(sub { return $rm }) if( $rm );
> 
> What happens in my apps when I already have sub setup containing:
> 
> 	$self -> mode_param(\&setup_mode);
> 
> <predicted_answer>
> Patient: Doctor! Doctor! It hurts when I do this!!
> Doctor: Don't do that...
> </predicted_answer>

Exactly. Unfortunately, C::A doesn't have a way to set the run mode to a
specific one. It has ways to specify how C::A should find the run mode, but not
to just set it. So by passing in a closure, I can tell C::A which mode is the
run mode (determined from parsing the PATH_INFO) for the duration of the request
(but just for that request; the next request could get a completely different
closure and rm).

> But seriously, folks.
> (2)
> I assume there are - in very simple terms - 2 ways to structure an app:
> 
> o One monolithic script
> 
> o One (Perl) module per run mode, with common code in a parent

I generally do neither. I have several modules with several run modes in each.
I'd wager that this is the more popular way to do it too.

> The latter obviously avoids loading code for run modes which are not being used,

Actually it doesn't. When you use or require your base class, it loads all of
the code in that base class regardless of whether or not you ever use those
methods. That's why there's AutoLoader or weird tricks like what CGI.pm does to
avoid loading stuff you don't use.

> but (for small apps especially) is there any other reason to structure things
> that way, apart from personal preference?

I'm not sure I understand why you see this as a problem. If you are using
Dispatch, then the run mode is being determined for you outside of your module,
so your module never has to think about how to get the run mode.

-- 
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.