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