more tweaks, I think I want to make this into a role
[gitmo/MooseX-AttributeHelpers.git] / t / 002_basic_collection.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::Array',
18         is        => 'ro',
19         isa       => 'ArrayRef',
20         default   => sub { [] },
21         provides  => {
22             'push' => 'add_options',
23             'pop'  => 'remove_last_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->add_options(1, 2, 3);
34 is_deeply($stuff->options, [1, 2, 3], '... got options now');
35
36 $stuff->add_options(10, 15);
37 is_deeply($stuff->options, [1, 2, 3, 10, 15], '... got more options now');
38
39 is($stuff->remove_last_option, 15, '... removed the last option');
40
41 is_deeply($stuff->options, [1, 2, 3, 10], '... got diff options now');
42
43
44