Commit | Line | Data |
4078709c |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 9; |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
10 | use_ok('Moose'); |
11 | } |
12 | |
13 | { |
14 | package Fake::DateTime; |
15 | use Moose; |
16 | |
17 | has 'string_repr' => (is => 'ro'); |
18 | |
19 | package Mortgage; |
20 | use Moose; |
21 | use Moose::Util::TypeConstraints; |
22 | |
23 | coerce 'Fake::DateTime' |
24 | => from 'Str' |
25 | => via { Fake::DateTime->new(string_repr => $_) }; |
26 | |
27 | has 'closing_date' => ( |
28 | is => 'rw', |
29 | isa => 'Fake::DateTime', |
30 | coerce => 1, |
31 | trigger => sub { |
32 | my ( $self, $val, $meta ) = @_; |
33 | ::pass('... trigger is being called'); |
34 | ::isa_ok($self->closing_date, 'Fake::DateTime'); |
35 | ::isa_ok($val, 'Fake::DateTime'); |
36 | } |
37 | ); |
38 | } |
39 | |
40 | { |
41 | my $mtg = Mortgage->new( closing_date => 'yesterday' ); |
42 | isa_ok($mtg, 'Mortgage'); |
43 | |
44 | # check that coercion worked |
45 | isa_ok($mtg->closing_date, 'Fake::DateTime'); |
46 | } |
47 | |
48 | Mortgage->meta->make_immutable; |
49 | ok(Mortgage->meta->is_immutable, '... Mortgage is now immutable'); |
50 | |
51 | { |
52 | my $mtg = Mortgage->new( closing_date => 'yesterday' ); |
53 | isa_ok($mtg, 'Mortgage'); |
54 | |
55 | # check that coercion worked |
56 | isa_ok($mtg->closing_date, 'Fake::DateTime'); |
57 | } |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |