6 use Test::More tests => 7 * 4;
10 use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce;
13 package LaTeX::TikZ::TestX;
16 use Any::Moose 'Util::TypeConstraints' => [ qw/
21 register_type_constraint
30 register_type_constraint(
31 LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new(
32 name => 'LaTeX::TikZ::TestX::Autocoerce',
33 parent => find_type_constraint(__PACKAGE__),
36 my ($last) = $_[0] =~ /::([^:]+)$/;
37 join '::', __PACKAGE__, "From$last";
42 coerce 'LaTeX::TikZ::TestX::Autocoerce'
43 => from 'LaTeX::TikZ::TestX'
46 coerce 'LaTeX::TikZ::TestX::Autocoerce'
48 => via { __PACKAGE__->new(id => $_) };
50 __PACKAGE__->meta->make_immutable;
52 sub main::X () { __PACKAGE__ }
56 package LaTeX::TikZ::TestY;
66 __PACKAGE__->meta->make_immutable;
68 sub main::Y () { __PACKAGE__ }
72 package LaTeX::TikZ::TestZ;
78 isa => 'LaTeX::TikZ::TestX::Autocoerce',
83 __PACKAGE__->meta->make_immutable;
85 sub main::Z () { __PACKAGE__ }
89 package LaTeX::TikZ::TestW;
92 use Any::Moose 'Util::TypeConstraints';
96 isa => 'LaTeX::TikZ::TestX',
100 coerce 'LaTeX::TikZ::TestX::Autocoerce'
104 __PACKAGE__->meta->make_immutable;
106 sub main::W () { __PACKAGE__ }
127 [ 123, 123, 'autocoerce X from int' ],
128 [ $x0, $time, 'autocoerce X from X' ],
129 [ $x0, $time, 'autocoerce X from X twice' ],
130 [ $y, 3, 'autocoerce X from Y' ],
131 [ $y2, 2, 'autocoerce X from another Y' ],
132 [ $w, $time, 'autocoerce X from W' ],
133 [ $w, $time, 'autocoerce X from W twice' ],
136 for my $test (@tests) {
137 my ($x, $exp, $desc) = @$test;
142 if (ref $exp eq 'Regexp') {
143 like $err, $exp, "could not $desc";
144 fail "$desc placeholder $_" for 1 .. 3;
146 is $err, '', "$desc doesn't croak";
147 isa_ok $z, Z(), "$desc returns a Z object";
149 isa_ok $x, X(), "$desc stores an X into the Z object";
150 is $x->id, $exp, "$desc correctly";