Search code examples
perlmooseclass-attribute

"Odd number of hash elements" when declaring MooseX::ClassAttribute


On OSX 'Mavericks', this:

package FOO;    
use Moose;
use MooseX::ClassAttribute;
class_has 'BAR' => ( is => 'rw' );

... checks clean per 'perl -c':

FOO.pm syntax OK

... but gives this error if I run it simply with 'perl FOO.pm':

Odd number of elements in hash assignment at /System/Library/Perl/Extras/5.16/MooseX/ClassAttribute.pm line 37. Can't use string ("file") as a HASH ref while "strict refs" in use at /Library/Perl/5.16/darwin-thread-multi-2level/Moose/Meta/Attribute.pm line 71.

I've tried every way I can to figure out what's going on here, but I'm stumped. Is there something else I have to 'use' or declare first? (This is the smallest test case I could come up with, but the error happens whenever I use class_has() in a module.)


Solution

  • When you get strange errors from a module that uses Moose, the first thing to do is run the moose-outdated script at the command line. You probably have an outdated MooseX module that's not compatible with the installed version of Moose.

    You should run moose-outdated every time you upgrade Moose, but it's easy to forget, especially when Moose was upgraded because it's one of the dependencies of some other module you're installing.