Reputation: 563
I am trying to create my own Perl module in /usr/local/lib/perl
I have the environmental variable PERL5LIB set:
$ env | grep PERL
PERL5LIB=/usr/local/lib/perl
If I create a module: $PERL5LIB/My/ModuleTest.pm
$ ./test.pl
Can't locate object method "new" via package "My::ModuleTest" (perhaps you forgot to load "My::ModuleTest"?) at ./test.pl line 8.
test.pl:
#!/usr/bin/perl
use strict;
use warnings;
use My::ModuleTest;
my $test = new My::ModuleTest;
print $test->check;
ModuleTest.pm:
package ModuleTest;
use strict;
use warnings;
sub new {
my $class = shift;
my ($opts)= @_;
my $self = {};
$self->{test} = "Hello World";
return bless $self, $class;
}
sub check {
my $self = shift;
my ($opts) = @_;
return $self->{test};
}
1;
I want to use the $PERL5LIB as the library path for my modules to segregate them from the installation directory.
Perl @INC:
$ perl -le 'print foreach @INC'
/usr/local/lib/perl
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/5.8.8
.
Upvotes: 9
Views: 1769
Reputation: 1717
Change the first line of your module from
package ModuleTest;
to
package My::ModuleTest;
Upvotes: 3
Reputation: 39763
Try package My::ModuleTest;
in your file ModuleTest.pm
- you should use the full name.
Upvotes: 10