X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_basic.t;h=f83967aeb29abbc3e92ac228fe80899bb481b142;hb=5d492ebf7be74446a747c14eefd9e5068e6069b4;hp=fced7191d1da9c0248b781afccafeb0cadf7eee9;hpb=bfacd619d119a4262f60eadcb431fae0cde270a1;p=gitmo%2FMoose-Policy.git diff --git a/t/001_basic.t b/t/001_basic.t index fced719..f83967a 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,33 +3,40 @@ use strict; use warnings; -use Test::More 'no_plan'; +use Test::More; BEGIN { - use_ok('Moose::Policy'); + require Moose; + + plan skip_all => 'Moose::Policy does not work with recent versions of Moose' + if Moose->VERSION >= 1.05; + + plan tests => 11; + + 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 - sub _process_options { + 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); } } @@ -42,10 +49,10 @@ BEGIN { { package Foo; - + use Moose::Policy 'My::Moose::Policy'; use Moose; - + has 'bar' => (is => 'rw', default => 'Foo::bar'); has 'baz' => (is => 'ro', default => 'Foo::baz'); } @@ -62,11 +69,9 @@ can_ok($foo, 'get_bar'); can_ok($foo, 'set_bar'); 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