Commit | Line | Data |
461dc6d3 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
5d492ebf |
6 | use Test::More; |
461dc6d3 |
7 | |
8 | BEGIN { |
5d492ebf |
9 | require Moose; |
10 | |
11 | plan skip_all => 'Moose::Policy does not work with recent versions of Moose' |
12 | if Moose->VERSION >= 1.05; |
13 | |
14 | plan tests => 28; |
15 | |
461dc6d3 |
16 | use_ok('Moose::Policy'); |
17 | } |
18 | |
19 | { |
20 | package Foo; |
21 | |
22 | use Moose::Policy 'Moose::Policy::FollowPBP'; |
23 | use Moose; |
24 | |
25 | has 'bar' => (is => 'rw', default => 'Foo::bar'); |
26 | has 'baz' => (is => 'ro', default => 'Foo::baz'); |
27 | } |
28 | |
29 | isa_ok(Foo->meta, 'Moose::Meta::Class'); |
30 | is(Foo->meta->attribute_metaclass, 'Moose::Policy::FollowPBP::Attribute', '... got our custom attr metaclass'); |
31 | |
32 | isa_ok(Foo->meta->get_attribute('bar'), 'Moose::Policy::FollowPBP::Attribute'); |
33 | |
34 | my $foo = Foo->new; |
35 | isa_ok($foo, 'Foo'); |
36 | |
37 | can_ok($foo, 'get_bar'); |
38 | can_ok($foo, 'set_bar'); |
39 | |
40 | can_ok($foo, 'get_baz'); |
41 | ok(! $foo->can('set_baz'), 'without setter'); |
42 | |
43 | is($foo->get_bar, 'Foo::bar', '... got the right default value'); |
44 | is($foo->get_baz, 'Foo::baz', '... got the right default value'); |
45 | |
09eff61e |
46 | { |
47 | package Bar; |
48 | use Moose::Policy 'Moose::Policy::FollowPBP'; |
49 | use Moose; |
50 | |
51 | extends 'Foo'; |
52 | |
53 | has 'boing' => (is => 'rw', default => 'Bar::boing'); |
54 | } |
55 | |
56 | isa_ok(Bar->meta, 'Moose::Meta::Class'); |
57 | is(Bar->meta->attribute_metaclass, 'Moose::Policy::FollowPBP::Attribute', '... got our custom attr metaclass'); |
58 | |
59 | isa_ok(Bar->meta->get_attribute('boing'), 'Moose::Policy::FollowPBP::Attribute'); |
60 | |
61 | my $bar = Bar->new; |
62 | isa_ok($bar, 'Bar'); |
63 | isa_ok($bar, 'Foo'); |
64 | |
65 | can_ok($bar, 'get_boing'); |
66 | can_ok($bar, 'set_boing'); |
67 | |
68 | is($bar->get_boing, 'Bar::boing', '... got the right default value'); |
69 | $bar->set_boing('Woot!'); |
70 | is($bar->get_boing, 'Woot!', '... got the right changed value'); |
71 | |
72 | { |
73 | package Baz; |
74 | use Moose; |
75 | |
76 | extends 'Bar'; |
77 | |
78 | has 'bling' => (is => 'ro', default => 'Baz::bling'); |
79 | } |
80 | |
81 | isa_ok(Baz->meta, 'Moose::Meta::Class'); |
82 | is(Baz->meta->attribute_metaclass, 'Moose::Meta::Attribute', '... got our custom attr metaclass'); |
83 | |
84 | isa_ok(Baz->meta->get_attribute('bling'), 'Moose::Meta::Attribute'); |
85 | |
86 | my $baz = Baz->new; |
87 | isa_ok($baz, 'Baz'); |
88 | isa_ok($baz, 'Bar'); |
89 | isa_ok($baz, 'Foo'); |
90 | |
91 | can_ok($baz, 'bling'); |
92 | |
93 | is($baz->bling, 'Baz::bling', '... got the right default value'); |