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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Test::Moose;
{
package Bar;
use Moose;
}
{
package Foo;
use Moose;
use Bread::Board::Declare;
has foo => (
is => 'ro',
isa => 'Str',
);
has bar => (
is => 'ro',
isa => 'Bar',
service => 0,
);
has baz => (
is => 'ro',
isa => 'Str',
block => sub { shift->param('foo') },
dependencies => ['foo'],
);
has quux => (
is => 'ro',
isa => 'Bar',
block => sub { shift->param('bar') },
dependencies => ['bar'],
);
}
with_immutable {
{
my $foo = Foo->new;
ok($foo->has_service($_), "has service $_") for qw(foo baz);
ok(!$foo->has_service($_), "doesn't have service $_") for qw(bar);
}
{
my $foo = Foo->new;
like(
exception { $foo->baz },
qr/^Attribute foo did not specify a service\. It must be given a value through the constructor or writer method before it can be resolved\./,
"got the right error when foo isn't set"
);
}
{
my $foo = Foo->new(foo => 'bar');
is($foo->baz, 'bar', "didn't get an error when foo is set");
}
{
my $foo = Foo->new;
like(
exception { $foo->quux },
qr/^Could not find container or service for bar in Foo/,
"can't depend on attrs with no service"
);
}
} 'Foo';
done_testing;
|