MooseX::Params::Validate

Subroutines that take more than a single argument should really be using something like MooseX::Params::Validate.

Consider:

sub vivisect { 
my ( $self, $args ) = @_;
confess 'Expected a hashref of arguments' unless 'HASH' eq ref $args;

my $hamster = $args->{hamster};

OK, so we know it accepts a hashref of arguments, and what's more, we know one of them is called hamster. But: what constitutes an acceptable hamster? What do we want to …

Sequences, Sets, Bags, Functions

Groups of Items

A sequence is an ordered list of items, whose items aren't necessarily unique. Perl's arrays are sequences of a finite size:

my @sequence = qw/bar baz ban baz baz/;

A set, however, is an unordered collection of unique items. Perl provides native support for sets in the form of the keys of hashes:

my %set1 = map { $_ => undef } qw/foo bar baz/;
my %set2 = map { $_ => undef } qw/bar foo foo baz/; # Same as above
my %set3 = map { $_ =>…

De Morgan's laws in Perl

We've been simplifying some ugly code recently, and De Morgan's laws have come up more than once. A developer on the team complained the Wikipedia entry obscured - from a developer's perspective - the simplicity of these quite useful transformation rules, so, expressed in Perl:

Given $p and $q as truth values:

(! ( $p && $q ) ) == ( (! $p) || (! $q) )
(! ( $p || $q ) ) == ( (! $p) && (! $q) )

OR:

NOT( p AND q ) is equivalent to (NOT p) OR  (NOT q)
NOT( p OR  q ) is equivalent to (NOT p) AND (NOT q)

So for example, say you come…

New Project: ziprip.js

I've been playing with JS a bit recently, and have released a client-side library for extracting postal addresses and geocoords from webpages - it's intended for use in bookmarklets and browser extensions:

http://zipripjs.com/

I've also made it work with node.js - which means it's installable via npm. For what it's worth, it's considerably easier to create a new user account for node packages (no human intervention step), and there's a built-in publish tool...

Introducing Class::ConfigHash

A while ago I saw a post by Ovid on boxing hashes for configuration in Dancer. The idea seemed pretty neat, and I found myself doing something similar in some work for Net-A-Porter, so I wrote a generalized implementation (although the underlying mechanism is different). From the synopsis:

my $config = Class::ConfigHash->_new({
   database => {
       user => 'rodion',
       pass => 'bonaparte'…