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

Re: [cgiapp] Re: ANNOUNCE: CGI::Application::Plugin::TT 0.06 ( auto filename implementation ).


On Sun, 6 Feb 2005 17:55:12 +0000 (UTC), Mark Stosberg
<suppressed> wrote:
> On 2005-02-03, Cees Hek <suppressed> wrote:
> >
> > - automatic template filename generation -- the tt_process method can
> > automatically generate a template filename based on the runmode that
> > called it (eg calling $self->tt_process($tt_vars) from runmode
> > 'my_runmode' in module 'My::App' would automatically load a template
> > with a filename of My/App/my_runmode.tmpl).  See docs for more info.
> 
> Interesting idea. This could be useful to support in load_tmpl() as
> well, as a way to provide more structure to how templates are named.
> 
> I have a question about the implementation. I was wondering why
> 'current_run_mode()' was not used to figure out the run mode. I saw
> drawbacks to both solutions.
> 
> With the current implementation, it won't work  if you try to use it
> from a function called by a run mode, instead of calling it directly
> from a run mode.
> 
> That could prehaps be improved if you walk up the caller stack until you
> you find a method that is mentioned in the run_modes() hash. If nothing
> is found, it's probably the anonymous subroutine case.
> 
> Hmm, I wonder what this code does now with run modes that are anonymous
> subs. :)
> 
> Using current_run_mode() would mean you won't have to worry about nested
> sub routine calls, but I don't think it would work right when one
> run mode calls another one.

I guess the implementation is the direct result of how I have used
this in my own applications.  You bring up some good points though,
and I hadn't considered the anonymous sub case (since I don't usually
use them as runmodes).

My reason for not using the current_run_mode() function is that I
don't think it is well suited to the task right now.  Mainly that is
because there is no ability for it to know about runmode swapping (ie
calling one runmode but returning the results of another).  Perhaps
there should be a way to switch runmodes that keeps current_run_mode()
accurate.  It would be quite simple to implement...

Also, basing the name on the function that called tt_process seems a
little bit more consistent.  When you call tt_process you can always
know what the template name will be, wheras if it is based on some
other conditions it can be unclear what template will be used, and it
may change from one request to the next.

However, I have left in the ability to override the template filename
generation function by passing in your own function.

My::App->tt_config(
  TEMPLATE_NAME_GENERATOR => sub { $_[0]->current_run_mode().'.tmpl' },
);

That should name the template based on the current runmode as defined
by CGI::Application.

Cheers,

--
Cees Hek

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