perigrin is on crack
[gitmo/MooseX-MetaDescription.git] / t / 003_inheriting_meta_desc.t
CommitLineData
4b67a690 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More no_plan => 1;
7use Test::Exception;
8
9BEGIN {
10 use_ok('MooseX::MetaDescription');
11}
12
13{
14 package Foo;
15 use Moose;
16
17 has 'baz' => (
18 traits => [ 'MooseX::MetaDescription::Meta::Trait' ],
19 is => 'ro',
20 isa => 'Str',
21 default => sub { 'Foo::baz' },
22 description => {
23 bar => 'Foo::baz::bar',
24 gorch => 'Foo::baz::gorch',
25 }
26 );
27
28 package Bar;
29 use Moose;
30
31 extends 'Foo';
32}
33
34# check the meta-desc
35
36my $baz_attr = Foo->meta->find_attribute_by_name('baz');
37isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description');
38is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref');
39
40{
41 my $baz_attr = Bar->meta->find_attribute_by_name('baz');
42 can_ok($baz_attr, 'description');
43 isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description');
44 is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref');
45
46 my ($baz_attr_2) = Bar->meta->compute_all_applicable_attributes;
47 is($baz_attr, $baz_attr_2, '... got the same attribute');
48}
49
50# check the actual descs
51
52foreach my $foo ('Foo', Foo->new, 'Bar', Bar->new) {
53
54 is_deeply(
55 $foo->meta->find_attribute_by_name('baz')->description,
56 {
57 bar => 'Foo::baz::bar',
58 gorch => 'Foo::baz::gorch',
59 },
60 '... got the right class description'
61 );
62}