Greetings,Tắt constructors inline với MooseX :: Khai
Là một followup để tôi previous question về Moose, bây giờ tôi đã chạy vào một vấn đề mới. Tôi đã có một lớp học Moose sử dụng Recipe 12 để mở rộng một lớp học không phải Moose cha mẹ. Dưới đây là:
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
);
}
Điều này thật tuyệt vời. Tôi cũng có một lớp con của lớp này sử dụng MooseX::Declare
. Tuy nhiên, bởi vì tôi bây giờ trọng các Moose constructor mặc định, lớp con của tôi phát ra cảnh báo này:
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
Kể từ MooseX::Declare
cuộc gọi make_immutable
tự động đằng sau hậu trường, tôi đã không thể tìm ra cách để làm cho nó bật tham số inline_constructor => 0
.