Add a test file for RT #53286
[gitmo/Mouse.git] / t / 900_bug / 004_RT53286.t
1 #!perl -w
2 # reported by Christine Spang (RT #53286)
3 package Foo;
4 use Mouse;
5
6 has app_handle => (
7     is       => 'rw',
8     isa      => 'Baz',
9     required => 1,
10 );
11
12 has handle => (
13     is       => 'rw',
14     isa      => 'Int',
15     # app_handle should not be undef here!
16     default  => sub { shift->app_handle->handle() },
17 );
18
19 no Mouse;
20
21 1;
22
23 package Bar;
24 use Mouse;
25
26 has app_handle => (
27     is       => 'rw',
28     isa      => 'Baz',
29     required => 1,
30 );
31
32 sub do_something {
33     my $self = shift;
34     my $foo = Foo->new( app_handle => $self->app_handle );
35     return $foo->handle;
36 }
37
38 no Mouse;
39
40 1;
41
42 package Baz;
43 use Mouse;
44
45 sub handle {
46     # print "This works correctly.\n";
47     return 1;
48 }
49
50 no Mouse;
51
52 1;
53
54 package main;
55 use strict;
56 use warnings;
57 use Test::More tests => 2;
58 use Test::Exception;
59
60 my $bar = Bar->new( app_handle => Baz->new() );
61 ok($bar, "Test class Bar instantiated w/attribute app_handle Baz");
62
63 # Trigger the default sub of baz's handle attribute, which tries to call
64 # a method on an attribute which was set to an object passed in via the
65 # constructor.
66 lives_and { is($bar->do_something(), 1, "attribute was passed in okay") };