From: gfx Date: Tue, 2 Feb 2010 03:29:18 +0000 (+0900) Subject: Fix RT #54203 (reported by chocolateboy) that setters might return undef. X-Git-Tag: 0.49~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ca8e67d622c1a14bee4933ad64b1e465c5d63766;p=gitmo%2FMouse.git Fix RT #54203 (reported by chocolateboy) that setters might return undef. --- diff --git a/t/900_bug/004_RT54203.t b/t/900_bug/004_RT54203.t new file mode 100644 index 0000000..3ccab82 --- /dev/null +++ b/t/900_bug/004_RT54203.t @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +# originally mouse_bad.pl, reported by chocolateboy (RT #54203) + +use constant HAS_PATH_CLASS => eval{ require Path::Class }; +use Test::More HAS_PATH_CLASS ? (tests => 4) : (skip_all => 'Testing with Path::Class'); + +package MyClass; + +use Mouse; +use Path::Class qw(file); + +has path => ( + is => 'rw', + isa => 'Str', +); + +sub BUILD { + my $self = shift; + my $path1 = file($0)->stringify; + ::ok(defined $path1, 'file($0)->stringify'); + + $self->path(file($0)->stringify); + my $path2 = $self->path(); + ::ok(defined $path2, '$self->path(file($0)->stringify)'); + + my $path3 = $self->path(file($0)->stringify); + ::ok(defined $path3, 'my $path3 = $self->path(file($0)->stringify)'); +} + +package main; + +my $object = MyClass->new(); +ok defined($object->path); diff --git a/xs-src/Mouse.xs b/xs-src/Mouse.xs index df7ca48..0a7d3f9 100644 --- a/xs-src/Mouse.xs +++ b/xs-src/Mouse.xs @@ -271,7 +271,7 @@ mouse_class_initialize_object(pTHX_ SV* const meta, SV* const object, HV* const if(flags & MOUSEf_ATTR_HAS_TC){ value = mouse_xa_apply_type_constraint(aTHX_ xa, value, flags); } - set_slot(object, slot, value); + value = set_slot(object, slot, value); if(SvROK(value) && flags & MOUSEf_ATTR_IS_WEAK_REF){ weaken_slot(object, slot); } @@ -307,7 +307,7 @@ mouse_class_initialize_object(pTHX_ SV* const meta, SV* const object, HV* const } if(MOUSE_xc_flags(xc) & MOUSEf_XC_IS_ANON){ - set_slot(object, newSVpvs_flags("__METACLASS__", SVs_TEMP), meta); + (void)set_slot(object, newSVpvs_flags("__METACLASS__", SVs_TEMP), meta); } } @@ -439,7 +439,7 @@ CODE: } sv_setsv_mg((SV*)gv, code_ref); /* *gv = $code_ref */ - set_slot(methods, name, code); /* $self->{methods}{$name} = $code */ + (void)set_slot(methods, name, code); /* $self->{methods}{$name} = $code */ /* name the CODE ref if it's anonymous */ { diff --git a/xs-src/MouseAccessor.xs b/xs-src/MouseAccessor.xs index 2d26088..909e595 100644 --- a/xs-src/MouseAccessor.xs +++ b/xs-src/MouseAccessor.xs @@ -132,7 +132,7 @@ mouse_attr_set(pTHX_ SV* const self, MAGIC* const mg, SV* value){ value = mouse_xa_apply_type_constraint(aTHX_ MOUSE_mg_xa(mg), value, flags); } - set_slot(self, slot, value); + value = set_slot(self, slot, value); if(flags & MOUSEf_ATTR_IS_WEAK_REF){ weaken_slot(self, slot); diff --git a/xs-src/MouseTypeConstraints.xs b/xs-src/MouseTypeConstraints.xs index 8b94c85..8188467 100644 --- a/xs-src/MouseTypeConstraints.xs +++ b/xs-src/MouseTypeConstraints.xs @@ -738,6 +738,6 @@ CODE: else{ check = newRV_inc((SV*)mouse_tc_generate(aTHX_ NULL, (check_fptr_t)mouse_types_check, (SV*)checks)); } - set_slots(self, "compiled_type_constraint", check); + (void)set_slots(self, "compiled_type_constraint", check); }