X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FMetaDescription%2FMeta%2FClass.pm;h=5d1e2cccfd2b86c987ed4908e8b75bd722faef98;hb=56e78a9caff840fb68085ead8837a64c839740de;hp=3e0395c75eea29baa32e6bfc07c3c2f008214b56;hpb=c13295c80061a10bc2612b024bfdb52687d3a3b0;p=gitmo%2FMooseX-MetaDescription.git diff --git a/lib/MooseX/MetaDescription/Meta/Class.pm b/lib/MooseX/MetaDescription/Meta/Class.pm index 3e0395c..5d1e2cc 100644 --- a/lib/MooseX/MetaDescription/Meta/Class.pm +++ b/lib/MooseX/MetaDescription/Meta/Class.pm @@ -1,35 +1,26 @@ package MooseX::MetaDescription::Meta::Class; use Moose; -use MooseX::MetaDescription::Description::Class; - -our $VERSION = '0.01'; +our $VERSION = '0.02'; our $AUTHORITY = 'cpan:STEVAN'; extends 'Moose::Meta::Class'; - -has 'description' => ( - is => 'ro', - isa => 'HashRef', - lazy => 1, - default => sub { +{} }, -); - -has 'metadescription' => ( - is => 'ro', - isa => 'MooseX::MetaDescription::Description', - lazy => 1, - default => sub { - my $self = shift; - - # TODO: handle traits ... - - MooseX::MetaDescription::Description::Class->new( - %{$self->description}, - class => $self, - ) - }, -); + with 'MooseX::MetaDescription::Meta::Trait'; + +has '+description' => ( + default => sub { + my $self = shift; + my @supers = $self->linearized_isa; + shift @supers; + my %desc; + foreach my $super (@supers) { + if ($super->meta->isa('MooseX::MetaDescription::Meta::Class')) { + %desc = (%{ $super->meta->description }, %desc) + } + } + \%desc; + }, +); no Moose; 1; @@ -39,25 +30,76 @@ __END__ =head1 NAME -MooseX::MetaDescription::Meta::Class - A Moosey solution to this problem +MooseX::MetaDescription::Meta::Class - Custom class metaclass for meta-descriptions =head1 SYNOPSIS - use MooseX::MetaDescription::Meta::Class; + package Foo; + use metaclass 'MooseX::MetaDescription::Meta::Class' => ( + description => { + 'Hello' => 'World', + } + ); + use Moose; + + package Bar; + use Moose; + + extends 'Foo'; + + # always add it *after* the extends + __PACKAGE__->meta->description->{'Hello'} = 'Earth'; + + package Baz; + use Moose; + + extends 'Bar'; + + package Gorch; + use metaclass 'MooseX::MetaDescription::Meta::Class' => ( + description => { + 'Hello' => 'World' + } + ); + use Moose; + + extends 'Baz'; + + # ... + + Foo->meta->description # { 'Hello' => 'World', 'World' => 'Hello' } + Bar->meta->description # { 'Hello' => 'Earth', 'World' => 'Hello' } # change one, inherit the other + Baz->meta->description # { 'Hello' => 'Earth', 'World' => 'Hello' } # inherit both + Gorch->meta->description # { 'Hello' => 'World' } # overrides all, no inheritance =head1 DESCRIPTION +This module provides the custom metaclass to add Meta Descriptions +to your classes. It provides a limited degree of inheritance of +meta-descriptions, the details of which are shown above in the +SYNOPSIS section. + =head1 METHODS +NOTE: these are methods composed into this class from +L refer to that +module for the complete description. + =over 4 -=item B<> +=item B + +=item B + +=item B + +=item B =back =head1 BUGS -All complex software has bugs lurking in it, and this module is no +All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.