From: Shawn M Moore Date: Tue, 10 Jun 2008 05:29:52 +0000 (+0000) Subject: Some errors for auto_deref X-Git-Tag: 0.04~41 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=45ea86205954c36cdc0f1472b5edf519459b2b56;p=gitmo%2FMouse.git Some errors for auto_deref --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 64d3d6e..0d25298 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -162,6 +162,14 @@ sub create { if ref($args{default}) && ref($args{default}) ne 'CODE'; + confess "You cannot auto-dereference without specifying a type constraint on attribute $name" + if $args{auto_deref} && !exists($args{isa}); + + confess "You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute $name" + if $args{auto_deref} + && $args{isa} ne 'ArrayRef' + && $args{isa} ne 'HashRef'; + $args{type_constraint} = delete $args{isa} if exists $args{isa}; diff --git a/t/026-auto-deref.t b/t/026-auto-deref.t index 0edffed..b9a4971 100644 --- a/t/026-auto-deref.t +++ b/t/026-auto-deref.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 13; +use Test::More tests => 15; use Test::Exception; do { @@ -19,6 +19,21 @@ do { isa => 'HashRef', auto_deref => 1, ); + + ::throws_ok { + has any => ( + is => 'rw', + auto_deref => 1, + ); + } qr/You cannot auto-dereference without specifying a type constraint on attribute any/; + + ::throws_ok { + has scalar => ( + is => 'rw', + isa => 'Value', + auto_deref => 1, + ); + } qr/You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute scalar/; }; my $obj;