diff options
author | doy <doy@tozt.net> | 2008-12-07 00:18:23 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2008-12-07 00:18:23 -0500 |
commit | d856c3ed52aa1ec973f9acfd02f128ddb8e84965 (patch) | |
tree | 222308e2a6a0e6da082e4181c6bf89ca1b6168a7 | |
parent | 254e8b9c08249f1fa8119d49b3eaf2f91c680018 (diff) | |
download | moosex-role-matcher-d856c3ed52aa1ec973f9acfd02f128ddb8e84965.tar.gz moosex-role-matcher-d856c3ed52aa1ec973f9acfd02f128ddb8e84965.zip |
synopsis
-rw-r--r-- | lib/MooseX/Role/Matcher.pm | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/MooseX/Role/Matcher.pm b/lib/MooseX/Role/Matcher.pm index 4ca1f5b..8936640 100644 --- a/lib/MooseX/Role/Matcher.pm +++ b/lib/MooseX/Role/Matcher.pm @@ -8,6 +8,32 @@ use List::MoreUtils qw/any all/; =head1 SYNOPSIS + package Person; + use Moose; + with 'MooseX::Role::Matcher' => { default_match => 'name' }; + + has name => (isa => 'Str'); + has age => (isa => 'Num'); + has phone => (isa => 'Str'); + + package main; + my @people = map { Person->new(name => $_->[0], + age => $_->[1], + phone => $_->[2] } + ['James', 22, '555-1914'], + ['Jesse', 22, '555-6287'], + ['Eric', 21, '555-7634']; + # is James 22? + $people[0]->match(age => 22); + # which people are not 22? + my @not_twenty_two = Person->grep_matches([@people], '!age' => 22); + # do any of the 22-year-olds have a phone number ending in 4? + Person->any_match([@people], age => 22, number => qr/4$/); + # 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 }); + =head1 DESCRIPTION =cut |