Fix RT #54203 (reported by chocolateboy) that setters might return undef.
[gitmo/Mouse.git] / t / 900_bug / 004_RT54203.t
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);