diff options
author | doy <doy@tozt.net> | 2008-12-05 21:48:09 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2008-12-05 21:48:09 -0500 |
commit | 790844762eade061c7bb7854e2dc264202bad479 (patch) | |
tree | 253608873066973f3aeae54f097eeb5b33be29f3 /lib/MooseX/Role | |
parent | 38889135a5f0854f07490c23b2e077e0893bf212 (diff) | |
download | moosex-role-matcher-790844762eade061c7bb7854e2dc264202bad479.tar.gz moosex-role-matcher-790844762eade061c7bb7854e2dc264202bad479.zip |
parameterized!
Diffstat (limited to 'lib/MooseX/Role')
-rw-r--r-- | lib/MooseX/Role/Searchable.pm | 17 |
1 files 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; |