summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2008-12-07 00:47:26 -0500
committerdoy <doy@tozt.net>2008-12-07 00:47:26 -0500
commit3af700804cef2e274364ab78d588a2b51f05e080 (patch)
tree3b4f6bee77ad6e842646a4a349cb4b15ee2fb5b7
parentf72f582111bb4da827ed4fb7a7ff855f6faf9786 (diff)
downloadmoosex-role-matcher-3af700804cef2e274364ab78d588a2b51f05e080.tar.gz
moosex-role-matcher-3af700804cef2e274364ab78d588a2b51f05e080.zip
synopsis cleanups, from sartak
-rw-r--r--lib/MooseX/Role/Matcher.pm11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/MooseX/Role/Matcher.pm b/lib/MooseX/Role/Matcher.pm
index fec35c8..b54e490 100644
--- a/lib/MooseX/Role/Matcher.pm
+++ b/lib/MooseX/Role/Matcher.pm
@@ -12,22 +12,27 @@ use List::MoreUtils qw/any all/;
use Moose;
with 'MooseX::Role::Matcher' => { default_match => 'name' };
- has name => (isa => 'Str');
- has age => (isa => 'Num');
- has phone => (isa => 'Str');
+ has name => (is => 'ro', isa => 'Str');
+ has age => (is => 'ro', isa => 'Num');
+ has phone => (is => 'ro', isa => 'Str');
package main;
my @people = (Person->new(name => 'James', age => 22, phone => '555-1914'),
Person->new(name => 'Jesse', age => 22, phone => '555-6287'),
Person->new(name => 'Eric', age => 21, phone => '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 == 4 });