0

How can I start a mod_perl handler (called MyCacheHandler.pm) directly from another perl module (called MyModule.pm). Because currently I'm starting the handler via a web browser, but it would be a little bit easier to call it with MyModule.

atticus3000
  • 409
  • 1
  • 4
  • 12

2 Answers2

0

As I understand it, you want to have it (MyCacheHandler) running in the background, and it won't produce any visible (to a browser) output? (Just side effects).

If that's correct, why is it even implemented as a mod_perl handler. Just implement it as a script and run it from cron, or as a daemon of some kind.

You could still control MyCacheHandler from MyModule (say via IPC).

David-SkyMesh
  • 5,041
  • 1
  • 31
  • 38
  • Well, I can't use MyCacheHandler as cron, because I only need it if MyModule was used. So the user starts MyModule I need MyCacheHandler, so I want to call something like PerlModules::MyChacheHandler::handler() in MyModule. Will it work? – atticus3000 Aug 08 '13 at 08:38
  • It depends what `MyCacheHandler` *does*. In your previous question you had it set three different cache values, sleeping between calls to `set`. If you call that function from inside your `MyModule` handler, then it will 'block' the rest of the code in `MyModule` from running. You need some way to run it in the background. – David-SkyMesh Aug 08 '13 at 08:41
  • Ok. I understand the problem. So is it possible to use Apache2::SubProcess to start a new sub process which start the MyCacheHandler? – atticus3000 Aug 08 '13 at 08:46
  • I've personally never used `Apache2::SubProcess` but it looks like it would work. Give it a go, and if you have trouble, edit your question to get some assistance. – David-SkyMesh Aug 08 '13 at 08:51
0

Do some refactoring. Split MyCacheHandler.pm into two modules: one which is doing the hard work and does not depend on mod_perl anymore (that is, no more handling with $r), so it's callable from other modules. The other would be a now thin mod_perl handler calling the first module.

Or leave it as is, and just use LWP::UserAgent to access MyCacheHandler from MyModule.

Slaven Rezic
  • 4,571
  • 14
  • 12
  • He doesn't mention it in the post, but @atticus3000 wants the code in `MyCacheHandler` to run asynchronously with respect to `MyModule`. No amount of refactoring will fix this. – David-SkyMesh Aug 10 '13 at 10:15