more tweaks, I think I want to make this into a role
[gitmo/MooseX-AttributeHelpers.git] / t / 003_basic_hash.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More no_plan => 1;
7
8 BEGIN {
9     use_ok('MooseX::AttributeHelpers');   
10 }
11
12 {
13     package Stuff;
14     use Moose;
15
16     has 'options' => (
17         metaclass => 'Collection::Hash',
18         is        => 'ro',
19         isa       => 'HashRef',
20         default   => sub { {} },
21         provides  => {
22             'set' => 'set_option',
23             'get' => 'get_option',            
24         }
25     );
26 }
27
28 my $stuff = Stuff->new();
29 isa_ok($stuff, 'Stuff');
30
31 is_deeply($stuff->options, {}, '... no options yet');
32
33 $stuff->set_option(foo => 'bar');
34 is_deeply($stuff->options, { foo => 'bar' }, '... got options now');
35
36 $stuff->set_option(bar => 'baz');
37 is_deeply($stuff->options, { foo => 'bar', bar => 'baz' }, '... got more options now');
38
39 is($stuff->get_option('foo'), 'bar', '... got the right option');
40
41
42