From: Ryan T. <li...@ry...> - 2005-06-25 18:50:30
|
Hello, I recently moved a simple CGI::Prototype-based Web app over to a mod_perl2 installation. It wasn't too hard. One thing I eventually noticed: if you dispatch to objects representing particular classes, as CGI::Prototype::Hidden does (see name_to_page and its call to $package->reflect->object), you have to be careful to re-initialize slots as needed, because package objects are not garbage collected and thus will persist. To handle initialization, for each class with slots I want killed before the next request, I do a control_leave with $self->reflect->deleteSlots(qw(userfoo userbar tempfoo tempbar)), along with $self->SUPER::control_leave(@_) for any classes above. If you fail to re-initialize your slots, they persist to the next hit, which is a feature if you know what you're doing and a bug otherwise. I have not yet found it useful to persist any slots. I am curious if name_to_page was made with an eye toward mod_perl -- was it foreseen that in a persistent environment one might need to initialize slots? I'm wondering if a better approach might be to make my own name_to_page that does $package->new, thus not requiring any initialization, but costing more (probably) in obj creation and requiring extra work to keep track of shortname (essentially page_to_name to remember what state name/package was used to gen the object). I have not yet found any slots I wish to persist so I end up having to remember to write an initializer for each slot I create. Cheers RT PS Liked the first Linux Mag article. |