문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top