Reputation: 133
As the title states, I get this error when trying to use my perl module, but I have no idea what it means and I can't seem to find any clear results on the internet. My code consists of 3 files: a script (myApp.pl) which uses a module (MyLib.pm) which in turn uses another module (Secret.pm). Here they are in their entirety:
myApp.pl
#!/path/to/perl
my $version = "1.0.0";
use warnings;
use strict;
use Testing::MyLib;
MyLib.pm
package Testing::MyLib;
use strict;
use warnings;
use Testing::Secret;
Secret.pm
package Testing::Secret;
use strict;
use warnings;
use Exporter qw( import );
our @EXPORT = ();
our %EXPORT_TAGS = (
'all' => [ qw( MY_CONSTANT )]
);
our @EXPORT_OK = (
@{ $EXPORT_TAGS{all}}
);
use constant MY_CONSTANT => 'bla bla bla';
They exit in this file structure:
/bin/myApp.pl
/lib/perl/Testing/MyLib.pm
/lib/perl/Testing/Secret.pm
And the detail of the error message is:
[user@pc ~]$ myApp.pl
"import" is not exported by the Exporter module at /###/lib/perl/Testing/Secret.pm line 6
Can't continue after import errors at /###/lib/perl/Testing/Secret.pm line 6
BEGIN failed--compilation aborted at /###/lib/perl/Testing/Secret.pm line 6.
Compilation failed in require at /###/lib/perl/Testing/MyLib.pm line 6.
BEGIN failed--compilation aborted at /###/lib/perl/Testing/MyLib.pm line 6.
Compilation failed in require at /###/bin/myApp.pl line 7.
BEGIN failed--compilation aborted at /###/bin/myApp.pl line 7.
Upvotes: 3
Views: 1127
Reputation: 9231
use Exporter qw( import );
requests that Exporter exports (creates) import
in your module's namespace. This is the method that handles requests to export from your module. Versions of Exporter older than 5.57 don't recognize this request, leading to the error message you obtained.
Since Exporter 5.57 or newer has been bundled with Perl since Perl 5.8.3, you must have a pretty ancient version of Perl and the module!
You could upgrade Exporter, or you could inherit import
from Exporter, which is a little messier but works with any version of Exporter.
package MyPackage;
use strict;
use warnings;
use Exporter;
our @ISA = 'Exporter';
our @EXPORT_OK = ...;
Upvotes: 6