且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Moose中处理多重继承的构造函数

更新时间:2023-11-11 17:21:16

您是否已经查看过驼鹿::菜谱::基本:: DateTime_ExtendingNonMooseParent MooseX :: NonMoose ?

更新:我对Moose和各种技术不太熟悉.我无法同时使用MooseX::DeclareMooseX::NonMoose来编译模块.但是,这似乎可行:

Update: I am not very familiar with Moose and assorted techniques. I was not able to get the modules to compile using MooseX::Declare and MooseX::NonMoose together. However, here is something that seems to work:

应用程序基础类

package My::App;

use Moose;
use MooseX::NonMoose;
extends 'CGI::Application';

sub setup {
    my $self = shift;
    $self->start_mode( 'main' );

    $self->run_modes(
        map { $_ = $_->name;
              /^rm_ (?<rm>.+) $/x ? ( $+{rm} => $_ ) : ()
        } $self->meta->get_all_methods
    );
}

"My::App"

派生类

package My::Login;
use Moose;
extends 'My::App';

sub rm_main { 'it works!' }

"My::Login"

脚本

#!/usr/bin/perl

use strict;
use warnings;

# For testing on the command line
use FindBin qw( $Bin );
use lib $Bin;

use My::Login;

my $app = My::Login->new;

$app->run;

输出

C:\Temp\f> t
Content-Type: text/html; charset=ISO-8859-1

it works!