Created
June 14, 2013 10:54
-
-
Save tobyink/5781007 to your computer and use it in GitHub Desktop.
Based on demo script from http://blogs.perl.org/users/chisel/2011/05/moosextypesstructured---how-i-detest-thee.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
package Thingy; | |
use Moo; | |
use Types::Standard qw(Str Int HashRef ArrayRef Dict Tuple Optional); | |
has payload => ( | |
is => 'rw', | |
isa => ArrayRef[ | |
Dict[ | |
some_id => Int, | |
another_id => Int, | |
some_colour => Str, | |
yet_another_id => Optional[Int], | |
] | |
], | |
); | |
package main; | |
use Try::Tiny; | |
use Data::Dumper; | |
my $thingy = Thingy->new; | |
try { | |
$thingy->payload([ | |
{ some_id => 'Ten' }, | |
]); | |
} | |
catch { | |
warn $_; | |
warn Dumper( $_->explain ); | |
}; | |
warn "Moo: $Moo::VERSION"; | |
warn "Types::Standard: $Types::Standard::VERSION"; | |
__END__ | |
[{"some_id" => "Ten"}] did not pass type constraint "ArrayRef[Dict[another_id=>Int,some_colour=>Str,some_id=>Int,yet_another_id=>Optional[Int]]]" at (eval 237) line 12. | |
$VAR1 = [ | |
'[{"some_id" => "Ten"}] did not pass type constraint "ArrayRef[Dict[another_id=>Int,some_colour=>Str,some_id=>Int,yet_another_id=>Optional[Int]]]"', | |
'"ArrayRef[Dict[another_id=>Int,some_colour=>Str,some_id=>Int,yet_another_id=>Optional[Int]]]" constrains each value in the array with "Dict[another_id=>Int,some_colour=>Str,some_id=>Int,yet_another_id=>Optional[Int]]"', | |
'{"some_id" => "Ten"} did not pass type constraint "Dict[another_id=>Int,some_colour=>Str,some_id=>Int,yet_another_id=>Optional[Int]]" (in $_->[0])', | |
'"Dict[another_id=>Int,some_colour=>Str,some_id=>Int,yet_another_id=>Optional[Int]]" requires key "another_id" to appear in hash' | |
]; | |
Moo: 1.002 at ./scratch.pl line 35. | |
Types::Standard: 0.007_05 at ./scratch.pl line 36. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment