diff options
author | doy <doy@tozt.net> | 2009-02-04 02:21:21 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2009-02-04 02:21:21 -0500 |
commit | 35d7133e682132e137136fcdb76af19070201466 (patch) | |
tree | a9c8cf81e3500d23e01c8e6e57fbcc299764892a | |
parent | df3abd2f97edefab7f86ef4ee0d0779d7744bc7a (diff) | |
download | moosex-role-matcher-35d7133e682132e137136fcdb76af19070201466.tar.gz moosex-role-matcher-35d7133e682132e137136fcdb76af19070201466.zip |
die by default if the method doesn't exist, rather than just failing to match, but allow this to be overridden
-rw-r--r-- | lib/MooseX/Role/Matcher.pm | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/MooseX/Role/Matcher.pm b/lib/MooseX/Role/Matcher.pm index d8755a8..0b3468d 100644 --- a/lib/MooseX/Role/Matcher.pm +++ b/lib/MooseX/Role/Matcher.pm @@ -74,9 +74,14 @@ parameter default_match => ( isa => 'Str', ); +parameter allow_missing_methods => ( + isa => 'Bool', +); + role { my $p = shift; my $default = $p->default_match; +my $allow_missing_methods = $p->allow_missing_methods; method _apply_to_matches => sub { my $class = shift; @@ -244,6 +249,8 @@ method match => sub { # immediately if a false condition is found. for my $matcher (keys %args) { my ($invert, $name) = $matcher =~ /^(!)?(.*)$/; + confess blessed($self) . " has no method named $name" + unless $self->can($name) || $allow_missing_methods; my $value = $self->can($name) ? $self->$name : undef; my $seek = $args{$matcher}; |