remove mechanism for specifying superclass in _constructor_maker_for
[gitmo/Moo.git] / xt / moox-types.t
CommitLineData
ceedd7fc 1use strictures 1;
2use Test::More;
3
4{
5 package TypeOMatic;
6
7 use Moo::Role;
8 use Sub::Quote;
9 use MooX::Types::MooseLike::Base qw(Str);
10 use MooX::Types::MooseLike::Numeric qw(PositiveInt);
11
12 has named_type => (
13 is => 'ro',
14 isa => Str,
15 );
16
17 has named_external_type => (
18 is => 'ro',
19 isa => PositiveInt,
20 );
21
22 package TypeOMatic::Consumer;
23
24 # do this as late as possible to simulate "real" behaviour
25 use Moo::HandleMoose;
26 use Moose;
27 with 'TypeOMatic';
28}
29
30my $meta = Class::MOP::class_of('TypeOMatic::Consumer');
31
32my ($str, $positive_int)
33 = map $meta->get_attribute($_)->type_constraint->name,
34 qw(named_type named_external_type);
35
36is($str, 'Str', 'Built-in Moose type ok');
37is(
38 $positive_int, 'MooseX::Types::Common::Numeric::PositiveInt',
39 'External (MooseX::Types type) ok'
40);
41
513a3b5d 42local $@;
43eval q {
44 package Fooble;
45 use Moo;
46 my $isa = sub { 1 };
47 $Moo::HandleMoose::TYPE_MAP{$isa} = sub { $isa };
48 has barble => (is => "ro", isa => $isa);
49 __PACKAGE__->meta->get_attribute("barble");
50};
51
52like(
53 $@,
5002e2f0 54 qr/^error inflating attribute 'barble' for package 'Fooble': \$TYPE_MAP\{CODE\(\w+?\)\} did not return a valid type constraint/,
513a3b5d 55 'error message for incorrect type constraint inflation',
56);
57
ceedd7fc 58done_testing;