Commit | Line | Data |
615d5d5f |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More tests => 13; |
5 | use Test::Exception; |
6 | |
7 | do { |
8 | package Class; |
9 | use Mouse; |
10 | |
11 | has array => ( |
12 | is => 'rw', |
13 | isa => 'ArrayRef', |
14 | auto_deref => 1, |
15 | ); |
16 | |
17 | has hash => ( |
18 | is => 'rw', |
19 | isa => 'HashRef', |
20 | auto_deref => 1, |
21 | ); |
22 | }; |
23 | |
24 | my $obj; |
25 | lives_ok { |
26 | $obj = Class->new; |
27 | } qr/auto_deref without defaults don't explode on new/; |
28 | |
29 | my ($array, @array, $hash, %hash); |
30 | lives_ok { |
31 | @array = $obj->array; |
32 | %hash = $obj->hash; |
33 | $array = $obj->array; |
34 | $hash = $obj->hash; |
35 | |
36 | $obj->array; |
37 | $obj->hash; |
38 | } qr/auto_deref without default doesn't explode on get/; |
39 | |
40 | is($obj->array, undef, "array without value is undef in scalar context"); |
41 | is($obj->hash, undef, "hash without value is undef in scalar context"); |
42 | |
43 | TODO: { |
44 | local $TODO = "auto_deref not implemented"; |
45 | is(@array, 0, "array without value is empty in list context"); |
46 | is(keys %hash, 0, "hash without value is empty in list context"); |
47 | }; |
48 | |
49 | @array = $obj->array([1, 2, 3]); |
50 | %hash = $obj->hash({foo => 1, bar => 2}); |
51 | |
52 | TODO: { |
53 | local $TODO = "auto_deref not implemented"; |
54 | is_deeply(\@array, [1, 2, 3], "setter returns the dereferenced list"); |
55 | is_deeply(\%hash, {foo => 1, bar => 2}, "setter returns the dereferenced hash"); |
56 | }; |
57 | |
58 | lives_ok { |
59 | @array = $obj->array; |
60 | %hash = $obj->hash; |
61 | $array = $obj->array; |
62 | $hash = $obj->hash; |
63 | |
64 | $obj->array; |
65 | $obj->hash; |
66 | } qr/auto_deref without default doesn't explode on get/; |
67 | |
68 | is_deeply($array, [1, 2, 3], "auto_deref in scalar context gives the reference"); |
69 | is_deeply($hash, {foo => 1, bar => 2}, "auto_deref in scalar context gives the reference"); |
70 | |
71 | TODO: { |
72 | local $TODO = "auto_deref not implemented"; |
73 | is_deeply(\@array, [1, 2, 3], "auto_deref in list context gives the list"); |
74 | is_deeply(\%hash, {foo => 1, bar => 2}, "auto_deref in list context gives the hash"); |
75 | }; |
76 | |