in reply to Cannot call my installed module
# Why is Exporter white while other use # statements are colored
I don't know, but I can confirm that the same thing happens in macvim with the vividchalk color scheme:
use strict; #strict is same color as use, which is orange use warnings; #same as previous use 5.012; #5.012 is blue use vars; #vars is orange use Benchmark qw(:all); #Benchmark is white use List::BinarySearch; #A module I installed is white
Experimenting with different modules, it appears that lower case builtin modules appear in orange, while any upper case module name is white.
Note that @INC contains the list of directories that perl will search for modules--that you use. There are lots of modules in those directories, but perl will only load them into your program, if you use them. If you look at the use docs, the statement 'use Module' is equivalent to:
BEGIN { require Module; Module->import( LIST ); }
What does that mean? Well require() does this:
...require demands that a library file be included if it hasn't already been included. The file is included via the do-FILE mechanism, which is essentially just a variety of eval...
Which means that perl searches the directories in @INC for the specified Module, and if found perl then evals the text file converting it into code. After the require, perl calls a subroutine named import() that is defined in Module. Typically, the import() method creates aliases in the caller (i.e your perl program) for the subroutines defined in the Module--which allows your program to call the subroutines. The following lines in your program take care of the aliasing for you:
@ISA = qw(Exporter); @EXPORT = qw(testsub); @EXPORT_OK = qw($string);
If you are worried about the subroutine names in the Module clashing with names in your perl program, you can write:
use Module ();
And thereafter, you can refer to the subroutines by their fully qualified names, e.g. Dir::Module::subroutine_name
But perl cannot see the subroutines defined in a text file just because the text file resides in a directory in @INC. You have to convert the text file to code with use/require. Your 'use lib' just adds a directory to @INC.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Cannot call my installed module
by ShermW0829 (Sexton) on Feb 24, 2013 at 17:44 UTC | |
by ShermW0829 (Sexton) on Feb 24, 2013 at 21:23 UTC | |
by Anonymous Monk on Feb 24, 2013 at 22:21 UTC |