11 plan skip_all => 'Moose::Policy does not work with recent versions of Moose'
12 if Moose->VERSION >= 1.05;
16 use_ok('Moose::Policy');
20 package My::Moose::Meta::Attribute;
23 extends 'Moose::Meta::Attribute';
25 # this one gives you PBP accessors
26 # and gives you accessors unless you said otherwise
27 sub _process_options {
28 my ($class, $name, $options) = @_;
29 my $is = delete $options->{is} || 'rw';
31 $options->{reader} = 'get_' . $name;
34 $options->{reader} = 'get_' . $name;
35 $options->{writer} = 'set_' . $name;
38 # only way to not get accessors
41 # pass it through and let him deal with it
45 $class->SUPER::_process_options($name, $options);
50 package My::Moose::Policy;
51 # policy just specifies metaclass delegates
52 use constant attribute_metaclass => 'My::Moose::Meta::Attribute';
59 use Moose::Policy 'My::Moose::Policy';
62 has 'bar' => (default => 'Foo::bar');
63 has 'baz' => (default => 'Foo::baz');
64 has 'bop' => (is => 'bare', default => 'woot');
65 eval { has 'oops' => (is => 'thbbbt'); };
69 ok($oops, "thbbt got booted out");
71 isa_ok(Foo->meta, 'Moose::Meta::Class');
72 is(Foo->meta->attribute_metaclass, 'My::Moose::Meta::Attribute', '... got our custom attr metaclass');
74 isa_ok(Foo->meta->get_attribute('bar'), 'My::Moose::Meta::Attribute');
79 can_ok($foo, 'get_bar');
80 can_ok($foo, 'set_bar');
82 can_ok($foo, 'get_baz');
83 can_ok($foo, 'set_baz');
85 ok(! $foo->can('bop'), 'do not want any bop');
86 ok(! $foo->can('get_bop'), 'do not want any bop');
87 ok(! $foo->can('set_bop'), 'do not want any bop');
89 ok(! $foo->can('oops'), 'do not want any oops');
90 ok(! $foo->can('get_oops'), 'do not want any oops');
91 ok(! $foo->can('set_oops'), 'do not want any oops');
93 is($foo->get_bar, 'Foo::bar', '... got the right default bar value');
94 is($foo->get_baz, 'Foo::baz', '... got the right default baz value');
95 ok(exists($foo->{bop}), 'we have bop');
96 ok(! exists($foo->{oops}), 'do not want to have an oops');
97 is($foo->{bop}, 'woot', '... got the right default bop value');
99 $foo->set_bar('the new bar');
100 is($foo->get_bar, 'the new bar', 'setter works');
102 # vim:ts=4:sw=4:et:sta