diff options
-rw-r--r-- | lib/MooseX/Role/Matcher.pm | 7 | ||||
-rw-r--r-- | t/100-collection.t | 9 |
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'); |