Randal L. Schwartz <merlyn@stonehenge.com> wrote:
Another way would be to put all your slots into one big "per hit" slot,
and then ensure that this is cleared out:
sub My::App::app_enter {
my $self = shift;
$self->reflect->addSlot(per_hit => {});
}
I like this approach quite a bit.
After reading your message, though, I got a bit greedy and decided I
wanted to be able to add slots rather than just hash entries to per_hit,
so I could do cool things like autoload fields and coderefs that you don't
have to know are coderefs.
Then I got a bit lazy and decided I did not want to edit all my templates
to change things like "[% self.user %]" to "[% self.per_hit.user %]".
So I decided to extend your idea a bit to the following:
sub My::App::app_enter{
my $self = shift;
my $per_hit = Class::Prototyped->new;
$self->reflect->addSlots( 'per_hit*' => $per_hit,
per_hit => $per_hit );
}
I went through my classes and changed most every ->reflect->addSlots
to ->per_hit->reflect->addSlots, and things seem to be working fine. At
least, nothing has blown up yet ;->
I double-checked to make sure the 'per_hit*' parent classes were not
accumulating on top of one another, one for each hit. As I
suspected, writing a parent slot with the same name as
a previously-established parent slot seems to overwrite it.
One problem with this approach is that almost every slot I create seems to
be per_hit. I'm starting to think it would be smarter to create a
'persist*'/'persist' slot in the manner above, then in control_leave
iterate over
the slots and delete each one except 'persist'. This may be time consuming,
however.
RT
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
cgi-prototype-users mailing list
cgi-prototype-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cgi-prototype-users