Quoth matt.t.gr...@gmail.com (Matt Grimm):
> What is the conventional wisdom (if any) for handling conditional
> dependencies in modules?
> 
> For example, I have a logger class wrapped around Log4perl that
> supports screen, email, and syslog appenders, and each appender can be
> individually toggled on or off. Is it better to force the dependencies
> on the underlying syslog and email modules at the top of the logger
> class, or is it acceptable to bury those imports in the methods that
> actually do the initialization of each appender? It sort of comes down
> to whether I want the issue detected at compile time or run time I
> suppose, but is generally frowned upon to put imports down inside
> class methods?

If (and only if) you have a sane way to recover if the modules in
question aren't loaded, I would rather load them as late as possible.
This especially applies if they won't necessarily be needed every time
your module is used.

You may also want to look at the prefork module on CPAN.

Ben

Reply via email to