Reputation: 323
I have the following perl module:
#!/usr/bin/env perl
package temp;
require Exporter;
our @ISA = ('Exporter');
our @EXPORT = qw(temp_print);
sub temp_print {
my ($p) = @_ ;
print "$p\n" ;
}
1;
This file is present here: ./f/temp.pm My main file is called test.pl and looks like this
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin qw($Bin);
use lib $Bin;
use f::temp ;
temp_print("hi");
When I try to execute test.pl, it doesn't seem to be importing temp_print into the main package:
% ./test.pl
Undefined subroutine &main::temp_print called at ./test.pl line 8.
I'm not sure what I am missing. This seems to be pretty basic, but can't seem to figure why the subroutines from my package are not being imported. Could you help me figure out what's wrong?
Upvotes: 1
Views: 77
Reputation: 118695
use Exporter ...
is shorthand for
BEGIN {
require Exporter;
Exporter->import(...);
}
By saying require Exporter
instead, you are skipping the call to Exporter
's import
method.
You'll also have to sort out the correct package/file name problem as zdim's comment alludes to.
Upvotes: 1