oops... i forgot s/Moose/Mouse/ orz
[gitmo/Mouse.git] / t / 300_immutable / 007_immutable_trigger_from_constructor.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9 plan skip_all => "mouse doesn't support Maybe[] yet";
10 plan tests => 3;
11
12 {
13     package AClass;
14
15     use Mouse;
16
17     has 'foo' => (is => 'rw', isa => 'Maybe[Str]', trigger => sub {
18         die "Pulling the Foo trigger\n"
19     });
20     
21     has 'bar' => (is => 'rw', isa => 'Maybe[Str]');    
22     
23     has 'baz' => (is => 'rw', isa => 'Maybe[Str]', trigger => sub {
24         die "Pulling the Baz trigger\n"
25     });    
26
27     __PACKAGE__->meta->make_immutable; #(debug => 1);
28
29     no Mouse;
30 }
31
32 eval { AClass->new(foo => 'bar') };
33 like ($@, qr/^Pulling the Foo trigger/, "trigger from immutable constructor");
34
35 eval { AClass->new(baz => 'bar') };
36 like ($@, qr/^Pulling the Baz trigger/, "trigger from immutable constructor");
37
38 lives_ok { AClass->new(bar => 'bar') } '... no triggers called';
39
40
41