Fix RT #54203 (reported by chocolateboy) that setters might return undef.
gfx [Tue, 2 Feb 2010 03:29:18 +0000 (12:29 +0900)]
t/900_bug/004_RT54203.t [new file with mode: 0644]
xs-src/Mouse.xs
xs-src/MouseAccessor.xs
xs-src/MouseTypeConstraints.xs

diff --git a/t/900_bug/004_RT54203.t b/t/900_bug/004_RT54203.t
new file mode 100644 (file)
index 0000000..3ccab82
--- /dev/null
@@ -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);
index df7ca48..0a7d3f9 100644 (file)
@@ -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 */
     {
index 2d26088..909e595 100644 (file)
@@ -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);
index 8b94c85..8188467 100644 (file)
@@ -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);
 }