2

Is it possible to use MooseX meta attributes with Moops?

Consider this Moose sample code:

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";

I tried to transform this to Moops like so:

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";
tobyink
  • 13,478
  • 1
  • 23
  • 35
sschober
  • 2,003
  • 3
  • 24
  • 38

1 Answers1

2

Moops classes are backed by Moo, not Moose by default. Thus MooseX extensions will not usually work.

However, it's possible to use Moose instead of Moo:

class TraitTest with MooseX::Getopt using Moose {
    ...
}
tobyink
  • 13,478
  • 1
  • 23
  • 35
  • Yeah, I read about `using Moose` in the documentation. I thought it might be possible to use the `Moo` "backend", as there is `MooX::late`. I'd really like to use `Moo` together with `MooseX::Getopt` - do you think it would be feasible to port it? – sschober Feb 03 '14 at 18:32
  • You could try [MooX::Options](https://metacpan.org/pod/MooX::Options) which is similar to (but not the same as) MooseX::Getopt, and works with Moo. (Until the most recent release of Moops, it didn't work with Moops. But it does now.) – tobyink Feb 03 '14 at 20:23
  • Is there a way to set Moose as default instead of Moo? – mpapec Sep 24 '15 at 07:49