August 2011 Archives

Adventures in self-documenting code

Further to my recent work on Params::Validate::Dependencies, I wanted to make the code-refs returned by the magic any_of / all_of etc functions somewhat self-documenting. And I've done it. However, there's quite a bit of boiler-plate in lib/Params/Validate/Dependencies.pm as a result. For example, I had to write:
  if($DOC) { return $DOC->_doc_me(list => \@options); }
four times, and define four almost-identical classes.

Number::Phone::Country now knows about South Sudan

On 9 July 2011, southern Sudan gained its independence, and became the independent republic of South Sudan. It has been allocated ISO 3166 country code SS and ITU-T E.164 dialling code +211. Number::Phone::Country now knows about the world's youngest country.

I did have to make two small assumptions though, as there's no data available. I assumed that, like (northern) Sudan and most other countries, the dialling codes to use inside the country t…

Params::Validate::Dependencies and Data::Domain::Dependencies

I've unleashed Params::Validate::Dependencies on an unsuspecting world, and, because it was easy, have also bundled a Data::Domain subclass with it too. I hope people find it useful!

Having hacked on this stuff, I am now firmly convinced not only that all problems can be solved by introducing another layer of closures, but that all problems should be solved in this way :-)

Params::Validate::Dependencies

Params::Validate is a very useful module, which lets you easily enforce rules such as "the 'foo' parameter to the 'bar' subroutine should be an arrayref". It also has some very basic support for dependencies - eg, that the 'baz' parameter must always be used in conjunction with the 'bar' parameter.

But for a problem I had, it didn't go far enough. So I've extended it. Params::Validate::Dependencies (Github link; not yet on the CPAN) extends the validate() method to add support for things like "must ha…

About David Cantrell

user-pic I'm in yur test resultz analyzn yr failz