oh God that looks absolutely delicious.
Here is the perl6 example using MooseX::Declare (http://search.cpan.org/dist/MooseX-Declare/) in perl5:
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 errorOne 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:
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.