简体   繁体   English

声明MooseX :: ClassAttribute时,“哈希元素的奇数个”

[英]“Odd number of hash elements” when declaring MooseX::ClassAttribute

On OSX 'Mavericks', this: 在OSX'Mavericks'上,这是:

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

... checks clean per 'perl -c': ...根据'perl -c'检查是否干净:

FOO.pm syntax OK FOO.pm语法确定

... but gives this error if I run it simply with 'perl FOO.pm': ...但是如果我仅使用'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. 在/System/Library/Perl/Extras/5.16/MooseX/ClassAttribute.pm第37行的哈希分配中,元素的奇数个数。在/处使用“ strict refs”时,不能将字符串(“ file”)用作HASH ref Library / Perl / 5.16 / darwin-thread-multi-2level / Moose / Meta / Attribute.pm第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.) (这是我能想到的最小的测试用例,但是每当我在模块中使用class_has()时,都会发生错误。)

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. 当您从使用Moose的模块中收到奇怪的错误时,首先要做的是在命令行中运行moose-outdated脚本。 You probably have an outdated MooseX module that's not compatible with the installed version of Moose. 您可能有一个过时的MooseX模块,该模块与已安装的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. 每次升级Moose时,都应该运行moose-outdated Moose,但这很容易忘记,尤其是在升级Moose时,因为它是要安装的其他模块的依赖项之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM