Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Heh. I was the one that suggested you use a tied hash. You need to be careful about one point: "exporting" is not the same as "exposing an interface". In Perl has, "export" has a precise meaning (to introduce symbol table entries into the caller's main package), whereas an interface style is strictly a design decision. The two are related, but not the same thing. Let me elaborate. Say you choose to present a function-oriented interface. You can choose to export the functions (using the standard Exporter module as your example code is doing). That means when I use the module, I get those sub symbols entered in my main package, potentially clashing with my own variable names or those from other packages. I can keep the function oriented interface but not export any names by using an object-oriented interface. So, for example, instead of this: I could have this: The difference between the first and second versions (as far as exported symbols is concerned) is that in the first example I have no control over clashing names like hostname and system_version, whereas in the second, name clashes aren't possible (well, except for the module name itself...) You notice that $sys, my handle to the package, is a lexical now. The same consideration applies to an interface exposed through variables, in this case a hash. I can choose to export the hash from my code, polluting my caller's namespace, or I can allow the caller to choose names by tying. Here's the first way: And here's the second: Again, the difference is that the first module introduced the %sysinfo_hash into the caller's namespace, but the second module introduced no new symbols. Nonetheless, both are exposing a variable-oriented interface. HTH In reply to Re: should a module export FUNCTIONS or VARIABLES?
by VSarkiss
|
|