From 8dc3efef28b5df4ed264fb377b73b14fa93c01c0 Mon Sep 17 00:00:00 2001 From: doy Date: Mon, 2 Feb 2009 00:07:49 -0500 Subject: undef values need to be checked against coderef and arrayref match types, since both of those could still succeed --- lib/MooseX/Role/Matcher.pm | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/MooseX/Role/Matcher.pm b/lib/MooseX/Role/Matcher.pm index 08b822d..765faa1 100644 --- a/lib/MooseX/Role/Matcher.pm +++ b/lib/MooseX/Role/Matcher.pm @@ -156,20 +156,29 @@ method _match => sub { my $value = shift; my $seek = shift; - return !defined $value if !defined $seek; - return 0 if !defined $value; - return $value =~ $seek if ref($seek) eq 'Regexp'; - if (ref($seek) eq 'CODE') { + # first check seek types that could match undef + if (!defined $seek) { + return !defined $value; + } + elsif (ref($seek) eq 'CODE') { local $_ = $value; return $seek->(); } - if (ref($seek) eq 'ARRAY') { + elsif (ref($seek) eq 'ARRAY') { for (@$seek) { return 1 if $self->_match($value => $_); } return 0; } - if (ref($seek) eq 'HASH') { + # then bail out if we still have an undef value + elsif (!defined $value) { + return 0; + } + # and now check seek types that would error with an undef value + elsif (ref($seek) eq 'Regexp') { + return $value =~ $seek; + } + elsif (ref($seek) eq 'HASH') { return 0 unless blessed($value) && $value->does('MooseX::Role::Matcher'); return $value->match(%$seek); -- cgit v1.2.3-54-g00ecf