I think you're in for a good surprize there, you can even do
subset Even of Int where { $_ % 2 == 0 };
sub foo(Even $a) {say $a;}
foo(2); # prints 2
foo(3); # Constraint type check failed for parameter '$a'
I think you're in for a good surprize there, you can even do
subset Even of Int where { $_ % 2 == 0 };
sub foo(Even $a) {say $a;}
foo(2); # prints 2
foo(3); # Constraint type check failed for parameter '$a'
XML parser defined using perl6 grammar rules: http://github.com/krunen/xml/blob/master/lib/XML/Grammar/Doc...
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.