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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
use strict;
use warnings;
use Test::More;
use Test::Fatal;
{
package Foo;
sub new {
bless({}, 'Foo')
}
sub a { 'Foo::a' }
$INC{'Foo.pm'} = __FILE__;
}
{
package Bar;
use Moose;
::is( ::exception {
has 'baz' => (
is => 'ro',
isa => 'Foo',
lazy => 1,
default => sub { Foo->new() },
handles => qr/^a$/,
);
}, undef, '... can create the attribute with delegations' );
}
my $bar;
is( exception {
$bar = Bar->new;
}, undef, '... created the object ok' );
isa_ok($bar, 'Bar');
is($bar->a, 'Foo::a', '... got the right delgated value');
my @w;
$SIG{__WARN__} = sub { push @w, "@_" };
{
package Baz;
use Moose;
::is( ::exception {
has 'bar' => (
is => 'ro',
isa => 'Foo',
lazy => 1,
default => sub { Foo->new() },
handles => qr/.*/,
);
}, undef, '... can create the attribute with delegations' );
}
is(@w, 0, "no warnings");
my $baz;
is( exception {
$baz = Baz->new;
}, undef, '... created the object ok' );
isa_ok($baz, 'Baz');
is($baz->a, 'Foo::a', '... got the right delgated value');
@w = ();
{
package Blart;
use Moose;
::is( ::exception {
has 'bar' => (
is => 'ro',
isa => 'Foo',
lazy => 1,
default => sub { Foo->new() },
handles => [qw(a new)],
);
}, undef, '... can create the attribute with delegations' );
}
{
local $TODO = "warning not yet implemented";
is(@w, 1, "one warning");
like($w[0], qr/not delegating.*new/i, "warned");
}
my $blart;
is( exception {
$blart = Blart->new;
}, undef, '... created the object ok' );
isa_ok($blart, 'Blart');
is($blart->a, 'Foo::a', '... got the right delgated value');
done_testing;
|