rianne809 has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to import a module var
by Perl Mouse (Chaplain) on Nov 22, 2005 at 12:23 UTC | |
Perl --((8:>*
| [reply] [d/l] |
by rianne809 (Novice) on Nov 22, 2005 at 13:06 UTC | |
| [reply] [d/l] |
by Perl Mouse (Chaplain) on Nov 22, 2005 at 13:50 UTC | |
And next time, don't post a gazillion lines - you could have written a short example with the same problem.
Perl --((8:>*
| [reply] |
by Anonymous Monk on Nov 22, 2005 at 13:27 UTC | |
| [reply] [d/l] |
|
Re: how to import a module var
by tirwhan (Abbot) on Nov 22, 2005 at 12:26 UTC | |
Unless the variable is exported (in which case you can import it with use Module qw($variable)), this is probably a bad idea, because you're accessing a module internal which can change its behaviour at any given time, thereby breaking your code. The module has an interface for a reason, use it. If the module does not give you a specific bit of information that you need, write a patch and add a method. If the module author is not willing to accept your patch, that's a pretty good indicator that there's a better way of doing what you want. Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan | [reply] [d/l] |
by philcrow (Priest) on Nov 22, 2005 at 14:25 UTC | |
This is especially important when cross language programs come along. When Perl is tied to Java or Python, those other languages can't see the exports, they need methods to call. Perhaps the only valid use of exports in the OO context is for mixin modules which provide exported subs that lots of other classes can import into their packages. But those exporting mixin providers don't have constructors. Which leaves me back at my rule of thumb: constructors and Exporter don't mix. This is not to say that clever OO modules might not have a magical import that does all sorts of mischief (like fabricating whole classes). But they shouldn't actually put anything into the caller's name space like Exporter does. Phil | [reply] |
by Perl Mouse (Chaplain) on Nov 22, 2005 at 14:36 UTC | |
than The former requires less tokens. ;-) And I'll export constants from my OO modules if I feel like it.
Perl --((8:>*
| [reply] [d/l] [select] |