I'm packaging some common functions in a small Perl module, that I load in the script using
use lib path/to/lib
In the module file I imported some other system installed modules (e.g. Carp qw(confess), but I cannot invoke confess directly, but rather Carp::confess, which is unusual to me.
This is my (non)-working example: https://github.com/telatin/bioinfo/blob/master/mini/script.pl
use 5.012;
use FindBin qw($Bin);
use lib "$Bin/Demo/lib";
use Local::Module;
say "Version: ", $Local::Module::VERSION;
Local::Module->new();
The module: https://github.com/telatin/bioinfo/blob/master/mini/Demo/lib/Local/Module.pm
use 5.012;
use warnings;
use Carp qw(confess);
package Local::Module;
$Local::Module::VERSION = 2;
sub new {
my ($class, $args) = @_;
my $self = {
debug => $args->{debug},
};
my $object = bless $self, $class;
confess "Unable to create fake object";
return $object;
}
1;
What should I do in the .pm file to avoid this problem?
$Binshould be$RealBin. That way, the program will keep working if you create a symlink to the program