Commit | Line | Data |
82cfc049 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
c5fc6242 |
6 | use Test::More tests => 8; |
82cfc049 |
7 | |
8 | BEGIN { |
b14c8df5 |
9 | use_ok('Moose::Policy'); |
10 | } |
11 | |
12 | { |
13 | package My::Moose::Meta::Attribute; |
14 | use Moose; |
15 | |
16 | extends 'Moose::Meta::Attribute'; |
17 | |
b9238462 |
18 | sub _process_options { |
b14c8df5 |
19 | my ($class, $name, $options) = @_; |
20 | if (exists $options->{is}) { |
21 | if ($options->{is} eq 'ro') { |
22 | $options->{reader} = 'get_' . $name; |
23 | } |
24 | elsif ($options->{is} eq 'rw') { |
25 | $options->{reader} = 'get_' . $name; |
26 | $options->{writer} = 'set_' . $name; |
27 | } |
28 | delete $options->{is}; |
29 | } |
b9238462 |
30 | |
31 | $class->SUPER::_process_options($name, $options); |
32 | } |
b14c8df5 |
33 | } |
34 | |
b14c8df5 |
35 | { |
36 | package My::Moose::Policy; |
5d1afb58 |
37 | use constant attribute_metaclass => 'My::Moose::Meta::Attribute'; |
38 | } |
39 | |
40 | { |
41 | package Foo; |
b14c8df5 |
42 | |
5d1afb58 |
43 | use Moose::Policy 'My::Moose::Policy'; |
44 | use Moose; |
b14c8df5 |
45 | |
c5fc6242 |
46 | has 'bar' => (is => 'rw', default => 'Foo::bar'); |
5d1afb58 |
47 | } |
48 | |
b9238462 |
49 | isa_ok(Foo->meta, 'Moose::Meta::Class'); |
50 | is(Foo->meta->attribute_metaclass, 'My::Moose::Meta::Attribute', '... got our custom attr metaclass'); |
51 | |
7efb3207 |
52 | isa_ok(Foo->meta->get_attribute('bar'), 'My::Moose::Meta::Attribute'); |
5d1afb58 |
53 | |
54 | my $foo = Foo->new; |
55 | isa_ok($foo, 'Foo'); |
56 | |
57 | can_ok($foo, 'get_bar'); |
58 | can_ok($foo, 'set_bar'); |
59 | |
60 | is($foo->get_bar, 'Foo::bar', '... got the right default value'); |
61 | |
62 | |
63 | |
64 | |
65 | |