smart-matching and sub funhouse

Bad timing: now that smart-matching is under scrutiny, I've started to have fun writing Perl like this:

use signatures;
use Path::Class;

file( 'file.txt' ) ~~ sub ($f) {
   say $f->basename;
   say $f->slurp;

This style and syntax is reminiscent of Python's with and Ruby's do, and, for this use case in particular, feels a bit more natural to me than right-to-left, functional-style Perl5:

map { say $_->slurp } file( 'file.txt');

I was just wondering if anyone likes them Perl served like tha'.

Thinking of an alternative, but similar syntax, a year or so ago I forked Perl 5.13.x and patched it trying to make it take sub { } as a method call. Things didn't work as I expected as I'm a Perl5 internals noob, it was a really hot Madrid summer afternoon and I had a higher-than-usual dead brain cell count, but the idea was to be able to call closures on objects:

my $f = file( 'ah-ha' );
$f -> sub {
    say $_->basename . ' = ' . $_->slurp;

Which probably could work nicely on native types too:

( 1..10 ) -> sub { ... };  # same as sub{ ... }->( 1..10 );
@arr -> sub { ... }; # sub{ ... }->( @arr );
%hash -> sub { ... }; 
"string" -> sub { ... };

The insignificant white-space before and after the arrow makes it even more expressive.

This is not a proposal, Perl6 already that covered: 'ponty-blocks' come to mind, which even drops sub altogether. But it sure feels like something that could make quite easily into Perl5 without causing a lot of grief.

OTRS on Plack

Lately I've been playing around with the OTRS ticketing system on one of my servers. OTRS is written in Perl, and is typically run as a CGI, mod_perl or FastCGI app. Usually I'd map it as a FastCGI app on Nginx and start the 2 FastCGI servers via a init.d script (one for the customer helpdesk and another for the management console).

But this time I wanted to give Plack a try.

I'm new to Plack and PSG…

CPAN source syntax highlighting

I've just updated a syntax highlighter bookmarklet I wrote a while back so that it now supports Chrome and Safari, besides Firefox.

I find it useful to syntax highlight when I peek at a module's source code in the CPAN website. You may find it useful too.

To install it, create a new bookmark and paste the following code into the location field (sorry, I couldn't find a way to post this as a javascript: link in this blog):


Perl::Critic --praise

Wouldn't it be cool if Perl::Critic had a --praise option?

It would tell programmers they have done something worth mentioning and throw in some inspirational kudos and uplifting recognition:

$ perlcritic --praise
Good! Filehandle is not a Bareword at line 4, column 1.  See page 202,204 of PBP.  (Cleverness: 1)
Nice use of comments in a regex. Maintainers will be happy at line 9, column 1.  See page 289 of PBP.  (Cleverness: 3)
Outstanding use of Moose roles at line 11, column 1.  (Cleverness: 2)
Named pa…

Test-driving MongoDB on a Moose

I spent a few hours this last weekend trying out MongoDB, and its Perl driver.

I was curious to see how I could put NoSQL databases to good programming use. MongoDB stroke me as a good contender for some experiments: it's easy to install, well documented and has an intuitive query language that reminds me of SQL::Abstract syntax. Besides, MongoDB ="…