Support modifier by regexp
[gitmo/Mouse.git] / t / 300_immutable / 007_immutable_trigger_from_constructor.t
CommitLineData
fc1d8369 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
b0000b3d 6use Test::More;
fc1d8369 7use Test::Exception;
8
b0000b3d 9plan tests => 3;
fc1d8369 10
11{
12 package AClass;
13
b0000b3d 14 use Mouse;
fc1d8369 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
b0000b3d 28 no Mouse;
fc1d8369 29}
30
31eval { AClass->new(foo => 'bar') };
32like ($@, qr/^Pulling the Foo trigger/, "trigger from immutable constructor");
33
34eval { AClass->new(baz => 'bar') };
35like ($@, qr/^Pulling the Baz trigger/, "trigger from immutable constructor");
36
37lives_ok { AClass->new(bar => 'bar') } '... no triggers called';
38
39
40