2 use warnings FATAL => 'all';
5 use Test::More tests => 8;
8 use Function::Parameters qw(:strict);
9 use Function::Parameters {
10 def => { strict => 1 },
20 $get_message = fun ($value) {
21 "Validation failed for constraint '$name' with value '$value'"
27 get_message => $get_message,
31 method check($value) {
32 $self->{check}($value)
35 method get_message($value) {
36 $self->{get_message}($value)
41 TEvenNum => MyTC->new('even number' => fun ($n) { $n =~ /^[0-9]+\z/ && $n % 2 == 0 }),
42 TShortStr => MyTC->new('short string' => fun ($s) { length($s) < 10 }),
45 fun foo((TEvenNum) $x, (TShortStr) $y) {
49 is foo(42, "hello"), "42/hello";
50 like exception { foo 41, "hello" }, qr{\bValidation failed for constraint 'even number' with value '41'};
51 like exception { foo 42, "1234567890~" }, qr{\bValidation failed for constraint 'short string' with value '1234567890~'};
52 like exception { foo 41, "1234567890~" }, qr{\bValidation failed for constraint 'even number' with value '41'};
54 def foo2((TEvenNum) $x, (TShortStr) $y) {
58 is foo2(42, "hello"), "42/hello";
59 like exception { foo2 41, "hello" }, qr{\bValidation failed for constraint 'even number' with value '41'};
60 like exception { foo2 42, "1234567890~" }, qr{\bValidation failed for constraint 'short string' with value '1234567890~'};
61 like exception { foo2 41, "1234567890~" }, qr{\bValidation failed for constraint 'even number' with value '41'};