From: sunnavy Date: Tue, 8 Sep 2009 23:27:27 +0000 (+0800) Subject: make auto_deref also handles isa not only ArrayRef and HashRef, but also ArrayRef... X-Git-Tag: 0.32~65 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a3f4f68e59a9f962a72410a3aa1ece6f1f3126b5;p=gitmo%2FMouse.git make auto_deref also handles isa not only ArrayRef and HashRef, but also ArrayRef[Foo::Bar] and HashRef[Foo::Bar] --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 73e8f9e..dfae8b2 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -209,8 +209,7 @@ sub validate_args { 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->{isa} !~ /^(?:ArrayRef|HashRef)(?:\[.*\])?$/; if ($args->{trigger}) { if (ref($args->{trigger}) eq 'HASH') { diff --git a/lib/Mouse/Meta/Method/Accessor.pm b/lib/Mouse/Meta/Method/Accessor.pm index af49197..38531bc 100644 --- a/lib/Mouse/Meta/Method/Accessor.pm +++ b/lib/Mouse/Meta/Method/Accessor.pm @@ -88,7 +88,7 @@ sub generate_accessor_method_inline { } if ($should_deref) { - if (ref($constraint) && $constraint->name eq 'ArrayRef') { + if (ref($constraint) && $constraint->name =~ '^ArrayRef\b') { $accessor .= 'if (wantarray) { return @{ '.$self.'->{'.$key.'} || [] }; }';