Commit | Line | Data |
c13295c8 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More no_plan => 1; |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
10 | use_ok('MooseX::MetaDescription'); |
11 | } |
12 | |
13 | { |
14 | package Foo; |
15 | use metaclass 'MooseX::MetaDescription::Meta::Class'; |
16 | use Moose; |
17 | |
18 | __PACKAGE__->meta->description->{'Hello'} = 'World'; |
19 | |
20 | has 'bar' => ( |
21 | metaclass => 'MooseX::MetaDescription::Meta::Attribute', |
22 | is => 'ro', |
23 | isa => 'Str', |
24 | default => sub { 'Foo::bar' }, |
25 | description => { |
26 | baz => 'Foo::bar::baz', |
27 | gorch => 'Foo::bar::gorch', |
28 | } |
29 | ); |
30 | |
31 | has 'baz' => ( |
32 | traits => [ 'MooseX::MetaDescription::Meta::Attribute::Trait' ], |
33 | is => 'ro', |
34 | isa => 'Str', |
35 | default => sub { 'Foo::baz' }, |
36 | description => { |
37 | bar => 'Foo::baz::bar', |
38 | gorch => 'Foo::baz::gorch', |
39 | } |
40 | ); |
41 | } |
42 | |
43 | # check the meta-desc |
44 | |
45 | my $foo_class = Foo->meta; |
4a7bc2f6 |
46 | isa_ok($foo_class->metadescription, 'MooseX::MetaDescription::Description::Class'); |
de7ba0e9 |
47 | is($foo_class->metadescription->descriptor, $foo_class, '... got the circular ref'); |
c13295c8 |
48 | |
49 | my $bar_attr = Foo->meta->get_attribute('bar'); |
4a7bc2f6 |
50 | isa_ok($bar_attr->metadescription, 'MooseX::MetaDescription::Description::Attribute'); |
de7ba0e9 |
51 | is($bar_attr->metadescription->descriptor, $bar_attr, '... got the circular ref'); |
c13295c8 |
52 | |
53 | my $baz_attr = Foo->meta->get_attribute('baz'); |
4a7bc2f6 |
54 | isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description::Attribute'); |
de7ba0e9 |
55 | is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref'); |
c13295c8 |
56 | |
57 | # check the actual descs |
58 | |
59 | foreach my $foo ('Foo', Foo->new) { |
60 | is_deeply( |
61 | $foo->meta->description, |
62 | { 'Hello' => 'World' }, |
63 | '... got the right class description' |
64 | ); |
65 | |
66 | is_deeply( |
67 | $foo->meta->get_attribute('bar')->description, |
68 | { |
69 | baz => 'Foo::bar::baz', |
70 | gorch => 'Foo::bar::gorch', |
71 | }, |
72 | '... got the right class description' |
73 | ); |
74 | |
75 | is_deeply( |
76 | $foo->meta->get_attribute('baz')->description, |
77 | { |
78 | bar => 'Foo::baz::bar', |
79 | gorch => 'Foo::baz::gorch', |
80 | }, |
81 | '... got the right class description' |
82 | ); |
83 | } |
84 | |