From: Shawn M Moore Date: Wed, 16 Jul 2008 05:04:45 +0000 (+0000) Subject: Ensure that trigger is always a coderef X-Git-Tag: 0.19~259 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6c5498d0ca72d8da91c411683a78ebaece63fdfa;p=gitmo%2FMouse.git Ensure that trigger is always a coderef --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index df091cc..4237806 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -254,6 +254,10 @@ sub validate_args { && $args{isa} ne 'ArrayRef' && $args{isa} ne 'HashRef'; + confess "Trigger must be a CODE ref on attribute ($name)" + if $args{trigger} + && ref($args{trigger}) ne 'CODE'; + return 1; } diff --git a/t/016-trigger.t b/t/016-trigger.t index 2925a8e..2a4dc94 100644 --- a/t/016-trigger.t +++ b/t/016-trigger.t @@ -20,11 +20,18 @@ do { ); ::lives_ok { - has error => ( + has not_error => ( is => 'ro', trigger => sub { }, ); } "it's no longer an error to have trigger on a readonly attribute"; + + ::throws_ok { + has error => ( + is => 'ro', + trigger => [], + ); + } qr/Trigger must be a CODE ref on attribute \(error\)/; }; can_ok(Class => 'attr');