X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_basic.t;h=0b50253b0383c28ef440a1b67ee8a768e91accd0;hb=2756232eadcf7f35de9d19a273b16528d487e7e3;hp=618b56ab0398179e9c5b96b8a799e38767bdd3c1;hpb=7efb32071f3f1526e3d64c30cf2afd224c9408b7;p=gitmo%2FMoose-Policy.git diff --git a/t/001_basic.t b/t/001_basic.t index 618b56a..0b50253 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,47 +3,51 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More 'no_plan'; BEGIN { - use_ok('Moose::Policy'); + use_ok('Moose::Policy'); } { package My::Moose::Meta::Attribute; use Moose; - + extends 'Moose::Meta::Attribute'; - - sub _process_options { + + # this method (mostly stolen from M::M::Attribute) just rebuilds the + # options so anything with 'is' gets PBP accessors + before '_process_options' => sub { my ($class, $name, $options) = @_; - if (exists $options->{is}) { - if ($options->{is} eq 'ro') { - $options->{reader} = 'get_' . $name; - } - elsif ($options->{is} eq 'rw') { - $options->{reader} = 'get_' . $name; - $options->{writer} = 'set_' . $name; - } - delete $options->{is}; - } - + if (exists $options->{is}) { + if ($options->{is} eq 'ro') { + $options->{reader} = 'get_' . $name; + } + elsif ($options->{is} eq 'rw') { + $options->{reader} = 'get_' . $name; + $options->{writer} = 'set_' . $name; + } + delete $options->{is}; + } + $class->SUPER::_process_options($name, $options); } } { package My::Moose::Policy; + # policy just specifies metaclass delegates use constant attribute_metaclass => 'My::Moose::Meta::Attribute'; } { package Foo; - + use Moose::Policy 'My::Moose::Policy'; use Moose; - - has 'bar' => (default => 'Foo::bar'); + + has 'bar' => (is => 'rw', default => 'Foo::bar'); + has 'baz' => (is => 'ro', default => 'Foo::baz'); } isa_ok(Foo->meta, 'Moose::Meta::Class'); @@ -57,9 +61,10 @@ isa_ok($foo, 'Foo'); can_ok($foo, 'get_bar'); can_ok($foo, 'set_bar'); -is($foo->get_bar, 'Foo::bar', '... got the right default value'); - - - +can_ok($foo, 'get_baz'); +ok(! $foo->can('set_baz'), 'without setter'); +is($foo->get_bar, 'Foo::bar', '... got the right default value'); +is($foo->get_baz, 'Foo::baz', '... got the right default value'); +# vim:ts=4:sw=4:et:sta