将MooseX元属性与Moops一起使用

时间:2014-02-03 15:54:52

标签: perl moose moops

是否可以在Moops中使用MooseX元属性?

考虑一下这个Moose示例代码:

use v5.14;
use strict;
use warnings;

package TraitTest;
use Moose;
with 'MooseX::Getopt';
has opt1 => (
    traits => ['Getopt'],
    is => 'ro',
    isa => 'Bool',
    cmd_aliases => ['o']
);
1;
package main;
print TraitTest->new_with_options()->opt1 ? "yes\n" : "no\n";

我试图将其转换为Moops,如下所示:

use v5.14;
use strict;
use warnings;

use Moops;
class TraitTest
with MooseX::Getopt
{

  has opt1 => (
#    metaclass => 'Getopt', # also not working
    traits => ['Getopt'],
    is => 'ro',
    isa => 'Bool',
    cmd_aliases => ['o']
  );
}
print TraitTest->new_with_options()->opt1 ? "yes\n" : "no\n";

1 个答案:

答案 0 :(得分:2)

Moop类支持Moo,默认情况下不支持Moose。因此,MooseX扩展通常不起作用。

但是,可以使用Moose而不是Moo:

class TraitTest with MooseX::Getopt using Moose {
    ...
}