Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Perl module in a user local folder

by niqola (Novice)
on Jan 15, 2013 at 04:13 UTC ( #1013308=perlquestion: print w/ replies, xml ) Need Help??
niqola has asked for the wisdom of the Perl Monks concerning the following question:

Hi! I'm writting perl module using OOP. All my modules (UTest.pm and Service.pm) are in some_dir/Lib/ folder. My test script test.pl is in some_dir.
#file UTest.pm package UTest; use warnings; use strict; sub new { my $class = shift; my $self = { 'name' => '', 'condition' => '', 'args' => [], }; return bless $self, $class; } # other sub ... 1;
#file Service.pm package Service; use UTest; our @ISA = qw(UTest); sub new { my ($class) = shift; my $self = UTest->new(); $self->{'captures'} = {}; bless $self, $class; return $self; } #others sub... 1;
#file test.pl use Lib::Service; my $service = Service->new; #... other codes
I get following error when i run test.pl:
Can't locate UTest.pm in @INC (@INC contains: /etc/perl /usr/local/lib +/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/p +erl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl + .) at Lib/Service.pm line 2. BEGIN failed--compilation aborted at Lib/Service.pm line 2. Compilation failed in require at ./mytest.pl line 2. BEGIN failed--compilation aborted at ./mytest.pl line 2.
Can someone help me? Thanks.

Comment on Perl module in a user local folder
Select or Download Code
Re: Perl module in a user local folder
by Athanasius (Abbot) on Jan 15, 2013 at 04:32 UTC
      Thank you. That works fine!
Re: Perl module in a user local folder
by Anonymous Monk on Jan 15, 2013 at 04:40 UTC

    Or, you name your "service" module properly,
    by use Lib::Service.pm, then in your test perl script, you can call use Lib::Service
    Infact, your Utest module should also be called Lib::UTest.pm.
    Note that "::" is just like saying "Lib/UTest.pm" or "Lib/Service"
    Hope this helps.

      Thank you for your answer. But Perl compains about syntax error with use Lib::Service.pm Maybe, i misunderstood something?
Re: Perl module in a user local folder
by sundialsvc4 (Abbot) on Jan 15, 2013 at 15:55 UTC

    Here or elsewhere, read up about this thing called @INC.   This is the list of places that Perl looks.   Other good search keys are PERL5LIB.   Entering perl -V on the command line (with an upper-case “V”) is also very informative.

    Also, very specifically, perldoc perlfaq8 where you will find a section specifically named, How do I add a directory to my include path (@INC) at runtime?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1013308]
Approved by Athanasius
Front-paged by 2teez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2015-07-02 23:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (47 votes), past polls