blob: 3f1c223399b84c6521d954658814edbc91b590e7 (
plain)
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
|
=head1 PURPOSE
Check that basic usage of MooX::late works.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012-2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use warnings;
use Test::More;
{
package Local::Role;
use Moo::Role;
use MooX::late;
has foo => (is => 'ro', isa => 'Str', default => 'foo');
}
{
package Local::Class;
use Moo;
use MooX::late;
with 'Local::Role';
has bar => (is => 'ro', isa => 'Str', default => 'bar');
}
my $o1 = Local::Class->new;
is($o1->foo, 'foo');
is($o1->bar, 'bar');
my $o2 = Local::Class->new(foo => 'bar', bar => 'foo');
is($o2->foo, 'bar');
is($o2->bar, 'foo');
ok not eval {
Local::Class->new(foo => []);
};
ok not eval {
Local::Class->new(bar => []);
};
{
package Local::Other;
use Moo;
use MooX::late;
has foo => (is => 'ro', lazy_build => 1);
sub _build_foo { 'foo' };
}
my $o = Local::Other->new;
ok( not $o->has_foo );
is( $o->foo, 'foo' );
ok( $o->has_foo );
$o->clear_foo;
ok( not $o->has_foo );
done_testing;
|