8d91e69d3d07399bfb870cafed747d26bb8c5133
[gitmo/MooseX-MetaDescription.git] / lib / MooseX / MetaDescription / Meta / Class.pm
1 package MooseX::MetaDescription::Meta::Class;
2 use Moose;
3
4 our $VERSION   = '0.04';
5 our $AUTHORITY = 'cpan:STEVAN';
6
7 extends 'Moose::Meta::Class';
8    with 'MooseX::MetaDescription::Meta::Trait';
9    
10 has '+description' => (
11    default => sub {
12        my $self   = shift;
13        my @supers = $self->linearized_isa;
14        shift @supers;
15        my %desc;
16        foreach my $super (@supers) {
17             if ($super->meta->isa('MooseX::MetaDescription::Meta::Class')) {
18                 %desc = (%{ $super->meta->description }, %desc)
19             }
20        }
21        \%desc;
22    },
23 );   
24
25 no Moose; 1;
26
27 __END__
28
29 =pod
30
31 =head1 NAME
32
33 MooseX::MetaDescription::Meta::Class - Custom class metaclass for meta-descriptions
34
35 =head1 SYNOPSIS
36
37   package Foo;
38   use metaclass 'MooseX::MetaDescription::Meta::Class' => (
39       description => {
40           'Hello' => 'World',
41       }
42   );
43   use Moose;
44   
45   package Bar;
46   use Moose;
47   
48   extends 'Foo';
49   
50   # always add it *after* the extends
51   __PACKAGE__->meta->description->{'Hello'} = 'Earth';
52   
53   package Baz;
54   use Moose;
55   
56   extends 'Bar';
57   
58   package Gorch;
59   use metaclass 'MooseX::MetaDescription::Meta::Class' => (
60       description => {
61           'Hello' => 'World'
62       }
63   );    
64   use Moose;
65
66   extends 'Baz';  
67
68   # ...
69   
70   Foo->meta->description # { 'Hello' => 'World', 'World' => 'Hello' }
71   Bar->meta->description # { 'Hello' => 'Earth', 'World' => 'Hello' } # change one, inherit the other  
72   Baz->meta->description # { 'Hello' => 'Earth', 'World' => 'Hello' } # inherit both 
73   Gorch->meta->description # { 'Hello' => 'World' } # overrides all, no inheritance   
74
75 =head1 DESCRIPTION
76
77 This module provides the custom metaclass to add Meta Descriptions 
78 to your classes. It provides a limited degree of inheritance of 
79 meta-descriptions, the details of which are shown above in the 
80 SYNOPSIS section.
81
82 =head1 METHODS 
83
84 NOTE: these are methods composed into this class from 
85 L<MooseX::MetaDescription::Meta::Trait> refer to that 
86 module for the complete description.
87
88 =over 4
89
90 =item B<description>
91
92 =item B<metadescription_classname>
93
94 =item B<metadescription>
95
96 =item B<meta>
97
98 =back
99
100 =head1 BUGS
101
102 All complex software has bugs lurking in it, and this module is no
103 exception. If you find a bug please either email me, or add the bug
104 to cpan-RT.
105
106 =head1 AUTHOR
107
108 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
109
110 =head1 COPYRIGHT AND LICENSE
111
112 Copyright 2008 Infinity Interactive, Inc.
113
114 L<http://www.iinteractive.com>
115
116 This library is free software; you can redistribute it and/or modify
117 it under the same terms as Perl itself.
118
119 =cut