Reorganize t/020_attributes/
[gitmo/Mouse.git] / t / 020_attributes / 020_trigger_and_coerce.t
CommitLineData
4060c871 1#!/usr/bin/perl
1f5ce14a 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
4060c871 5
6use strict;
7use warnings;
8
1f5ce14a 9use Test::More;
4060c871 10use Test::Exception;
11
12
4060c871 13{
14
15 package Fake::DateTime;
16 use Mouse;
17
18 has 'string_repr' => ( is => 'ro' );
19
20 package Mortgage;
21 use Mouse;
22 use Mouse::Util::TypeConstraints;
23
24 coerce 'Fake::DateTime' => 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 ) = @_;
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
48Mortgage->meta->make_immutable;
49ok( 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
1f5ce14a 59done_testing;