From 35d7133e682132e137136fcdb76af19070201466 Mon Sep 17 00:00:00 2001 From: doy Date: Wed, 4 Feb 2009 02:21:21 -0500 Subject: die by default if the method doesn't exist, rather than just failing to match, but allow this to be overridden --- lib/MooseX/Role/Matcher.pm | 7 +++++++ 1 file changed, 7 insertions(+) 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}; -- cgit v1.2.3-54-g00ecf