fixes
[gitmo/Moose.git] / t / 036_custom_attribute_metaclass.t
CommitLineData
b0ea39ef 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
590868a3 6use Test::More tests => 11;
b0ea39ef 7use Test::Exception;
8
9BEGIN {
10 use_ok('Moose');
11}
12
590868a3 13{
b0ea39ef 14 package Foo::Meta::Attribute;
15 use strict;
16 use warnings;
17
18 use base 'Moose::Meta::Attribute';
19
20 sub new {
21 my $class = shift;
22 $class->SUPER::new(@_, (is => 'rw', isa => 'Foo'));
23 }
24
25 package Foo;
26 use strict;
27 use warnings;
28 use Moose;
29
30 has 'foo' => (metaclass => 'Foo::Meta::Attribute');
31}
32
33my $foo = Foo->new;
34isa_ok($foo, 'Foo');
35
36my $foo_attr = Foo->meta->get_attribute('foo');
37isa_ok($foo_attr, 'Foo::Meta::Attribute');
38isa_ok($foo_attr, 'Moose::Meta::Attribute');
39
40is($foo_attr->name, 'foo', '... got the right name for our meta-attribute');
41ok($foo_attr->has_accessor, '... our meta-attrubute created the accessor for us');
42
43ok($foo_attr->has_type_constraint, '... our meta-attrubute created the type_constraint for us');
44
45my $foo_attr_type_constraint = $foo_attr->type_constraint;
46isa_ok($foo_attr_type_constraint, 'Moose::Meta::TypeConstraint');
47
48is($foo_attr_type_constraint->name, 'Foo', '... got the right type constraint name');
49is($foo_attr_type_constraint->parent->name, 'Object', '... got the right type constraint parent name');
590868a3 50
51{
52 package Bar::Meta::Attribute;
53 use strict;
54 use warnings;
55
56 use base 'Class::MOP::Attribute';
57
58 package Bar;
59 use strict;
60 use warnings;
61 use Moose;
62
63 ::dies_ok {
64 has 'bar' => (metaclass => 'Bar::Meta::Attribute');
65 } '... the attribute metaclass must be a subclass of Moose::Meta::Attribute';
66}
67