use 5.012;
use MooseX::Declare;
class Foo {
use MooseX::Types -declare => [ qw(Even) ];
use MooseX::Types::Moose qw(Int);
BEGIN {
subtype Even, as Int, where { $_ % 2 == 0 };
}
method bar ( Even $a ) { say $a }
}
my $foo = Foo->new;
$foo->bar( 2 ); # => prints 2
$foo->bar( 3 ); # => throws error
This is a cool capability. But I have to admit, it's lacking in the syntactic sugar that made the previous example look so appealing. I just simply read the code out loud in English and immediately knew what it meant. This is a bit more of a tongue twister. This notion of defining subsets of symbols like this could make code correctness for many cases a trivial thing.
Well, can you reasonably expect much else? It's a backported feature from perl6, constrained by the existing syntax of perl5. Of course it won't have the syntatic sugar.
One of the other cool capabilities of perl6 is the rules system, expanding on regexs so you can work with full on grammars. The perl6 grammar, written in perl6:
No, I'm simply stating that I really like what they're doing with Perl 6 so far. I'm excited by the new grammar system immensely.
It's clear that doing it in an older syntax is clearly less elegant. However, it's very impressive though that the back ports of Perl 6 features to Perl 5 are proceeding relatively nicely though. The work on Perl 6 has definitely been a boon to 5.
It goes away as soon as you put the MooseX::Types declaration into its own package. Which one does pretty often, since reusing types and coercions produces more maintainable code in general. The title of that library isn't "Organise your Moose types in libraries" without reason :)
I built it two weeks ago and I noticed the slow startup too. I'm pretty sure this will improve. It needs to improve because it matters for shell glue. For the rest of the code I'm writing, startup time is a total non-issue.
* It needs perl5 to build.
* Hello World still works.
* Perl can now compete with Java for slow startup.
* One of my pet perl hates, the inability to write "sub foo($a, $b, $c) {" is fixed.