0

I can't work out why I am unable to access a subpackage:

mbzdb:

#!/usr/bin/perl -w

use lib "./lib";
use MbzDb::Instance;

my $instance = new MbzDb::Instance();
$instance->startFromCommandLine();

lib/MbzDb/Instance.pm:

#!/usr/bin/perl -w

package MbzDb::Instance;

use strict;
use warnings;
use Getopt::Long;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(new startFromCommandLine);

sub new {
    my $class = shift;
    return bless {}, $class;
}

sub startFromCommandLine {
    my $self = shift;
}

If I use the same code in lib/MbzDb.pm the export works correctly. What am I doing wrong?

The error given is:

Can't locate object method "new" via package "MbzDb::Instance" (perhaps you forgot to load "MbzDb::Instance"?) at ./mbzdb line 6.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Elliot Chance
  • 5,526
  • 10
  • 49
  • 80

1 Answers1

0

Try using the excellent FindBin module.

use FindBin;
use lib $FindBin::Bin . '/lib';
use MbzDb::Instance;

This works if your structure looks like this:

mbzdb
lib/
  MbzDb/
    Instance.pm
ccosby
  • 11
  • 1