Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tobyink/5781007 to your computer and use it in GitHub Desktop.
Save tobyink/5781007 to your computer and use it in GitHub Desktop.
#!/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