Stas Bekman wrote:
Geoffrey Young wrote:


I would want at least a real-time interface for this, something similar to

$filter->init(sub {shift->update_mtime($package_mtime)} );



where would you run this code?


outsite of a handler() subroutine, pretty much like I showed it - on module load. I suspect you'd have to register the init handler that way for a few reasons, namely that you'd miss the first request if you waited until after default_handler runs to register your init filter. it's also good to do it outside of handler() to handle stuff like reloads, where the init routine might use a closure to avoid recalculating the package mtime on each request.

The problem is that currently the resolving (read: module compiling and handler resolving) is postponed till the first invocation of the handler unless the module was manually preloaded or PerlOptions +Autoload was set.
I suppose that this could be a documented thing. e.g.:

if you use filter_init, you must preload the module at the server startup.
that sounds reasonable.  preloading is always a good idea anyway.


I'm not sure what that means for actually getting at the filter object outside of a request :)

I don't think that's how it'll work. I was thinking of having a subroutine with a special attribute. So after the module has been compiled we can walk through all the CODE entries and check whether any of them is having the FilterInitHandler attribute and take it from there. Does this sound good?
you mean something like

sub my_update_mtime : filter_init {};

?

I guess that's ok. it really depends on how the other interfaces work. I like the streaming filter API, and wouldn't want to deviate too far from that model to get this to work. and $filter->init (or whatever) is a bit more like the other calls.

but you're in a better position to judge how this should/needs to work. besides, once the hooks are there, we can probably make it look however we want.


I read the thread at the URL you've provided. The latest comment from Dec says that the bug is still there. So I suppose that the feature was added but not really used so far. I could be wrong.

I'll try to look into this a bit more next week.

Cool. Thanks Geoff!
:)

--Geoff

Reply via email to