fREWdiculous!
6 May
This is mostly stuff I’ve gathered from this talk and updated slightly.
First off, have you ever tried to teach a programmer perl? I have. Note this:
1 2 3 4 5 6 7 8 9 10 |
The following is more palatable to most coders (also I like it better:)
1 2 3 4 5 6 7 8 | use <a href="http://search.cpan.org/search%3fmodule=Method::Signatures::Simple">Method::Signatures::Simple</a>; method foo($bar, $baz) { #... } method station { #... } |
That’s right, no fiddling with @_ at all. Sweet! Also note: this is not implemented with sketchy source filters. It’s quite robust. There is also MooseX::Method::Signatures (and MooseX::Declare which uses that) which can do even more, like defining named and optional params and type constraints.
I’ve already mentioned IO::All, so I’ll just say that it’s been endorsed by Matthew S. Trout, so you don’t have to tell me that the Right Way is to use some crufty C based interface or some weird old perl module that has capital letters in the functions and method parameters.
Next up, Moose::Autobox. I’ve also mentioned autobox, which this module uses, but Moose::Autobox goes further and defines some roles that your classes can also use to make them act like arrays etc. I wouldn’t be surprised if DBIx::Class 0.09x used some of these roles. Anyway, here’s a real example:
1 2 3 4 5 6 7 8 | use Method::Signature::Simple; use Moose::Autobox; method criticisms { return { data => $self->files_criticized->values->map(sub { @{ $_->{criticisms} } }) }; } |
Not quite Perl 6/Ruby, but still much clearer than the original (at least to this function programmer!)
And the of course there is the recently released (four months ago!) TryCatch. I haven’t used this module at all, but I look forward to it. It could really streamline some of the stuff we do at work.
Lastly, CLASS is a tiny nicety. All it does is replace __PACKAGE__ with CLASS; the code looks cleaner with it and it’s certainly shorter and easier to type.
I think we’ll be seeing a lot more of this kind of stuff in the near future. Devel::Declare seems to have mostly matured, so these modules will probably continue to crop up.
Anyway, woohoo! The future!
One Response for "Future Perl"
I’d like to see DBIC 0.09 actually make heavy use of MooseX::Declare, since that would give us an opportunity to really beat on it, in the same way Reaction helped beat on Moose, but I realize a lot of people have DBIC in production so this might not be possible.
Leave a reply