Support modifier by regexp
[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 tests => 3;
10
11 {
12     package AClass;
13
14     use Mouse;
15
16     has 'foo' => (is => 'rw', isa => 'Maybe[Str]', trigger => sub {
17         die "Pulling the Foo trigger\n"
18     });
19     
20     has 'bar' => (is => 'rw', isa => 'Maybe[Str]');    
21     
22     has 'baz' => (is => 'rw', isa => 'Maybe[Str]', trigger => sub {
23         die "Pulling the Baz trigger\n"
24     });    
25
26     __PACKAGE__->meta->make_immutable; #(debug => 1);
27
28     no Mouse;
29 }
30
31 eval { AClass->new(foo => 'bar') };
32 like ($@, qr/^Pulling the Foo trigger/, "trigger from immutable constructor");
33
34 eval { AClass->new(baz => 'bar') };
35 like ($@, qr/^Pulling the Baz trigger/, "trigger from immutable constructor");
36
37 lives_ok { AClass->new(bar => 'bar') } '... no triggers called';
38
39
40