Fix a test
[gitmo/Mouse.git] / t / 020_attributes / 007_attribute_custom_metaclass.t
CommitLineData
4060c871 1#!/usr/bin/perl
1f5ce14a 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
4060c871 5
6use strict;
7use warnings;
8
1f5ce14a 9use Test::More;
4060c871 10use Test::Exception;
11
12
4060c871 13{
14 package Foo::Meta::Attribute;
15 use Mouse;
16
17 extends 'Mouse::Meta::Attribute';
18
19 around 'new' => sub {
20 my $next = shift;
21 my $self = shift;
22 my $name = shift;
23 $next->($self, $name, (is => 'rw', isa => 'Foo'), @_);
24 };
25
26 package Foo;
27 use Mouse;
28
29 has 'foo' => (metaclass => 'Foo::Meta::Attribute');
30}
31{
32 my $foo = Foo->new;
33 isa_ok($foo, 'Foo');
34
35 my $foo_attr = Foo->meta->get_attribute('foo');
36 isa_ok($foo_attr, 'Foo::Meta::Attribute');
37 isa_ok($foo_attr, 'Mouse::Meta::Attribute');
38
39 is($foo_attr->name, 'foo', '... got the right name for our meta-attribute');
40 ok($foo_attr->has_accessor, '... our meta-attrubute created the accessor for us');
41
42 ok($foo_attr->has_type_constraint, '... our meta-attrubute created the type_constraint for us');
43
44 my $foo_attr_type_constraint = $foo_attr->type_constraint;
45 isa_ok($foo_attr_type_constraint, 'Mouse::Meta::TypeConstraint');
46
47 is($foo_attr_type_constraint->name, 'Foo', '... got the right type constraint name');
1f5ce14a 48 is($foo_attr_type_constraint->parent->name, 'Object', '... got the right type constraint parent name');
4060c871 49}
50{
51 package Bar::Meta::Attribute;
52 use Mouse;
53
1f5ce14a 54 extends 'Mouse::Meta::Attribute';
4060c871 55
56 package Bar;
57 use Mouse;
58
59 ::lives_ok {
79a725f4 60 has 'bar' => (metaclass => 'Bar::Meta::Attribute', is => 'bare');
4060c871 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
1f5ce14a 95done_testing;