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