Commit | Line | Data |
d26633fc |
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', |
c25a396f |
19 | isa => 'HashRef[Str]', |
d26633fc |
20 | default => sub { {} }, |
21 | provides => { |
c25a396f |
22 | 'set' => 'set_option', |
23 | 'get' => 'get_option', |
24 | 'empty' => 'has_options', |
25 | 'count' => 'num_options', |
d26633fc |
26 | } |
27 | ); |
28 | } |
29 | |
30 | my $stuff = Stuff->new(); |
31 | isa_ok($stuff, 'Stuff'); |
32 | |
c25a396f |
33 | can_ok($stuff, $_) for qw[ |
34 | set_option |
35 | get_option |
36 | has_options |
37 | num_options |
38 | ]; |
39 | |
40 | ok(!$stuff->has_options, '... we have no options'); |
41 | is($stuff->num_options, 0, '... we have no options'); |
42 | |
d26633fc |
43 | is_deeply($stuff->options, {}, '... no options yet'); |
44 | |
45 | $stuff->set_option(foo => 'bar'); |
c25a396f |
46 | |
47 | ok($stuff->has_options, '... we have options'); |
48 | is($stuff->num_options, 1, '... we have 1 option(s)'); |
d26633fc |
49 | is_deeply($stuff->options, { foo => 'bar' }, '... got options now'); |
50 | |
51 | $stuff->set_option(bar => 'baz'); |
c25a396f |
52 | |
53 | is($stuff->num_options, 2, '... we have 2 option(s)'); |
d26633fc |
54 | is_deeply($stuff->options, { foo => 'bar', bar => 'baz' }, '... got more options now'); |
55 | |
56 | is($stuff->get_option('foo'), 'bar', '... got the right option'); |
57 | |
58 | |
59 | |