From: Chris Prather Date: Fri, 27 Mar 2009 22:12:21 +0000 (-0400) Subject: optimize the where logic a bit X-Git-Tag: 0.73_01~42 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cdacfaf381f5ad01b37a6ac069d82fcef38d2eaa;p=gitmo%2FMoose.git optimize the where logic a bit --- diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index daef718..bf70f32 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -362,19 +362,20 @@ sub maybe_type { } sub duck_type { - my ($type_name, @methods) = @_; + my ( $type_name, @methods ) = @_; if ( ref $type_name eq 'ARRAY' && !@methods ) { - @methods = @$type_name; + @methods = @$type_name; $type_name = undef; } register_type_constraint( _create_type_constraint( - $type_name, 'Object', + $type_name, + 'Object', sub { my $obj = $_; - my @missing_methods = grep { !$obj->can($_) } @methods; - return ! scalar @missing_methods; + for (@methods) { return 0 unless $obj->can($_) } + return 1; }, sub { my $obj = $_;