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