Fix RT #54203 (reported by chocolateboy) that setters might return undef.
[gitmo/Mouse.git] / t / 900_bug / 004_RT54203.t
1 #!/usr/bin/env perl
2 # originally mouse_bad.pl, reported by chocolateboy (RT #54203)
3
4 use constant HAS_PATH_CLASS => eval{ require Path::Class };
5 use Test::More HAS_PATH_CLASS ? (tests => 4) : (skip_all => 'Testing with Path::Class');
6
7 package MyClass;
8
9 use Mouse;
10 use Path::Class qw(file);
11
12 has path => (
13     is  => 'rw',
14     isa => 'Str',
15 );
16
17 sub BUILD {
18     my $self = shift;
19     my $path1 = file($0)->stringify;
20     ::ok(defined $path1, 'file($0)->stringify');
21
22     $self->path(file($0)->stringify);
23     my $path2 = $self->path();
24     ::ok(defined $path2, '$self->path(file($0)->stringify)');
25
26     my $path3 = $self->path(file($0)->stringify);
27     ::ok(defined $path3, 'my $path3 = $self->path(file($0)->stringify)');
28 }
29
30 package main;
31
32 my $object = MyClass->new();
33 ok defined($object->path);