summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-02-02 00:07:49 -0500
committerdoy <doy@tozt.net>2009-02-02 00:07:49 -0500
commit8dc3efef28b5df4ed264fb377b73b14fa93c01c0 (patch)
treee1d034ebc0142d7290d45da0d94073066efdd58c
parentfa37cf1c06839c5d737c32b1fda4224f3217a394 (diff)
downloadmoosex-role-matcher-8dc3efef28b5df4ed264fb377b73b14fa93c01c0.tar.gz
moosex-role-matcher-8dc3efef28b5df4ed264fb377b73b14fa93c01c0.zip
undef values need to be checked against coderef and arrayref match types, since both of those could still succeed
-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);