summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/Role/Matcher.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MooseX/Role/Matcher.pm')
-rw-r--r--lib/MooseX/Role/Matcher.pm21
1 files 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);