Commit | Line | Data |
91297cb4 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
d68e679f |
6 | use Test::More 'no_plan'; |
91297cb4 |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
10 | use_ok('MooseX::MetaDescription'); |
11 | } |
12 | |
13 | { |
14 | package Foo::Description; |
15 | use Moose; |
6515e19d |
16 | |
91297cb4 |
17 | extends 'MooseX::MetaDescription::Description'; |
6515e19d |
18 | |
91297cb4 |
19 | has 'bar' => (is => 'ro', isa => 'Str'); |
6515e19d |
20 | has 'baz' => (is => 'ro', isa => 'Str'); |
21 | has 'gorch' => (is => 'ro', isa => 'Str'); |
22 | |
91297cb4 |
23 | package Foo::MetaDescription::Trait; |
24 | use Moose::Role; |
25 | |
26 | with 'MooseX::MetaDescription::Meta::Trait'; |
27 | |
0f4510ea |
28 | has 'metadescription_classname' => ( |
29 | default => 'Foo::Description', |
30 | is => 'ro', |
91297cb4 |
31 | ); |
6515e19d |
32 | |
91297cb4 |
33 | package Foo::MetaDescription::Attribute; |
34 | use Moose; |
6515e19d |
35 | |
91297cb4 |
36 | extends 'MooseX::MetaDescription::Meta::Attribute'; |
6515e19d |
37 | |
0f4510ea |
38 | has 'metadescription_classname' => ( |
39 | default => 'Foo::Description', |
40 | is => 'ro', |
6515e19d |
41 | ); |
91297cb4 |
42 | } |
43 | |
44 | { |
45 | package Foo; |
46 | use Moose; |
6515e19d |
47 | |
91297cb4 |
48 | has 'bar' => ( |
49 | metaclass => 'Foo::MetaDescription::Attribute', |
50 | is => 'ro', |
6515e19d |
51 | isa => 'Str', |
91297cb4 |
52 | default => sub { 'Foo::bar' }, |
53 | description => { |
54 | baz => 'Foo::bar::baz', |
55 | gorch => 'Foo::bar::gorch', |
56 | } |
57 | ); |
6515e19d |
58 | |
91297cb4 |
59 | has 'baz' => ( |
60 | traits => [ 'Foo::MetaDescription::Trait' ], |
61 | is => 'ro', |
6515e19d |
62 | isa => 'Str', |
91297cb4 |
63 | default => sub { 'Foo::baz' }, |
64 | description => { |
65 | bar => 'Foo::baz::bar', |
66 | gorch => 'Foo::baz::gorch', |
67 | } |
6515e19d |
68 | ); |
91297cb4 |
69 | } |
70 | |
71 | # check the meta-desc |
72 | |
73 | my $bar_attr = Foo->meta->get_attribute('bar'); |
74 | isa_ok($bar_attr->metadescription, 'MooseX::MetaDescription::Description'); |
75 | isa_ok($bar_attr->metadescription, 'Foo::Description'); |
76 | is($bar_attr->metadescription->descriptor, $bar_attr, '... got the circular ref'); |
77 | |
78 | my $baz_attr = Foo->meta->get_attribute('baz'); |
79 | isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description'); |
80 | isa_ok($baz_attr->metadescription, 'Foo::Description'); |
81 | is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref'); |
82 | |
83 | # check the actual descs |
84 | |
85 | foreach my $foo ('Foo', Foo->new) { |
86 | |
87 | is_deeply( |
88 | $foo->meta->get_attribute('bar')->description, |
89 | { |
90 | baz => 'Foo::bar::baz', |
91 | gorch => 'Foo::bar::gorch', |
92 | }, |
93 | '... got the right class description' |
94 | ); |
6515e19d |
95 | |
91297cb4 |
96 | my $bar_meta_desc = $foo->meta->get_attribute('bar')->metadescription; |
97 | is($bar_meta_desc->baz, 'Foo::bar::baz', '... we have methods'); |
6515e19d |
98 | is($bar_meta_desc->gorch, 'Foo::bar::gorch', '... we have methods'); |
91297cb4 |
99 | |
100 | is_deeply( |
101 | $foo->meta->get_attribute('baz')->description, |
102 | { |
103 | bar => 'Foo::baz::bar', |
104 | gorch => 'Foo::baz::gorch', |
105 | }, |
106 | '... got the right class description' |
107 | ); |
6515e19d |
108 | |
91297cb4 |
109 | my $baz_meta_desc = $foo->meta->get_attribute('baz')->metadescription; |
110 | is($baz_meta_desc->bar, 'Foo::baz::bar', '... we have methods'); |
6515e19d |
111 | is($baz_meta_desc->gorch, 'Foo::baz::gorch', '... we have methods'); |
91297cb4 |
112 | } |
113 | |