编译错误取决于“使用”顺序

时间:2012-08-28 08:17:54

标签: perl

我有这三个文件

常量/ Requests.pm

#!/usr/bin/perl

use strict;

use base 'Exporter';

use constant MR_NOACTION     =>   0;
use constant MR_START        =>   1;
use constant MR_STOP         =>   2;

our @EXPORT = (
    'MR_NOACTION',
    'MR_START',
    'MR_STOP'
);
1;

JobManDB.pm

#!/usr/bin/perl

package JobManDB;

use strict;
use warnings;

use constant WEB_DB_FILE    => "db/web.db";
use constant MASTER_DB_FILE => "db/master.db";

use Constants::Requests;

sub new
{
    print "Ahoj: " . MR_NOACTION . "\n";
    ...

Master.pm

#!/usr/bin/perl

package Master;

use strict;
use warnings;

use Time::HiRes qw( usleep );
use Data::Dumper;

use JobManDB;                   # use #1

use Constants::Requests;  # use #2

...

发布的程序正在运行,如果我将use #1use #2联系起来,则编译失败并显示错误:

Bareword "MR_NOACTION" not allowed while "strict subs" in use at lib/JobManDB.pm line 26.

(第26行是'new'子程序中的行)。我想知道为什么。谢谢。

编辑: 另一个问题是,如果我在Requests.pm的开头添加行package Requests;,则编译失败并出现相同的错误,但是在“使用”的顺序上是独立的。

1 个答案:

答案 0 :(得分:3)

Requests.pm文件缺少其包声明package Constants::Requests;