MANIFEST, Policy POD changes, other misc stuff
[gitmo/Moose-Policy.git] / t / 001_basic.t
CommitLineData
82cfc049 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
bfacd619 6use Test::More 'no_plan';
82cfc049 7
8BEGIN {
b3cebad5 9 use_ok('Moose::Policy');
b14c8df5 10}
11
12{
13 package My::Moose::Meta::Attribute;
14 use Moose;
b3cebad5 15
b14c8df5 16 extends 'Moose::Meta::Attribute';
b3cebad5 17
bfacd619 18 # this method (mostly stolen from M::M::Attribute) just rebuilds the
19 # options so anything with 'is' gets PBP accessors
2756232e 20 before '_process_options' => sub {
b14c8df5 21 my ($class, $name, $options) = @_;
b3cebad5 22 if (exists $options->{is}) {
23 if ($options->{is} eq 'ro') {
24 $options->{reader} = 'get_' . $name;
25 }
26 elsif ($options->{is} eq 'rw') {
27 $options->{reader} = 'get_' . $name;
28 $options->{writer} = 'set_' . $name;
29 }
30 delete $options->{is};
31 }
32
b9238462 33 $class->SUPER::_process_options($name, $options);
34 }
b14c8df5 35}
36
b14c8df5 37{
38 package My::Moose::Policy;
bfacd619 39 # policy just specifies metaclass delegates
5d1afb58 40 use constant attribute_metaclass => 'My::Moose::Meta::Attribute';
41}
42
43{
44 package Foo;
b3cebad5 45
5d1afb58 46 use Moose::Policy 'My::Moose::Policy';
47 use Moose;
b3cebad5 48
c5fc6242 49 has 'bar' => (is => 'rw', default => 'Foo::bar');
bfacd619 50 has 'baz' => (is => 'ro', default => 'Foo::baz');
5d1afb58 51}
52
b9238462 53isa_ok(Foo->meta, 'Moose::Meta::Class');
54is(Foo->meta->attribute_metaclass, 'My::Moose::Meta::Attribute', '... got our custom attr metaclass');
55
7efb3207 56isa_ok(Foo->meta->get_attribute('bar'), 'My::Moose::Meta::Attribute');
5d1afb58 57
58my $foo = Foo->new;
59isa_ok($foo, 'Foo');
60
61can_ok($foo, 'get_bar');
62can_ok($foo, 'set_bar');
63
bfacd619 64can_ok($foo, 'get_baz');
2ae39004 65ok(! $foo->can('set_baz'), 'without setter');
bfacd619 66
5d1afb58 67is($foo->get_bar, 'Foo::bar', '... got the right default value');
bfacd619 68is($foo->get_baz, 'Foo::baz', '... got the right default value');
5d1afb58 69
b3cebad5 70# vim:ts=4:sw=4:et:sta