6 use Test::More tests => 22;
9 use_ok('Moose::Policy');
13 package My::Moose::Meta::Attribute;
16 extends 'Moose::Meta::Attribute';
18 # this one gives you PBP accessors
19 # and gives you accessors unless you said otherwise
20 sub _process_options {
21 my ($class, $name, $options) = @_;
22 my $is = delete $options->{is} || 'rw';
24 $options->{reader} = 'get_' . $name;
27 $options->{reader} = 'get_' . $name;
28 $options->{writer} = 'set_' . $name;
31 # only way to not get accessors
34 # pass it through and let him deal with it
38 $class->SUPER::_process_options($name, $options);
43 package My::Moose::Policy;
44 # policy just specifies metaclass delegates
45 use constant attribute_metaclass => 'My::Moose::Meta::Attribute';
52 use Moose::Policy 'My::Moose::Policy';
55 has 'bar' => (default => 'Foo::bar');
56 has 'baz' => (default => 'Foo::baz');
57 has 'bop' => (is => 'bare', default => 'woot');
58 eval { has 'oops' => (is => 'thbbbt'); };
62 ok($oops, "thbbt got booted out");
64 isa_ok(Foo->meta, 'Moose::Meta::Class');
65 is(Foo->meta->attribute_metaclass, 'My::Moose::Meta::Attribute', '... got our custom attr metaclass');
67 isa_ok(Foo->meta->get_attribute('bar'), 'My::Moose::Meta::Attribute');
72 can_ok($foo, 'get_bar');
73 can_ok($foo, 'set_bar');
75 can_ok($foo, 'get_baz');
76 can_ok($foo, 'set_baz');
78 ok(! $foo->can('bop'), 'do not want any bop');
79 ok(! $foo->can('get_bop'), 'do not want any bop');
80 ok(! $foo->can('set_bop'), 'do not want any bop');
82 ok(! $foo->can('oops'), 'do not want any oops');
83 ok(! $foo->can('get_oops'), 'do not want any oops');
84 ok(! $foo->can('set_oops'), 'do not want any oops');
86 is($foo->get_bar, 'Foo::bar', '... got the right default bar value');
87 is($foo->get_baz, 'Foo::baz', '... got the right default baz value');
88 ok(exists($foo->{bop}), 'we have bop');
89 ok(! exists($foo->{oops}), 'do not want to have an oops');
90 is($foo->{bop}, 'woot', '... got the right default bop value');
92 $foo->set_bar('the new bar');
93 is($foo->get_bar, 'the new bar', 'setter works');
95 # vim:ts=4:sw=4:et:sta