projects
/
gitmo/Mouse.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
(parent:
c0085d1
)
Ensure that trigger is always a coderef
Shawn M Moore [Wed, 16 Jul 2008 05:04:45 +0000 (
05:04
+0000)]
lib/Mouse/Meta/Attribute.pm
patch
|
blob
|
blame
|
history
t/016-trigger.t
patch
|
blob
|
blame
|
history
diff --git
a/lib/Mouse/Meta/Attribute.pm
b/lib/Mouse/Meta/Attribute.pm
index
df091cc
..
4237806
100644
(file)
--- 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
(file)
--- 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');