
Cool Things in Perl 6 - fogus
http://blogs.perl.org/users/ovid/2010/01/cool-things-in-perl-6.html
======
telemachos
I love Perl. Perl is my language of choice. So I promise that I am not
trolling. Let's just stipulate that I'm slow or inexperienced or very
confused.

What is the cool in that code? Can someone explain to me (apparently using
small words) why this is exciting?

~~~
chromatic
The example defines a subtype which represents a file on disk. Any parameter
conforming to that subtype must name a file that is present on disk.

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.

~~~
telemachos
Nicely explained. Thanks.

------
access_denied
This kind of posts just show how good the perl community is in terms of
marketing. Not loud or shrill, just sharing a cup of fresh mint tea at an
oasis.

------
andrewljohnson
This title should be "cool thing in Perl 6." It's just a tiny blogpost about
subsets. There are zero other new features mentioned.

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!

~~~
mock
Lots of us use Perl these days. For example those of us that care about speed,
stability, and sane backwards compatibility. WWW::Mechanize is still a great
tool when appropriate. Catalyst and Moose are pretty awesome to work with as
well. I'm pretty happy with the state of Perl these days, there are lots of
reasons to recommend it, but if Python works for you, that's cool too.

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.

~~~
draegtun
Thanks for posting Stevan's gist... I hadn't seen that elsewhere.

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'.

~~~
jrockway
This reminds me that it would be nice if someone wrote a module that produced
type constraints like:

    
    
       File[Exists]
       File[Readable, Executable]
       Dir[Empty]
       

as an extension to MooseX::Types::Path::Class.

