From f72f582111bb4da827ed4fb7a7ff855f6faf9786 Mon Sep 17 00:00:00 2001 From: doy Date: Sun, 7 Dec 2008 00:33:20 -0500 Subject: use $_ for passing the value to coderef matchers, rather than passing it as an argument --- lib/MooseX/Role/Matcher.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/MooseX/Role') diff --git a/lib/MooseX/Role/Matcher.pm b/lib/MooseX/Role/Matcher.pm index b96ece5..fec35c8 100644 --- a/lib/MooseX/Role/Matcher.pm +++ b/lib/MooseX/Role/Matcher.pm @@ -29,7 +29,7 @@ use List::MoreUtils qw/any all/; # does everyone's name start with either J or E? Person->all_match([@people], name => [qr/^J/, qr/^E/]); # find the first person whose name is 4 characters long (using the default) - my $four = Person->first_match([@people], sub { length(shift) == 4 }); + my $four = Person->first_match([@people], sub { length == 4 }); =head1 DESCRIPTION @@ -104,7 +104,10 @@ method _match => sub { return !defined $value if !defined $seek; return 0 if !defined $value; return $value =~ $seek if ref($seek) eq 'Regexp'; - return $seek->($value) if ref($seek) eq 'CODE'; + if (ref($seek) eq 'CODE') { + local $_ = $value; + return $seek->(); + } if (ref($seek) eq 'ARRAY') { for (@$seek) { return 1 if $self->_match($value => $_); -- cgit v1.2.3-54-g00ecf