May 2014 Archives

Enumerations in Moose

It's quite a common pattern in object-oriented programming to have an attribute which takes a string as its value, but which only has a small number of valid values. For example:

 package Shirt;
 use Moose;
 # "S", "M", "L", or "XL"
 has size => (is => 'ro', isa => 'Str', required => 1);

This offers no protection against invalid string values.

 # No exception is thrown
 my $shirt = Shirt->new(size => "LX");

Planet Moose - April 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.

Apologies for being a little late delivering the news this month. If you'd like to contribute some news for next month's issue, you can do so on the wiki.


Version 2.1205 is a minor update containing a small bug fix and an improved test case. One interesting new addition is the is_role function in Moose::Util.

About Toby Inkster

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