Question

I like to code OO in Perl like this:

use MooseX::Declare;
use Method::Signatures::Modifiers;
use v5.14.2;


class Talker
{
     method talk (Str $text) {
         $self=>say $text;

     }

     my $talk_object = Talker->new();
     $talk_object->talk('Hello!');
}

Unfortunately this is quite slow, I couldn't find any Mouse or Moo equivalent to it. What a pity that Perl hasn't got anything like PyPy.

Does someone know how to archive the same with the lighter implementations?

Was it helpful?

Solution

The experimental Moops module is another syntax extension that works fairly similar. It is inspired by MooseX::Declare (but is faster) and by the p5-mop project that is trying to bring such syntax into core perl.

Your example would translate without significant changes. If you want to specify a MOP backend, you can declare a class like class Foo using Moose, but it defaults to Moo, which is simpler than Moose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top