X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F020_attributes%2F013_attr_dereference_test.t;h=fa788971456e279d027bea722b1b8b2c78a0eb7a;hb=ad3882b59692e4e4eab99f9b183c941e6f63d3bd;hp=bc11931803d409a985507472c106d6ebc04897d2;hpb=e59a5c292a333cac504b65ebd4bba20b5e98d796;p=gitmo%2FMoose.git diff --git a/t/020_attributes/013_attr_dereference_test.t b/t/020_attributes/013_attr_dereference_test.t index bc11931..fa78897 100644 --- a/t/020_attributes/013_attr_dereference_test.t +++ b/t/020_attributes/013_attr_dereference_test.t @@ -3,12 +3,9 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More; use Test::Exception; -BEGIN { - use_ok('Moose'); -} { package Customer; @@ -21,7 +18,7 @@ BEGIN { ::lives_ok { has 'customers' => ( is => 'ro', - isa => subtype('ArrayRef' => where { + isa => subtype('ArrayRef' => where { (blessed($_) && $_->isa('Customer') || return) for @$_; 1 }), auto_deref => 1, ); @@ -55,4 +52,31 @@ BEGIN { [], '... got the right dereferenced value' ); -} \ No newline at end of file +} + +{ + package AutoDeref; + use Moose; + + has 'bar' => ( + is => 'rw', + isa => 'ArrayRef[Int]', + auto_deref => 1, + ); +} + +{ + my $autoderef = AutoDeref->new; + + dies_ok { + $autoderef->bar(1, 2, 3); + } '... its auto-de-ref-ing, not auto-en-ref-ing'; + + lives_ok { + $autoderef->bar([ 1, 2, 3 ]) + } '... set the results of bar correctly'; + + is_deeply [ $autoderef->bar ], [ 1, 2, 3 ], '... auto-dereffed correctly'; +} + +done_testing;