2 use warnings FATAL => 'all';
5 use Test::More tests => 4;
8 use Function::Parameters qw(:strict);
17 $get_message = fun ($value) {
18 "Validation failed for constraint '$name' with value '$value'"
24 get_message => $get_message,
28 method check($value) {
29 $self->{check}($value)
32 method get_message($value) {
33 $self->{get_message}($value)
38 TEvenNum => MyTC->new('even number' => fun ($n) { $n =~ /^[0-9]+\z/ && $n % 2 == 0 }),
39 TShortStr => MyTC->new('short string' => fun ($s) { length($s) < 10 }),
42 fun foo((TEvenNum) $x, (TShortStr) $y) {
46 is foo(42, "hello"), "42/hello";
47 like exception { foo 41, "hello" }, qr{\bValidation failed for constraint 'even number' with value '41'};
48 like exception { foo 42, "1234567890~" }, qr{\bValidation failed for constraint 'short string' with value '1234567890~'};
49 like exception { foo 41, "1234567890~" }, qr{\bValidation failed for constraint 'even number' with value '41'};