Skip Menu |
 

This queue is for tickets about the Object-Tiny-RW CPAN distribution.

Report information
The Basics
Id: 71053
Status: resolved
Worked: 20 min
Priority: 0/
Queue: Object-Tiny-RW

People
Owner: Nobody in particular
Requestors: kmx [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)

Attachments


Subject: 'undef' value cannot be set via accessor
The bug is:

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
Download (untitled) / with headers
text/plain 253b
Thanks. Patch applied and v1.07 on it's way to CPAN. I also resurrected my repo from abandoned place to https://github.com/renormalist/Object-Tiny-RW . Steffen -- Steffen Schwigon <ss5@renormalist.net> Dresden Perl Mongers <http://dresden-pm.org/>


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.