所以我有这个小草图,试图获得子类型的悬念:
#!/usr/bin/perl
#
use strict;
use warnings;
package Foo;
use Moose;
use Moose::Util::TypeConstraints;
use Data::Dumper;
subtype 'ArrayRefOfHashrefs' => as 'ArrayRef[Hashref]';
has 'thingy' => ( 'is' => 'ro', 'isa' => 'ArrayRefOfHashrefs' );
package main;
my $foo = Foo->new('thingy' => [{ 'id' => 12 }]);
# The above produces:
use Data::Dumper;
print Dumper $foo->thingy;
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,我得到:
属性(thingy)不传递类型约束,因为:对于'ArrayRefOfHashrefs',值为ARRAY(0x7fda83028e08)的值为/[PATH] /site_perl/5.18.4/darwin2level/Moose/Object.pm第24行的验证失败
Moose :: Object :: new('Foo','thingy','ARRAY(0x7fda83028e08)')在../sketches/arrayrefofhashrefs.pl第17行调用
我究竟做错了什么?
| 归档时间: |
|
| 查看次数: |
42 次 |
| 最近记录: |