develooper Front page | perl.perl6.language | Postings from June 2005

Musing on registerable event handlers for some specific events

Thread Next
From:
Adam Kennedy
Date:
June 8, 2005 11:40
Subject:
Musing on registerable event handlers for some specific events
Message ID:
20050608055816.11590.qmail@lists.develooper.com
With my occasionally-stated preference for keeping the Perl 6 core 
slimmer than it already is, I feel a little silly about suggesting new 
features for P6, but I'd like to stimulate debate on one that I'd like 
to see.

Last year I was having some issues with a large web application that 
needed to run as both a CGI and mod_perl application.

In particular, I wanted an effect where modules that I didn't need for 
every call weren't loaded unless "appropriate".

Now for CGI that means run-time loading. We have a number of these, from 
AutoLoader to (my) Class::Autouse module.

In mod_perl or other forking scenarios these same modules should be 
preloaded BEFORE the fork, so that they only use memory once, not many 
times.

Although Class::Autouse already magically supported mod_perl and 
preloaded, it was obvious that this was the wrong approach. There needed 
to be a way to preload for ALL forking scenarios without duplicating 
logic all over the place.

As a result, I ended up creating prefork.pm to allow different modules 
to register callbacks that would be triggered just before forking, so 
that various run-time loading hooks could all be triggered and loaded 
automatically before the fork.

This has worked for me quite well, but is a voluntary situation in which 
any forking module has to trigger the prefork logic manually.

What I'd like to see for Perl 6 (and I'm not sure if this exists 
already), is some sort of minimal event manager.

The number of events I'm talking about would be extremely low, pre and 
post fork being one. I'm not sure about others, but again I'm imagining 
only events that matter process-wide.

I'd like to see the Perl 6 fork() command issue event triggers to some 
officially blessed event manager module. Any number of other modules 
could register callbacks for whichever events they liked.

The other alternative is to have the event manager overwrite the core 
fork() function... and I dislike this sort of hackery as these tricks 
generally only work if one person does it.

If it can be done in less than 10 lines lines of code, to get the most 
minimal hooks into the core, I'd like to see it done.

Thoughts?

Adam K

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About