|Syntactic Confectionery Delight|
Flexibility in Module for Import or Executeby temporal (Pilgrim)
|on Mar 11, 2013 at 21:17 UTC||Need Help??|
temporal has asked for the
wisdom of the Perl Monks concerning the following question:
Hey again monks,
I run up against this design decision a lot and figured I'd better ask for some wisdom before continuing with what feels like a bit of an odd workaround.
This works fine. For a little I was mixed up between exit codes and module import return value. I need to explicitly return 1; in order to make sure that the module stops execution there for importers and returns truth. For some reason I was laboring under the misconception that use checks the exit code when in fact it only cares about the return value.
I am aware that implementing this sort of thing isn't entirely sane. Best practice dictates that I keep module and script functionality separate. But I end up with a lot of scripts that turn into modules because they have lots of useful code for other scripts. But I'd like to keep the ability to run these module-ified scripts standalone.
Anyway, relying on caller feels a little bit hacky. So I'm looking for opinions/advice/admonishment regarding a better way to distinguish between a module being executed directly versus being imported?