Fix test warnings.
[gitmo/Moose-Policy.git] / t / 003_saidso.t
CommitLineData
461d2917 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
09eff61e 6use Test::More tests => 22;
461d2917 7
8BEGIN {
9 use_ok('Moose::Policy');
10}
11
12{
13 package My::Moose::Meta::Attribute;
14 use Moose;
15
16 extends 'Moose::Meta::Attribute';
17
18 # this one gives you PBP accessors
19 # and gives you accessors unless you said otherwise
20 sub _process_options {
21 my ($class, $name, $options) = @_;
22 my $is = delete $options->{is} || 'rw';
23 if($is eq 'ro') {
24 $options->{reader} = 'get_' . $name;
25 }
26 elsif($is eq 'rw') {
27 $options->{reader} = 'get_' . $name;
28 $options->{writer} = 'set_' . $name;
29 }
30 elsif($is eq 'no') {
31 # only way to not get accessors
32 }
33 else {
34 # pass it through and let him deal with it
35 $options->{is} = $is;
36 }
37
38 $class->SUPER::_process_options($name, $options);
39 }
40}
41
42{
43 package My::Moose::Policy;
44 # policy just specifies metaclass delegates
45 use constant attribute_metaclass => 'My::Moose::Meta::Attribute';
46}
47
48my $oops;
49{
50 package Foo;
51
52 use Moose::Policy 'My::Moose::Policy';
53 use Moose;
54
55 has 'bar' => (default => 'Foo::bar');
56 has 'baz' => (default => 'Foo::baz');
82a71d18 57 has 'bop' => (is => 'bare', default => 'woot');
461d2917 58 eval { has 'oops' => (is => 'thbbbt'); };
59 $oops = $@;
60}
61
62ok($oops, "thbbt got booted out");
63
64isa_ok(Foo->meta, 'Moose::Meta::Class');
65is(Foo->meta->attribute_metaclass, 'My::Moose::Meta::Attribute', '... got our custom attr metaclass');
66
67isa_ok(Foo->meta->get_attribute('bar'), 'My::Moose::Meta::Attribute');
68
69my $foo = Foo->new;
70isa_ok($foo, 'Foo');
71
72can_ok($foo, 'get_bar');
73can_ok($foo, 'set_bar');
74
75can_ok($foo, 'get_baz');
76can_ok($foo, 'set_baz');
77
78ok(! $foo->can('bop'), 'do not want any bop');
79ok(! $foo->can('get_bop'), 'do not want any bop');
80ok(! $foo->can('set_bop'), 'do not want any bop');
81
82ok(! $foo->can('oops'), 'do not want any oops');
83ok(! $foo->can('get_oops'), 'do not want any oops');
84ok(! $foo->can('set_oops'), 'do not want any oops');
85
86is($foo->get_bar, 'Foo::bar', '... got the right default bar value');
87is($foo->get_baz, 'Foo::baz', '... got the right default baz value');
88ok(exists($foo->{bop}), 'we have bop');
89ok(! exists($foo->{oops}), 'do not want to have an oops');
90is($foo->{bop}, 'woot', '... got the right default bop value');
91
92$foo->set_bar('the new bar');
93is($foo->get_bar, 'the new bar', 'setter works');
94
95# vim:ts=4:sw=4:et:sta
96