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