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