使用 MooseX::Declare 关闭内联构造函数
您好,
作为我上一个关于驼鹿的问题的后续,我'现在我们遇到了一个新问题。 我有一个 Moose 类,它使用 方案 12 用于扩展非 Moose 父类。 就是这样:
package MyApp::CGI;
### TODO: make this work with MooseX::Declare?
use Moose;
extends 'CGI::Application';
sub new {
my $class = shift;
my $obj = $class->SUPER::new( @_ );
return $class->meta->new_object( __INSTANCE__ => $obj, @_ );
}
sub setup {
my $self = shift;
$self->start_mode( 'main' );
my @methods = map { $_->name } $self->meta->get_all_methods;
$self->run_modes( map { /^rm_(.+)$/ => $_ }
grep { /^rm_/ }
@methods
);
}
这很好用。 我还有一个此类的子类,它使用 MooseX::Declare
。 但是,因为我现在重写默认的 Moose 构造函数,所以我的子类发出此警告:
Not inlining 'new' for MyApp::CGI::Login since it is not inheriting the default Moose::Object::new
If you are certain you don't need to inline your constructor, specify inline_constructor => 0 in your call to MyApp::CGI::Login->meta->make_immutable
由于 MooseX::Declare
在幕后自动调用 make_immutable
,我无法弄清楚如何让它打开 inline_constructor => 0 参数。
Greetings,
As a followup to my previous question about Moose, I've now run into a new problem. I've got a Moose class which uses Recipe 12 in order to extend a non-Moose parent class. Here it is:
package MyApp::CGI;
### TODO: make this work with MooseX::Declare?
use Moose;
extends 'CGI::Application';
sub new {
my $class = shift;
my $obj = $class->SUPER::new( @_ );
return $class->meta->new_object( __INSTANCE__ => $obj, @_ );
}
sub setup {
my $self = shift;
$self->start_mode( 'main' );
my @methods = map { $_->name } $self->meta->get_all_methods;
$self->run_modes( map { /^rm_(.+)$/ => $_ }
grep { /^rm_/ }
@methods
);
}
This works great. I also have a subclass of this class which uses MooseX::Declare
. However, because I am now overriding the default Moose constructor, my subclass emits this warning:
Not inlining 'new' for MyApp::CGI::Login since it is not inheriting the default Moose::Object::new
If you are certain you don't need to inline your constructor, specify inline_constructor => 0 in your call to MyApp::CGI::Login->meta->make_immutable
Since MooseX::Declare
calls make_immutable
automatically behind the scenes, I haven't been able to figure out how to get it to turn on the inline_constructor => 0
parameter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 IRC 上的一些人,我能够破解这个问题。 声明类
mutable
足以关闭MooseX::Declare
中的auto_make_immutable
标志,因此我可以手动执行此操作。 (当然,这也适用于非 MX::Declare 类。)修订版本:
Thanks to some folks on IRC I was able to crack this one. Declaring the class
mutable
was sufficient to turn off theauto_make_immutable
flag inMooseX::Declare
, so I could then do it manually. (Of course this also works with a non-MX::Declare class.)Revised version: