RT#83929: fix memory leak in union types
[gitmo/Moose.git] / t / immutable / immutable_trigger_from_constructor.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Fatal;
8
9
10 {
11     package AClass;
12
13     use Moose;
14
15     has 'foo' => (is => 'rw', isa => 'Maybe[Str]', trigger => sub {
16         die "Pulling the Foo trigger\n"
17     });
18
19     has 'bar' => (is => 'rw', isa => 'Maybe[Str]');
20
21     has 'baz' => (is => 'rw', isa => 'Maybe[Str]', trigger => sub {
22         die "Pulling the Baz trigger\n"
23     });
24
25     __PACKAGE__->meta->make_immutable; #(debug => 1);
26
27     no Moose;
28 }
29
30 eval { AClass->new(foo => 'bar') };
31 like ($@, qr/^Pulling the Foo trigger/, "trigger from immutable constructor");
32
33 eval { AClass->new(baz => 'bar') };
34 like ($@, qr/^Pulling the Baz trigger/, "trigger from immutable constructor");
35
36 is( exception { AClass->new(bar => 'bar') }, undef, '... no triggers called' );
37
38 done_testing;