作者:喵喵浮游生物 | 来源:互联网 | 2022-11-28 17:45
1> ikegami..:
如果你使用常量而不是变量,
package Funx;
use strict;
use warnings;
use constant qw( );
use Exporter qw( import );
BEGIN {
my %error_codes = (
FUNX_SUCCESS => 0,
FUNX_NOFILE => 1,
FUNX_COPYFAIL => 2,
FUNX_SOXFAIL => 3,
FUNX_CURLFAIL => 4,
FUNX_OPENFAIL => 5,
FUNX_APPRUNNING => 6,
FUNX_RAWDBEXIISTS => 7,
FUNX_DBCREATEERR => 8,
FUNX_DBCOnNECTERR=> 9,
FUNX_TMPFILEERR => 10,
FUNX_DBWRITEERR => 11,
FUNX_INVALIDUSER => 12,
FUNX_DBLOCKERR => 13,
FUNX_DBUNLOCKERR => 14,
FUNX_WERR => 100,
);
constant->import(\%error_codes);
my @syms = keys(%error_codes);
our @EXPORT_OK = \@syms;
our %EXPORT_TAGS = ( ALL => \@syms, ERROR_CODES => \@syms );
}
除了解决您提出的问题之外,还有以上内容
修复了用户命名空间的污染问题.默认情况下,不要将一堆符号转储到其他名称空间中!
修复可能与其他模块冲突的可怜名称.您认为您是唯一具有代码的模块SUCCESS
吗?
修复了模块的污染问题@ISA
.Funx不是Exporter的子类.
用法:
use Funx; # Imports nothing.
use Funx qw( ); # Imports nothing.
use Funx qw( :ERROR_CODES ); # Imports error codes.
use Funx qw( :ALL ); # Imports error codes.
use Funx qw( FUNX_SUCCESS FUNX_NOFILE ); # Imports specific error codes.