Permalink
Browse files

Merge pull request #14 from melo/is-ro-error-message

Add proper error message when calling setter on a is ro attr
  • Loading branch information...
2 parents 1556a1e + 9a5f60e commit b97869f0ea342416d97f3054781d157694940355 @Leont Leont committed Apr 19, 2012
Showing with 3 additions and 3 deletions.
  1. +1 −1 lib/Mo/is.pm
  2. +1 −1 src/Mo/is.pm
  3. +1 −1 t/is.t
View
@@ -1,3 +1,3 @@
package Mo::is;$M="Mo::";
$VERSION=0.30;
-*{$M.'is::e'}=sub{my($P,$e,$o)=@_;$o->{is}=sub{my($m,$n,%a)=@_;$a{is}or return$m;sub{$#_&&$a{is}eq 'ro'&&caller ne 'Mo::coerce'?die:$m->(@_)}}};
+*{$M.'is::e'}=sub{my($P,$e,$o)=@_;$o->{is}=sub{my($m,$n,%a)=@_;$a{is}or return$m;sub{$#_&&$a{is}eq 'ro'&&caller ne 'Mo::coerce'?die$n.' is ro':$m->(@_)}}};
View
@@ -8,7 +8,7 @@ $VERSION = 0.30;
$args{is} or return $method;
sub {
$#_ && $args{is} eq 'ro' && caller ne 'Mo::coerce'
- ? die
+ ? die $name.' is ro'
: $method->(@_)
};
};
View
2 t/is.t
@@ -12,4 +12,4 @@ package main;
my $f = Foo::is->new(stuff => 'foo');
is $f->stuff, 'foo', 'values passed to constructor are successfully accepted';
eval { $f->stuff('barbaz') };
-ok $@, 'setting values after initialization throws an exception';
+like $@, qr{^stuff is ro}, 'setting values after initialization throws an exception';

0 comments on commit b97869f

Please sign in to comment.