Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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 ( and are in some_dir/Lib/ folder. My test script is in some_dir.
#file package UTest; use warnings; use strict; sub new { my $class = shift; my $self = { 'name' => '', 'condition' => '', 'args' => [], }; return bless $self, $class; } # other sub ... 1;
#file 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 use Lib::Service; my $service = Service->new; #... other codes
I get following error when i run
Can't locate 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/ line 2. BEGIN failed--compilation aborted at Lib/ line 2. Compilation failed in require at ./ line 2. BEGIN failed--compilation aborted at ./ line 2.
Can someone help me? Thanks.

Replies are listed 'Best First'.
Re: Perl module in a user local folder
by Athanasius (Chancellor) 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, then in your test perl script, you can call use Lib::Service
    Infact, your Utest module should also be called
    Note that "::" is just like saying "Lib/" or "Lib/Service"
    Hope this helps.

      Thank you for your answer. But Perl compains about syntax error with use 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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2016-10-26 05:52 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (336 votes). Check out past polls.