oops... i forgot s/Moose/Mouse/ orz
[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 skip_all => "mouse doesn't support Maybe[] yet";
10plan tests => 3;
fc1d8369 11
12{
13 package AClass;
14
b0000b3d 15 use Mouse;
fc1d8369 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
b0000b3d 29 no Mouse;
fc1d8369 30}
31
32eval { AClass->new(foo => 'bar') };
33like ($@, qr/^Pulling the Foo trigger/, "trigger from immutable constructor");
34
35eval { AClass->new(baz => 'bar') };
36like ($@, qr/^Pulling the Baz trigger/, "trigger from immutable constructor");
37
38lives_ok { AClass->new(bar => 'bar') } '... no triggers called';
39
40
41