Add another MOOSE_TEST_MD option, MooseX
[gitmo/Moose.git] / t / attributes / attribute_custom_metaclass.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Fatal;
8
9
10 {
11     package Foo::Meta::Attribute;
12     use Moose;
13
14     extends 'Moose::Meta::Attribute';
15
16     around 'new' => sub {
17         my $next = shift;
18         my $self = shift;
19         my $name = shift;
20         $next->($self, $name, (is => 'rw', isa => 'Foo'), @_);
21     };
22
23     package Foo;
24     use Moose;
25
26     has 'foo' => (metaclass => 'Foo::Meta::Attribute');
27 }
28 {
29     my $foo = Foo->new;
30     isa_ok($foo, 'Foo');
31
32     my $foo_attr = Foo->meta->get_attribute('foo');
33     isa_ok($foo_attr, 'Foo::Meta::Attribute');
34     isa_ok($foo_attr, 'Moose::Meta::Attribute');
35
36     is($foo_attr->name, 'foo', '... got the right name for our meta-attribute');
37     ok($foo_attr->has_accessor, '... our meta-attrubute created the accessor for us');
38
39     ok($foo_attr->has_type_constraint, '... our meta-attrubute created the type_constraint for us');
40
41     my $foo_attr_type_constraint = $foo_attr->type_constraint;
42     isa_ok($foo_attr_type_constraint, 'Moose::Meta::TypeConstraint');
43
44     is($foo_attr_type_constraint->name, 'Foo', '... got the right type constraint name');
45     is($foo_attr_type_constraint->parent->name, 'Object', '... got the right type constraint parent name');
46 }
47 {
48     package Bar::Meta::Attribute;
49     use Moose;
50
51     extends 'Class::MOP::Attribute';
52
53     package Bar;
54     use Moose;
55
56     ::is( ::exception {
57         has 'bar' => (metaclass => 'Bar::Meta::Attribute');
58     }, undef, '... the attribute metaclass need not be a Moose::Meta::Attribute as long as it behaves' );
59 }
60
61 {
62     package Moose::Meta::Attribute::Custom::Foo;
63     sub register_implementation { 'Foo::Meta::Attribute' }
64
65     package Moose::Meta::Attribute::Custom::Bar;
66     use Moose;
67
68     extends 'Moose::Meta::Attribute';
69
70     package Another::Foo;
71     use Moose;
72
73     ::is( ::exception {
74         has 'foo' => (metaclass => 'Foo');
75     }, undef, '... the attribute metaclass alias worked correctly' );
76
77     ::is( ::exception {
78         has 'bar' => (metaclass => 'Bar', is => 'bare');
79     }, undef, '... the attribute metaclass alias worked correctly' );
80 }
81
82 {
83     my $foo_attr = Another::Foo->meta->get_attribute('foo');
84     isa_ok($foo_attr, 'Foo::Meta::Attribute');
85     isa_ok($foo_attr, 'Moose::Meta::Attribute');
86
87     my $bar_attr = Another::Foo->meta->get_attribute('bar');
88     isa_ok($bar_attr, 'Moose::Meta::Attribute::Custom::Bar');
89     isa_ok($bar_attr, 'Moose::Meta::Attribute');
90 }
91
92 done_testing;