X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_basic.t;h=867445b924cd97b3958a2f38e2d10b42b5995cf7;hb=c5fc62425bdff217fd1860d24eb42f637217cd44;hp=298e89cdc347a7a403b3a4ec7a47526c34557d25;hpb=82cfc0496fef93b198fc6e6a6f85d102eedacf1f;p=gitmo%2FMoose-Policy.git diff --git a/t/001_basic.t b/t/001_basic.t index 298e89c..867445b 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,8 +3,63 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 8; BEGIN { - use_ok('Moose'); -} \ No newline at end of file + use_ok('Moose::Policy'); +} + +{ + package My::Moose::Meta::Attribute; + use Moose; + + extends 'Moose::Meta::Attribute'; + + sub _process_options { + 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}; + } + + $class->SUPER::_process_options($name, $options); + } +} + +{ + package My::Moose::Policy; + use constant attribute_metaclass => 'My::Moose::Meta::Attribute'; +} + +{ + package Foo; + + use Moose::Policy 'My::Moose::Policy'; + use Moose; + + has 'bar' => (is => 'rw', default => 'Foo::bar'); +} + +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'); + +can_ok($foo, 'get_bar'); +can_ok($foo, 'set_bar'); + +is($foo->get_bar, 'Foo::bar', '... got the right default value'); + + + + +