我有这个 perl 脚本
#!/usr/bin/perl
use lib "/home/gdanko/test/perl";
use Main;
Plugins::Plug1::devices;
模块 Main 看起来像这样
package Main;
use lib "/home/gdanko/test/perl";
use Plugins::Plug1;
use DBI;
@ISA = ('Exporter');
@EXPORT = qw();
@EXPORT_OK = qw($dbh &load_devices);
our $dbh = DBI->connect("dbi:SQLite:dbname=/home/gdanko/test/mydb.db", "", "");
sub load_devices {
my $sth = $dbh->prepare("SELECT * FROM devices");
$sth->execute;
my $devices = $dbh->selectall_hashref($sth, "id");
return $devices;
}
1;
模块 Plug1 看起来像这样
package Plug1;
use lib "/home/gdanko/test/perl";
use Data::Dumper;
use Main qw(&load_devices);
@ISA = ('Exporter');
@EXPORT = ();
@EXPORT_OK = qw(&devices);
sub devices {
print "module plug1\n";
my $devices = Main::load_devices;
print Dumper(\$devices->{maguro});
}
1;
当我从主脚本执行 Plugins::Plug::devices 时,我得到以下回报: gdanko@apollo:~/test$ ./script.pl module plug1 $VAR1 = \undef;
如何使 Main 中的方法和变量可用于 Plug1?