July 2014 Archives

Method Privacy in Perl

This is a slightly expanded version of a comment I posted a couple of days ago on NEILB's blog.

Neil was mostly talking about private functions, while I'll be talking mostly about private methods (i.e. object-oriented programming), but I think there's probably a good deal of overlap between the two concepts.

The traditional way of indicating a method is private is to name it with a leading underscore:

   sub _secret_sauce {
      my $self = shift;
      ...;
   }
   
   $self->_secret_sauce(@args);

The assumption is even baked into the Perl development and testing toolchain in a few places. For example Pod::Coverage won't complain about missing documentation for a sub if that sub happens to be named with a leading underscore.

I used to think the underscore convention was good enough. But partly because of this upcoming project and partly because of problems I've encountered working on various codebases, I've been forced to re-evaluate my thinking, and have come to the conclusion that the underscore convention is insufficient.

Meta-Meta-Meta Problem Solving

OK, so I'm working on a project and some unexpected bug crops up. It turns out to be a bug in a dependency. I could work around it, but...

I happen to maintain the dependency, so better to fix it at source. Done. Let's set up Travis testing for this dependency too...

Oh no, build fails. Test::Modern won't install on all the versions of Perl I'd hoped it would. (In particular, Perl 5.6.) Why? Turns out some of Test::Modern's dependencies use Module::Build and Module::Build::Tiny, and they require Perl 5.8.

So let's try out Ingy's Alt concept and release alternative distributions of these dependencies which will install cleanly on Perl 5.6. Hence Alt::Test::Warnings::ButEUMM (which led to this) and Alt::Module::Runtime::ButEUMM.

Because Sometimes Lightspeed is Too Slow

Spaceballs: Lightspeed is too slow. We'll have to go right to ludicrous speed.

I've pushed Type::Tiny 0.045_03 to CPAN this afternoon. Initial results from CPAN testers seem promising, but if you've got a distribution that uses Type::Tiny it might be worth trying it out with the new version to see if anything breaks. (I don't think anything should!)

The big change in this release is that it adds support for an optional XS backend, which massively boosts the speed of many type constraint checks — especially parameterized types like ArrayRef[InstanceOf["HTTP::Response"]]. The XS backend is a fork of Mouse's type constraints, and needs to be installed separately. It's called Type::Tiny::XS. (OK; not a very creative name.)

Planet Moose - June 2014

Welcome to Planet Moose, a brief write up on what's been happening in the world of Moose in the past month, for the benefit of those of you who don't have their eyes permanently glued to the #moose IRC channel, or the MetaCPAN recent uploads page.

If you'd like to contribute some news for next month's issue, you can do so on the wiki.

Moose

Moose 2.1208 and 2.1209 have been released containing some minor bugfixes.

About Toby Inkster

user-pic I'm tobyink on CPAN, IRC and PerlMonks.