X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_basic.t;h=0b50253b0383c28ef440a1b67ee8a768e91accd0;hb=2756232eadcf7f35de9d19a273b16528d487e7e3;hp=549a5c661976b760c29885e19dc60ac87c4a1d21;hpb=5d1afb587de9486c5740ff030d6a60b434634c4a;p=gitmo%2FMoose-Policy.git diff --git a/t/001_basic.t b/t/001_basic.t index 549a5c6..0b50253 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,48 +3,57 @@ 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'; - + + # 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'); +is(Foo->meta->attribute_metaclass, 'My::Moose::Meta::Attribute', '... got our custom attr metaclass'); + +isa_ok(Foo->meta->get_attribute('bar'), 'My::Moose::Meta::Attribute'); my $foo = Foo->new; isa_ok($foo, 'Foo'); @@ -52,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