Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Created July 1, 2010 14:29
Show Gist options
  • Save jjn1056/460032 to your computer and use it in GitHub Desktop.
Save jjn1056/460032 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Test::More;
use Moose::Util::TypeConstraints;
use MooseX::Types::Structured qw(Dict Tuple);
use MooseX::Types::Moose qw(Int);
my $deeper_tc = subtype
as Dict[
a => Tuple[
Dict[
a1a => Tuple[Int],
a1b => Tuple[Int],
],
Dict[
a2a => Tuple[Int],
a2b => Tuple[Int],
],
],
b => Tuple[
Dict[
b1a => Tuple[Int],
b1b => Tuple[Int],
],
Dict[
b2a => Tuple[Int],
b2b => Tuple[Int],
],
],
];
my $struc_to_validate = {
a=>[
{
a1a=>[1],
a1b=>[2]
},
{
a2a=>[3],
a2b=>[4]
}
],
b=>[
{
b1a=>[5],
b1b=>['AA']
},
{
b2a=>[7],
b2b=>[8]
}
]
};
ok my $message = $deeper_tc->validate($struc_to_validate),
'got error message of some sort';
done_testing();
warn $message;
## And the output of the warn is:
John-Napiorkowski-MacBook-Pro:MooseX-Types-Structured johnn$ prove -lvr t/13-deeper_error.t
t/13-deeper_error.t ..
ok 1 - got error message of some sort
1..1
Validation failed for '__ANON__' with value { a: [ HASH(0x100826b38), HASH(0x100bec748) ], b: [ HASH(0x100be8e90), HASH(0x100be5348) ] }, Internal Validation Error is:
[+] Validation failed for 'Tuple[Dict[b1a,Tuple[Int],b1b,Tuple[Int]],Dict[b2a,Tuple[Int],b2b,Tuple[Int]]]' with value [ { b1a: ARRAY(0x100be69c0), b1b: ARRAY(0x100be2630) }, { b2a: ARRAY(0x100be8d70), b2b: ARRAY(0x100be5a78) } ]
[+] Validation failed for 'Dict[b1a,Tuple[Int],b1b,Tuple[Int]]' with value { b1a: [ 5 ], b1b: [ "AA" ] }
[+] Validation failed for 'Tuple[Int]' with value [ "AA" ]
[+] Validation failed for 'Int' with value AA at t/13-deeper_error.t line 61.
ok
All tests successful.
Files=1, Tests=1, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.26 cusr 0.03 csys = 0.32 CPU)
Result: PASS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment