[tpm] use from a local directory
Uri Guttman
uri at StemSystems.com
Tue Mar 22 11:38:49 PDT 2011
>>>>> "FH" == Fulko Hew <fulko.hew at gmail.com> writes:
FH> But now I have a situation where the generated modules have 'use
FH> constant' in them and I need to have the callers be able to use
FH> those constants easily.
FH> At the moment they need to do $x = Module1::CONSTANT_1(); in order
FH> for it to work. Something more natural would be $x =
FH> Module1::CONSTANT_1; ie. without the parens.
FH> To do that I need to use export/import (right?)
Module1::CONSTANT_1() is fully qualified name so it doesn't need
importing.
if you import something, you only see the last part of the name
(CONSTANT_1) in your current symbol table. you seem to have cross over
those two concepts.
FH> And the only way to do that is something like 'use module qw/CONSTANT_1/;
no, you could have them exported by default so you wouldn't need the
qw// part.
FH> But then I'm using USE, not REQUIRE, and then the modules need to
FH> be installed in a standard directory... and the problem then
FH> mushrooms.
use and require do the same searching in the same dirs. the only
differences are that require is run time vs compile time for use and use
will call the import method on the loaded class. you can't import with
require.
FH> Then I find out about 'use lib', but it only knows about
FH> explicitly defined directories. And 'use lib' isn't any different
FH> than didling the @INC variable anyway. And there doesn't seem to
FH> be an easy way of didling either to get it to include the
FH> 'invoked' directory (only the current-working-dirctory).
the dirs have nothing do to with this. it is the compile time vs runtime
and importing that matters.
what is wrong with having the users do a use line? make all your
constants export by default (in @EXPORT) and you have a simple
interface.
uri
--
Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
More information about the toronto-pm
mailing list