在静默模式下使用 perl MooseX 扩展?
我的 ubuntu 机器上安装了 perl 5.10.1。我想安装 Moose 和 MooseX 扩展,所以我使用 aptitude 包管理器安装了这些包。以下是我安装的所有软件包:
$ sudo apt-cache pkgnames | grep moose
libmoosex-singleton-perl
libmoosex-compiletime-traits-perl
libmoosex-types-structured-perl
libmoosex-traits-pluggable-perl
libmoosex-nonmoose-perl
libmoosex-methodattributes-perl
libmoosex-strictconstructor-perl
libmoosex-classattribute-perl
libany-moose-perl
libmoosex-traits-perl
libmoosex-meta-typeconstraint-forcecoercion-perl
libmoosex-attributehelpers-perl
libmoosex-types-set-object-perl
libmoosex-multiinitarg-perl
libmoosex-has-sugar-perl
libmoosex-role-withoverloading-perl
libmoosex-getopt-perl
libmoosex-aliases-perl
libmoosex-types-varianttable-perl
libmoosex-types-datetime-perl
libmoosex-yaml-perl
libmoosex-daemonize-perl
libmoosex-blessed-reconstruct-perl
libmoosex-emulate-class-accessor-fast-perl
libmoosex-poe-perl
libmoose-perl
libmoosex-types-common-perl
libmoosex-async-perl
libmoosex-method-signatures-perl
libmoosex-storage-perl
libmoosex-log-log4perl-perl
libmoose-policy-perl
libmoosex-semiaffordanceaccessor-perl
libmoose-autobox-perl
libmoosex-app-cmd-perl
libmoosex-role-parameterized-perl
libmoosex-params-validate-perl
libmoosex-object-pluggable-perl
libmoosex-declare-perl
libmoosex-lazyrequire-perl
libmoosex-methodattributes
libmoosex-clone-perl
libmoosex-types-perl
libmoosex-types-path-class-perl
我的问题是,为什么当我运行使用 MooseX::* 扩展的代码时会出现乱码?有没有办法开启静音模式?仅使用 Moose 不会在输出中显示任何其他内容,而是显示所需的结果,但如果使用 MooseX::Declare ,我会得到以下结果:
$ ./myPerlProg.pl
The old Moose::Util::MetaRole API (before version 0.94) has been deprecated at /usr/local/lib/perl/5.10.1/Moose/Util/MetaRole.pm line 16
Moose::Util::MetaRole::apply_metaclass_roles('for_class', 'MooseX::Method::Signatures', 'attribute_metaclass_roles', 'ARRAY(0x9ec2988)') called at /usr/share/perl5/MooseX/LazyRequire.pm line 15
MooseX::LazyRequire::init_meta('MooseX::LazyRequire', 'for_class', 'MooseX::Method::Signatures', 'metaclass', undef) called at /usr/local/lib/perl/5.10.1/Moose/Exporter.pm line 355
Moose::Exporter::__ANON__('MooseX::LazyRequire') called at /usr/share/perl5/MooseX/Method/Signatures.pm line 10
MooseX::Method::Signatures::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
require MooseX/Method/Signatures.pm called at /usr/share/perl5/MooseX/Declare/Syntax/MethodDeclaration.pm line 5
MooseX::Declare::Syntax::MethodDeclaration::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
require MooseX/Declare/Syntax/MethodDeclaration.pm called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 114
Class::MOP::__ANON__() called at /usr/local/share/perl/5.10.1/Try/Tiny.pm line 71
eval {...} called at /usr/local/share/perl/5.10.1/Try/Tiny.pm line 67
Try::Tiny::try('CODE(0x9acde78)', 'Try::Tiny::Catch=REF(0x9a966a8)') called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 125
Class::MOP::load_first_existing_class('MooseX::Declare::Syntax::MethodDeclaration') called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 137
Class::MOP::load_class('MooseX::Declare::Syntax::MethodDeclaration', undef) called at /usr/local/lib/perl/5.10.1/Moose/Util.pm line 109
Moose::Util::_apply_all_roles('Moose::Meta::Class=HASH(0x9ac6200)', undef, 'MooseX::Declare::Syntax::MethodDeclaration') called at /usr/local/lib/perl/5.10.1/Moose/Util.pm line 87
Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x9ac6200)', 'MooseX::Declare::Syntax::MethodDeclaration') called at /usr/local/lib/perl/5.10.1/Moose.pm line 58
Moose::with('Moose::Meta::Class=HASH(0x9ac6200)', 'MooseX::Declare::Syntax::MethodDeclaration') called at /usr/local/lib/perl/5.10.1/Moose/Exporter.pm line 294
Moose::with('MooseX::Declare::Syntax::MethodDeclaration') called at /usr/share/perl5/MooseX/Declare/Syntax/Keyword/MethodModifier.pm line 9
require MooseX/Declare/Syntax/Keyword/MethodModifier.pm called at (eval 205) line 1
MooseX::Declare::Syntax::MooseSetup::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval 'package MooseX::Declare::Syntax::MooseSetup; use MooseX::Declare::Syntax::Keyword::MethodModifier;' called at /usr/share/perl5/aliased.pm line 50
aliased::_load_alias('MooseX::Declare::Syntax::Keyword::MethodModifier', 'MooseX::Declare::Syntax::MooseSetup') called at /usr/share/perl5/aliased.pm line 20
aliased::import('aliased', 'MooseX::Declare::Syntax::Keyword::MethodModifier') called at /usr/share/perl5/MooseX/Declare/Syntax/MooseSetup.pm line 8
MooseX::Declare::Syntax::MooseSetup::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
require MooseX/Declare/Syntax/MooseSetup.pm called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 114
Class::MOP::__ANON__() called at /usr/local/share/perl/5.10.1/Try/Tiny.pm line 71
eval {...} called at /usr/local/share/perl/5.10.1/Try/Tiny.pm line 67
Try::Tiny::try('CODE(0x9ab31c8)', 'Try::Tiny::Catch=REF(0x9a8e398)') called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 125
Class::MOP::load_first_existing_class('MooseX::Declare::Syntax::MooseSetup') called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 137
Class::MOP::load_class('MooseX::Declare::Syntax::MooseSetup', undef) called at /usr/local/lib/perl/5.10.1/Moose/Util.pm line 109
Moose::Util::_apply_all_roles('Moose::Meta::Class=HASH(0x9a054b8)', undef, 'MooseX::Declare::Syntax::MooseSetup', 'MooseX::Declare::Syntax::RoleApplication', 'MooseX::Declare::Syntax::Extending') called at /usr/local/lib/perl/5.10.1/Moose/Util.pm line 87
Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x9a054b8)', 'MooseX::Declare::Syntax::MooseSetup', 'MooseX::Declare::Syntax::RoleApplication', 'MooseX::Declare::Syntax::Extending') called at /usr/local/lib/perl/5.10.1/Moose.pm line 58
Moose::with('Moose::Meta::Class=HASH(0x9a054b8)', 'MooseX::Declare::Syntax::MooseSetup', 'MooseX::Declare::Syntax::RoleApplication', 'MooseX::Declare::Syntax::Extending') called at /usr/local/lib/perl/5.10.1/Moose/Exporter.pm line 294
Moose::with('MooseX::Declare::Syntax::MooseSetup', 'MooseX::Declare::Syntax::RoleApplication', 'MooseX::Declare::Syntax::Extending') called at /usr/share/perl5/MooseX/Declare/Syntax/Keyword/Class.pm line 7
require MooseX/Declare/Syntax/Keyword/Class.pm called at (eval 1) line 1
MooseX::Declare::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval 'package MooseX::Declare; use MooseX::Declare::Syntax::Keyword::Class;' called at /usr/share/perl5/aliased.pm line 50
aliased::_load_alias('MooseX::Declare::Syntax::Keyword::Class', 'MooseX::Declare') called at /usr/share/perl5/aliased.pm line 20
aliased::import('aliased', 'MooseX::Declare::Syntax::Keyword::Class', 'ClassKeyword') called at /usr/share/perl5/MooseX/Declare.pm line 6
MooseX::Declare::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
require MooseX/Declare.pm called at ./myPerlProg10.pl line 3
main::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
Variable "$class" is not imported at ./myPerlProg10.pl line 12.
I have perl 5.10.1 installed on my ubuntu machine. I wanted to install the Moose and MooseX extentions, so I did install the packages with the aptitude package manager. Here are all the packages I have installed:
$ sudo apt-cache pkgnames | grep moose
libmoosex-singleton-perl
libmoosex-compiletime-traits-perl
libmoosex-types-structured-perl
libmoosex-traits-pluggable-perl
libmoosex-nonmoose-perl
libmoosex-methodattributes-perl
libmoosex-strictconstructor-perl
libmoosex-classattribute-perl
libany-moose-perl
libmoosex-traits-perl
libmoosex-meta-typeconstraint-forcecoercion-perl
libmoosex-attributehelpers-perl
libmoosex-types-set-object-perl
libmoosex-multiinitarg-perl
libmoosex-has-sugar-perl
libmoosex-role-withoverloading-perl
libmoosex-getopt-perl
libmoosex-aliases-perl
libmoosex-types-varianttable-perl
libmoosex-types-datetime-perl
libmoosex-yaml-perl
libmoosex-daemonize-perl
libmoosex-blessed-reconstruct-perl
libmoosex-emulate-class-accessor-fast-perl
libmoosex-poe-perl
libmoose-perl
libmoosex-types-common-perl
libmoosex-async-perl
libmoosex-method-signatures-perl
libmoosex-storage-perl
libmoosex-log-log4perl-perl
libmoose-policy-perl
libmoosex-semiaffordanceaccessor-perl
libmoose-autobox-perl
libmoosex-app-cmd-perl
libmoosex-role-parameterized-perl
libmoosex-params-validate-perl
libmoosex-object-pluggable-perl
libmoosex-declare-perl
libmoosex-lazyrequire-perl
libmoosex-methodattributes
libmoosex-clone-perl
libmoosex-types-perl
libmoosex-types-path-class-perl
My question is, why do I get gibberish when I run code that uses the MooseX::* extentions? Is there a way to enable a silent mode? Using just Moose will not show anything else at output but the desired results, but here is what I get if I use MooseX::Declare :
$ ./myPerlProg.pl
The old Moose::Util::MetaRole API (before version 0.94) has been deprecated at /usr/local/lib/perl/5.10.1/Moose/Util/MetaRole.pm line 16
Moose::Util::MetaRole::apply_metaclass_roles('for_class', 'MooseX::Method::Signatures', 'attribute_metaclass_roles', 'ARRAY(0x9ec2988)') called at /usr/share/perl5/MooseX/LazyRequire.pm line 15
MooseX::LazyRequire::init_meta('MooseX::LazyRequire', 'for_class', 'MooseX::Method::Signatures', 'metaclass', undef) called at /usr/local/lib/perl/5.10.1/Moose/Exporter.pm line 355
Moose::Exporter::__ANON__('MooseX::LazyRequire') called at /usr/share/perl5/MooseX/Method/Signatures.pm line 10
MooseX::Method::Signatures::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
require MooseX/Method/Signatures.pm called at /usr/share/perl5/MooseX/Declare/Syntax/MethodDeclaration.pm line 5
MooseX::Declare::Syntax::MethodDeclaration::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
require MooseX/Declare/Syntax/MethodDeclaration.pm called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 114
Class::MOP::__ANON__() called at /usr/local/share/perl/5.10.1/Try/Tiny.pm line 71
eval {...} called at /usr/local/share/perl/5.10.1/Try/Tiny.pm line 67
Try::Tiny::try('CODE(0x9acde78)', 'Try::Tiny::Catch=REF(0x9a966a8)') called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 125
Class::MOP::load_first_existing_class('MooseX::Declare::Syntax::MethodDeclaration') called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 137
Class::MOP::load_class('MooseX::Declare::Syntax::MethodDeclaration', undef) called at /usr/local/lib/perl/5.10.1/Moose/Util.pm line 109
Moose::Util::_apply_all_roles('Moose::Meta::Class=HASH(0x9ac6200)', undef, 'MooseX::Declare::Syntax::MethodDeclaration') called at /usr/local/lib/perl/5.10.1/Moose/Util.pm line 87
Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x9ac6200)', 'MooseX::Declare::Syntax::MethodDeclaration') called at /usr/local/lib/perl/5.10.1/Moose.pm line 58
Moose::with('Moose::Meta::Class=HASH(0x9ac6200)', 'MooseX::Declare::Syntax::MethodDeclaration') called at /usr/local/lib/perl/5.10.1/Moose/Exporter.pm line 294
Moose::with('MooseX::Declare::Syntax::MethodDeclaration') called at /usr/share/perl5/MooseX/Declare/Syntax/Keyword/MethodModifier.pm line 9
require MooseX/Declare/Syntax/Keyword/MethodModifier.pm called at (eval 205) line 1
MooseX::Declare::Syntax::MooseSetup::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval 'package MooseX::Declare::Syntax::MooseSetup; use MooseX::Declare::Syntax::Keyword::MethodModifier;' called at /usr/share/perl5/aliased.pm line 50
aliased::_load_alias('MooseX::Declare::Syntax::Keyword::MethodModifier', 'MooseX::Declare::Syntax::MooseSetup') called at /usr/share/perl5/aliased.pm line 20
aliased::import('aliased', 'MooseX::Declare::Syntax::Keyword::MethodModifier') called at /usr/share/perl5/MooseX/Declare/Syntax/MooseSetup.pm line 8
MooseX::Declare::Syntax::MooseSetup::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
require MooseX/Declare/Syntax/MooseSetup.pm called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 114
Class::MOP::__ANON__() called at /usr/local/share/perl/5.10.1/Try/Tiny.pm line 71
eval {...} called at /usr/local/share/perl/5.10.1/Try/Tiny.pm line 67
Try::Tiny::try('CODE(0x9ab31c8)', 'Try::Tiny::Catch=REF(0x9a8e398)') called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 125
Class::MOP::load_first_existing_class('MooseX::Declare::Syntax::MooseSetup') called at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 137
Class::MOP::load_class('MooseX::Declare::Syntax::MooseSetup', undef) called at /usr/local/lib/perl/5.10.1/Moose/Util.pm line 109
Moose::Util::_apply_all_roles('Moose::Meta::Class=HASH(0x9a054b8)', undef, 'MooseX::Declare::Syntax::MooseSetup', 'MooseX::Declare::Syntax::RoleApplication', 'MooseX::Declare::Syntax::Extending') called at /usr/local/lib/perl/5.10.1/Moose/Util.pm line 87
Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x9a054b8)', 'MooseX::Declare::Syntax::MooseSetup', 'MooseX::Declare::Syntax::RoleApplication', 'MooseX::Declare::Syntax::Extending') called at /usr/local/lib/perl/5.10.1/Moose.pm line 58
Moose::with('Moose::Meta::Class=HASH(0x9a054b8)', 'MooseX::Declare::Syntax::MooseSetup', 'MooseX::Declare::Syntax::RoleApplication', 'MooseX::Declare::Syntax::Extending') called at /usr/local/lib/perl/5.10.1/Moose/Exporter.pm line 294
Moose::with('MooseX::Declare::Syntax::MooseSetup', 'MooseX::Declare::Syntax::RoleApplication', 'MooseX::Declare::Syntax::Extending') called at /usr/share/perl5/MooseX/Declare/Syntax/Keyword/Class.pm line 7
require MooseX/Declare/Syntax/Keyword/Class.pm called at (eval 1) line 1
MooseX::Declare::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval 'package MooseX::Declare; use MooseX::Declare::Syntax::Keyword::Class;' called at /usr/share/perl5/aliased.pm line 50
aliased::_load_alias('MooseX::Declare::Syntax::Keyword::Class', 'MooseX::Declare') called at /usr/share/perl5/aliased.pm line 20
aliased::import('aliased', 'MooseX::Declare::Syntax::Keyword::Class', 'ClassKeyword') called at /usr/share/perl5/MooseX/Declare.pm line 6
MooseX::Declare::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
require MooseX/Declare.pm called at ./myPerlProg10.pl line 3
main::BEGIN() called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
eval {...} called at /usr/share/perl5/MooseX/LazyRequire.pm line 10
Variable "$class" is not imported at ./myPerlProg10.pl line 12.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些是弃用警告(在 Moose 1.09 中引入)。您正在使用的扩展(或您的代码本身)正在使用的功能将在 Moose 的某些未来版本中删除。如果是 MooseX 扩展引起了警告,请查找更新版本。如果这是您的代码,请修复它。
例如,第一个警告(关于使用旧 Moose::Util::MetaRole API 的 MooseX/LazyRequire.pm)应通过安装 MooseX::LazyRequire 0.06。
我从你对 mirod 答案的评论中看到,你从 CPAN 安装了 Moose,但从 aptitude 安装了 MooseX 模块。这就是导致你的问题的原因; Moose 的版本对于您的扩展来说太新了。要么安装 CPAN 中的所有内容,要么安装 aptitude 中的所有内容。对于 Moose 和 MooseX::* 等密切相关的模块,混合使用 CPAN 和 aptitude 安装可能会导致问题。
These are deprecation warnings (introduced in Moose 1.09). The extensions you're using (or your code itself) is using features that will be removed in some future version of Moose. If it's a MooseX extension that's causing the warning, look for an updated version. If it's your code, fix it.
For example, the first warning (about MooseX/LazyRequire.pm using the old Moose::Util::MetaRole API) should be fixed by installing MooseX::LazyRequire 0.06.
I see from your comment on mirod's answer that you installed Moose from CPAN but the MooseX modules from aptitude. That's what caused your problem; the version of Moose was too new for your extensions. Either install everything from CPAN, or everything from aptitude. Mixing CPAN and aptitude installs for closely-related modules like Moose and MooseX::* is likely to cause problems.