Cool Things in Perl 6
blogs.perl.org
blogs.perl.org
What is the cool in that code? Can someone explain to me (apparently using small words) why this is exciting?
Think of this subtype as a named precondition -- it's a concise, intention-revealing way of reporting error conditions without cluttering the internals of the function with duplicate error-handling code.
And who uses Perl these days anyways? I can't think of a task I wouldn't rather script in Python.
I remember the glory days of web scraping when all a man had was LWP, Mechanize, and his own mastery of regex to work with. But those days are long gone!
I motivated that with an example, which arguably is better than what I comment on. :-)
But seriously, the large majority of Perl articles on HN gets that kind of garbage. Give it a rest, please. At least don't show the world you lack better things to do.
So you can see why it's worth getting upset over.
Just the other day I found that my favorite color, green, is no longer the most popular. Everything green I owned then instantly turned orange. Now I am stuck looking at orange things all the time! It's tragic! And could surely have been avoided if I told everyone that green was better on web-based discussion forums.
Slightly more on topic - when Ovid first posted this to his feed, Stevan Little pointed out that you could already do it in Perl 5 ( http://gist.github.com/268717 ). Watching the give and take between the Perl 6 language and the Modern Perl movement is (I think) one of the more interesting and exciting areas of language development these days.
When I first saw Ovid's post I could see a MooseX::Declare lightbulb going off in my head ;-)
use 5.010;
use MooseX::Declare;
class Foo {
use MooseX::Types -declare => [ qw(Filename) ];
use MooseX::Types::Moose qw(Str);
BEGIN {
subtype Filename, as Str, where { -x $_ };
}
method file ( Filename $name ) {
say "Houston, we have a filename: $name";
}
}
my $foo = Foo->new;
my $perl = `which perl`; chomp $perl;
$foo->file( $perl );
$foo->file( 'no_such_file' );
Above throws the expected exeception on 'no_such_file'. File[Exists]
File[Readable, Executable]
Dir[Empty]
as an extension to MooseX::Types::Path::Class.