From: gfx Date: Sat, 9 Jan 2010 07:54:42 +0000 (+0900) Subject: Apply a patch to support handle => sub { ... }, contributed by Frank Cuny. X-Git-Tag: 0.46~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7bc014283bca353a4d7a0019a0d49d4d7b11bd84;p=gitmo%2FMouse.git Apply a patch to support handle => sub { ... }, contributed by Frank Cuny. --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 41d80a6..61e9dba 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -412,6 +412,11 @@ sub _canonicalize_handles { elsif (ref($handles) eq 'ARRAY') { return map { $_ => $_ } @$handles; } + elsif ( ref($handles) eq 'CODE' ) { + my $class_or_role = ( $self->{isa} || $self->{does} ) + || $self->throw_error( "Cannot find delegate metaclass for attribute " . $self->name ); + return $handles->( $self, Mouse::Meta::Class->initialize("$class_or_role")); + } elsif (ref($handles) eq 'Regexp') { my $class_or_role = ($self->{isa} || $self->{does}) || $self->throw_error("Cannot delegate methods based on a Regexp without a type constraint (isa)"); diff --git a/t/020_attributes/011_more_attr_delegation.t b/t/020_attributes/011_more_attr_delegation.t index 15f8e6a..75d6fa1 100644 --- a/t/020_attributes/011_more_attr_delegation.t +++ b/t/020_attributes/011_more_attr_delegation.t @@ -123,9 +123,6 @@ do not fail at compile time. ); } "can't create attr with generative handles parameter and no isa"; - our $TODO; -{ - local $TODO = 'handles => CODE is not supported'; ::lives_ok { has child_d => ( isa => "ChildD", @@ -137,7 +134,6 @@ do not fail at compile time. } ); } "can't create attr with generative handles parameter and no isa"; -} ::lives_ok { has child_e => ( @@ -148,8 +144,6 @@ do not fail at compile time. ); } "can delegate to non moose class using explicit method list"; -{ - local $TODO = 'handles => CODE is not supported'; my $delegate_class; ::lives_ok { has child_f => ( @@ -164,7 +158,6 @@ do not fail at compile time. } "subrefs on non moose class give no meta"; ::is( $delegate_class, "ChildF", "plain classes are handed down to subs" ); -} ::lives_ok { has child_g => (