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