Merge branch 'master' of moose.perl.org:Mouse
[gitmo/Mouse.git] / t / 900_bug / 004_RT53286.t
CommitLineData
de821fdf 1#!perl -w
2# reported by Christine Spang (RT #53286)
3package Foo;
4use Mouse;
5
6has app_handle => (
7 is => 'rw',
8 isa => 'Baz',
9 required => 1,
10);
11
12has handle => (
13 is => 'rw',
14 isa => 'Int',
15 # app_handle should not be undef here!
16 default => sub { shift->app_handle->handle() },
17);
18
19no Mouse;
20
211;
22
23package Bar;
24use Mouse;
25
26has app_handle => (
27 is => 'rw',
28 isa => 'Baz',
29 required => 1,
30);
31
32sub do_something {
33 my $self = shift;
34 my $foo = Foo->new( app_handle => $self->app_handle );
35 return $foo->handle;
36}
37
38no Mouse;
39
401;
41
42package Baz;
43use Mouse;
44
45sub handle {
46 # print "This works correctly.\n";
47 return 1;
48}
49
50no Mouse;
51
521;
53
54package main;
55use strict;
56use warnings;
57use Test::More tests => 2;
58use Test::Exception;
59
60my $bar = Bar->new( app_handle => Baz->new() );
61ok($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.
66lives_and { is($bar->do_something(), 1, "attribute was passed in okay") };