Skip Menu |

This queue is for tickets about the Class-Std CPAN distribution.

Report information
The Basics
Id: 13824
Status: resolved
Priority: 0/
Queue: Class-Std

People
Owner: Nobody in particular
Requestors: chromatic [...] wgz.org
Cc:
AdminCc:

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



Subject: Allow False Values as Attribute Parameters
This patch fixes an apparent bug where passing a false value (such as zero or the empty string) to an object's constructor fails the assignment. Perhaps rule #257 should be "Don't forget that assignments can succeed but return false values!" :)
diff -ur lib/Class/Std.pm~ /lib/Class/Std.pm --- lib/Class/Std.pm~ 2005-05-25 15:29:20.000000000 -0700 +++ lib/Class/Std.pm 2005-07-21 17:55:15.000000000 -0700 @@ -327,8 +327,8 @@ # Get arg from initializer list... next INIT if defined $attr_ref->{ref}{$new_obj_id}; if (defined $attr_ref->{init_arg}) { - $attr_ref->{ref}{$new_obj_id} = $arg_set{$attr_ref->{init_arg}} - and next INIT; + $attr_ref->{ref}{$new_obj_id} = $arg_set{$attr_ref->{init_arg}}; + next INIT; } diff -ur t/simple.t~ /t/simple.t --- t/simple.t~ 2005-05-15 20:58:24.000000000 -0700 +++ /t/simple.t 2005-07-21 17:57:20.000000000 -0700 @@ -119,3 +119,19 @@ eval { $derobj->setname('new name') }; ok $@ =~ m/\ACan't locate object method "setname" via package "Der"/ => 'Read only name attribute'; + +my $der2 = Der->new({ + name => 'MyBase::name', + snum => 'MyBase::snum', + rank => 'generic rank', + priv => 'generic priv', + MyBase => { + rank => 'MyBase::rank', + priv => 'MyBase::priv', + }, + Der => { + snum => 0, + priv => 'Der::priv', + }, +}); +is( $der2->get_snum(), 0, 'false values allowable as attribute parameters' );