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.
Is there a "Try Perl 6" on the web yet? Google is failing me and I'd love to paste one of the grammar examples into a textbox and start playing it; especially since I don't see Windows binaries linked from the article.
Not exactly the most optimal way, but you can hop on to the IRC channel #perl6 and run code there using one of many codebots. Admittedly, you are limited to one-liners here. And, your code will be public, so it's not like running in the "comfort of your own session".
Thanks to everyone who put this together. This probably sounds silly, but Perl was the first programming language I ever did anything "real" with (it was my second language, after Microsoft QuickBASIC), and no matter how many other languages I try I'll always have a soft spot in my heart for Perl. So it's great to see a real release for Perl 6 which, as it matures, I think will prove itself as the best mainstream dynamic imperative language out there.
EDIT: In particular, I think macros and stm will be killer features with respect to other languages, once they're implemented in Rakudo.
As a Perl 5 developer I'm really excited about Perl 6. But the reason I won't use Perl 6 for at least the next 3 years is the same reason Ruby isn't my core language for production apps: I'm waiting for it to get really fast and really stable. Ruby is just about there, so I'll probably switch to Ruby in the next year or so. Then 3 to 6 years from now I'll switch to some incarnation of Perl 6 assuming it maintains its momentum and has tangible benefits over Ruby.
I'm not an early adopter. I think startups are risky enough and technology choices are but one point of differentiation in business.
I'm happily using MooseX::Declare for when I want better OO - and given Moose is a full metaprotocol with appropriate, extensible objects for everything (ruby has nothing like attributes, let alone extensible meta-attributes, sadly) it's a hugely powerful tool.
Piers Cawley happily gave up on ruby and came back to perl5 as a result of it - you should give it a play before looking at a more drastic switch.
* 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.