From 790844762eade061c7bb7854e2dc264202bad479 Mon Sep 17 00:00:00 2001 From: doy Date: Fri, 5 Dec 2008 21:48:09 -0500 Subject: parameterized! --- lib/MooseX/Role/Searchable.pm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/MooseX/Role/Searchable.pm b/lib/MooseX/Role/Searchable.pm index 3ec380a..8ea13e8 100644 --- a/lib/MooseX/Role/Searchable.pm +++ b/lib/MooseX/Role/Searchable.pm @@ -1,9 +1,18 @@ #!/usr/bin/perl package MooseX::Role::Searchable; -use Moose::Role; +use MooseX::Role::Parameterized; use List::Util qw/first/; use List::MoreUtils qw/any apply/; +parameter default_match => ( + is => 'ro', + isa => 'Str', +); + +role { +my $p = shift; +my $default = $p->default_match; + sub _apply_to_matches { my $on_match = shift; my $code = shift; @@ -16,7 +25,7 @@ sub _apply_to_matches { # pass in a regex? return the first item for which the regex matches ID if (ref($matcher) eq 'Regexp') { - return $on_match->(sub { $code->($_) }, (grep { $_->match(identity => $matcher) } @_)); + return $on_match->(sub { $code->($_) }, (grep { $_->match($default => $matcher) } @_)); } my $value = shift; @@ -82,6 +91,8 @@ sub match { return 1; } -no Moose::Role; +}; + +no MooseX::Role::Parameterized; 1; -- cgit v1.2.3-54-g00ecf