summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2008-12-06 23:11:06 -0500
committerdoy <doy@tozt.net>2008-12-06 23:11:06 -0500
commitfe814d63a053867c38e9b22c449475ea1573f02e (patch)
treeb91941f2af415ed8c3e63e2bc666e830221dfbcf
parent108c4ab3669e263875df3fb68dc8e2edf7783ef2 (diff)
downloadmoosex-role-matcher-fe814d63a053867c38e9b22c449475ea1573f02e.tar.gz
moosex-role-matcher-fe814d63a053867c38e9b22c449475ea1573f02e.zip
add all_match
-rw-r--r--lib/MooseX/Role/Matcher.pm7
-rw-r--r--t/100-collection.t9
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/MooseX/Role/Matcher.pm b/lib/MooseX/Role/Matcher.pm
index d4731cc..0bb4ce0 100644
--- a/lib/MooseX/Role/Matcher.pm
+++ b/lib/MooseX/Role/Matcher.pm
@@ -2,7 +2,7 @@
package MooseX::Role::Matcher;
use MooseX::Role::Parameterized;
use List::Util qw/first/;
-use List::MoreUtils qw/any/;
+use List::MoreUtils qw/any all/;
parameter default_match => (
is => 'ro',
@@ -38,6 +38,11 @@ method any_match => sub {
$class->_apply_to_matches(\&any, @_);
};
+method all_match => sub {
+ my $class = shift;
+ $class->_apply_to_matches(\&all, @_);
+};
+
method _match => sub {
my $self = shift;
my $value = shift;
diff --git a/t/100-collection.t b/t/100-collection.t
index ed360fe..02b1a61 100644
--- a/t/100-collection.t
+++ b/t/100-collection.t
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More tests => 4;
use Test::Deep;
package Foo;
@@ -33,6 +33,11 @@ sub any_match {
Foo->any_match($self->foos, @_);
}
+sub all_match {
+ my $self = shift;
+ Foo->all_match($self->foos, @_);
+}
+
sub grep_matches {
my $self = shift;
Foo->grep_matches($self->foos, @_);
@@ -50,5 +55,7 @@ is($foos->first_match(a => ''), $foo2,
'first_match works');
ok(!$foos->any_match(b => qr/z/),
'any_match works');
+ok($foos->all_match(c => qr/[^bf]/),
+ 'all_match works');
cmp_deeply([$foos->grep_matches(c => qr/o/)], set(shallow($foo2), shallow($foo3)),
'grep_matches works');