549a5c661976b760c29885e19dc60ac87c4a1d21
[gitmo/Moose-Policy.git] / t / 001_basic.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 1;
7
8 BEGIN {
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     before '_process_options' => sub {
19         my ($class, $name, $options) = @_;
20         if (exists $options->{is}) {
21                 if ($options->{is} eq 'ro') {
22                         $options->{reader} = 'get_' . $name;
23                 }
24                 elsif ($options->{is} eq 'rw') {
25                 $options->{reader} = 'get_' . $name;                                                    
26                 $options->{writer} = 'set_' . $name;                            
27                 }
28                 delete $options->{is};
29         }
30     };
31 }
32
33
34 {
35     package My::Moose::Policy;
36     use constant attribute_metaclass => 'My::Moose::Meta::Attribute';
37 }
38
39 {
40     package Foo;
41     
42     use Moose::Policy 'My::Moose::Policy';
43     use Moose;
44     
45     has 'bar' => (default => 'Foo::bar');
46 }
47
48
49 my $foo = Foo->new;
50 isa_ok($foo, 'Foo');
51
52 can_ok($foo, 'get_bar');
53 can_ok($foo, 'set_bar');
54
55 is($foo->get_bar, 'Foo::bar', '... got the right default value');
56
57
58
59
60