Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Cannot call my installed module

by 7stud (Deacon)
on Feb 24, 2013 at 04:18 UTC ( #1020371=note: print w/replies, xml ) Need Help??

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
    Thanks all. This is good. Sherman

      Doing the following as suggested worked

       use lib '/home/sherman/module_test/share/perl/5.14.2';

       use testdir::moduletest;

      thank you all. I was banging my head and I kept re-reading and it didn't make sense at the time.


        thank you all. I was banging my head and I kept re-reading and it didn't make sense at the time.

        :) Been there, done that, took a break to practice :)

        When I'm stuck and a regular break doesn't help, an exercise break helps

        I start a new directory and walk-through something like Simple Module Tutorial, typing it myself instead of copy/paste

        Instead of commenting/uncommenting lines, I save each to a different file (

        The benefits 1) it stick in my memory (like muscle memory) 2) I have short example (in my style) available for copy/review at anytime

        Eventually I back this up in version control

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020371]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2018-06-18 00:46 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (107 votes). Check out past polls.