http://www.perlmonks.org?node_id=761655


in reply to How to write effective modules

Is a global in the $main:: namespace the right way to do it? No, it is not! Sometimes you'll build a set of modules that all assume a certain runtime environment, but even then that environment will be encapsulated behind method calls (or at least subroutine calls), so other modules don't need to know the internals.

Basic rule of thumb: it's fine for one module to depend on the public API of another module, but it's wrong to depend on the internal implementation of that API. And $main::db wouldn't be considered a good public API by most people.

Replies are listed 'Best First'.
Re^2: How to write effective modules
by salazar (Scribe) on May 04, 2009 at 15:00 UTC
    What is an example of, and how would you go about creating, a "good" public API?
      Template-Toolkit. The pieces depend on each other, but they all have good encapsulation.
        I'm sorry to say that I've never used Template Toolkit: I am still pretty new. (err.. should I be using it?)

        Could you clarify? That'd be much appreciated.