Subject: | 'undef' value cannot be set via accessor |
The bug is:
Show quoted text
Show quoted text
#at this point $o->attribute is still 1
The patch including test for this case is attached.
--
kmx
Show quoted text
# My::Class is using Object::Tiny::RW
$o = My::Class->new( attribute=>1 );Show quoted text
#...
$o->attribute(undef);#at this point $o->attribute is still 1
The patch including test for this case is attached.
--
kmx
Subject: | Object-Tiny-RW-1.06.patch |
diff -ru Object-Tiny-RW-1.06.orig/lib/Object/Tiny/RW.pm Object-Tiny-RW-1.06/lib/Object/Tiny/RW.pm
--- Object-Tiny-RW-1.06.orig/lib/Object/Tiny/RW.pm Thu Sep 17 17:22:36 2009
+++ Object-Tiny-RW-1.06/lib/Object/Tiny/RW.pm Sun Sep 18 20:32:17 2011
@@ -16,7 +16,7 @@
map {
defined and ! ref and /^[^\W\d]\w*$/s
or die "Invalid accessor name '$_'";
- "sub $_ { if (defined \$_[1]) { \$_[0]->{$_} = \$_[1] } ; return \$_[0]->{$_} }\n"
+ "sub $_ { if (\@_ > 1) { \$_[0]->{$_} = \$_[1] } ; return \$_[0]->{$_} }\n"
} @_;
die "Failed to generate $pkg" if $@;
return 1;
diff -ru Object-Tiny-RW-1.06.orig/t/02_main.t Object-Tiny-RW-1.06/t/02_main.t
--- Object-Tiny-RW-1.06.orig/t/02_main.t Thu Sep 17 16:51:06 2009
+++ Object-Tiny-RW-1.06/t/02_main.t Sun Sep 18 20:34:10 2011
@@ -7,7 +7,7 @@
$^W = 1;
}
-use Test::More tests => 13;
+use Test::More tests => 14;
# Define a class
SCOPE: {
@@ -42,6 +42,8 @@
is( $object->{baz}, 3, '->{baz} does contain value' );
$object->foo(42);
is( $object->foo, 42, '->foo(new_value) ok' );
+ $object->bar(undef);
+ is( $object->bar, undef, '->bar(new_value) ok' );
}
# Trigger the constructor exception