1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Test::Moose;
{
package Foo;
use Moose;
use Bread::Board::Declare;
has foo => (
is => 'ro',
isa => 'Ref',
value => 'FOO',
);
has bar => (
is => 'ro',
isa => 'Str',
block => sub { {} },
);
has baz => (
is => 'ro',
isa => 'HashRef',
block => sub { shift->param('bar') },
dependencies => ['bar'],
);
}
with_immutable {
my $foo = Foo->new;
like(exception { $foo->foo },
qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Ref' with value FOO/,
"error when service returns invalid value");
like(exception { $foo->bar },
qr/^Attribute \(bar\) does not pass the type constraint because: Validation failed for 'Str' with value HASH/,
"error when service returns invalid value");
like(exception { $foo->baz },
qr/^Attribute \(bar\) does not pass the type constraint because: Validation failed for 'Str' with value HASH/,
"error when service returns invalid value, even as a dependency");
} 'Foo';
done_testing;
|