[Maypole] Re: Maypole responding to requests very slowly (or, how to get just one associated record instead of getting the world)

David Baird dave@riverside-cms.co.uk
Fri, 03 Dec 2004 16:08:25 +0000


Simon Flack wrote:
> Peter Speltz wrote:
>> I was thinking in the view::base where "IT" is created of doing 
>> something like
>> this:
>>
>>     . . .
>>     cgi => $r->template_args{classmetadata_cgi} || { $class->to_cgi }
>>     . . .
>>
>> Then the model's sub can make them if it wants or set it to "1" to get 
>> none or
>> do nothing and get them.
> 
> 
> That looks good. But I'm not sure that it should be controlled by a 
> template parameter. I was going to suggest something in $r->config, but 
> that doesn't smell quite right either.
> 
> Perhaps it's something that you define on a class-by-class basis. Or 
> perhaps you want different behaviour for different actions in a model?
> 
> I'd be tempted to change it to:
> 
>      cgi => sub { $class->to_cgi() },
> or
>      cgi => sub { $class->to_field(@_) },
> 
> That should work quite nicely for M::V::TT - there's no overhead unless 
> you actually use it in the template. I imagine you'd need a different 
> solution for Mason though.

Mason templates are just Perl, so you would say

     $classmetadata->{cgi}->()

instead of

     $classmetadata->{cgi}

Out of interest, how does the call look in TT - is it the same for both 
cases?

Maybe the whole classmetadata thing should be an object?

d.