X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FMetaDescription.pm;h=ebf6837e1e4f6ac9116fe2dbae78227474266285;hb=7c697304c34ed8e620e2c41e3d5cce74c578b653;hp=eb744547428850a52118d9e28dfebc1009ee41ee;hpb=0cb2eb0f8842c7047e7e47a67d1b11f13195c5ab;p=gitmo%2FMooseX-MetaDescription.git diff --git a/lib/MooseX/MetaDescription.pm b/lib/MooseX/MetaDescription.pm index eb74454..ebf6837 100644 --- a/lib/MooseX/MetaDescription.pm +++ b/lib/MooseX/MetaDescription.pm @@ -1,7 +1,7 @@ package MooseX::MetaDescription; use Moose; -our $VERSION = '0.01'; +our $VERSION = '0.03'; our $AUTHORITY = 'cpan:STEVAN'; use MooseX::MetaDescription::Meta::Class; @@ -20,36 +20,55 @@ MooseX::MetaDescription - A framework for adding additional metadata to Moose cl =head1 SYNOPSIS - package Foo; - use metaclass 'MooseX::MetaDescription::Meta::Class'; - use Moose; - - __PACKAGE__->meta->description->{'Hello'} = 'World'; - - has 'bar' => ( - metaclass => 'MooseX::MetaDescription::Meta::Attribute', - is => 'ro', - isa => 'Str', - default => sub { 'Foo::bar' }, - description => { - baz => 'Foo::bar::baz', - } - ); - - ... - - $foo->meta->description; # { 'Hello' => 'World' } - $foo->meta->get_attribute('bar')->description; # { baz => 'Foo::bar::baz' } + package Foo; + use metaclass 'MooseX::MetaDescription::Meta::Class' => ( + # add class-level metadata + description => { + 'Hello' => 'World' + } + ); + use Moose; + + has 'bar' => ( + metaclass => 'MooseX::MetaDescription::Meta::Attribute', + is => 'ro', + isa => 'Str', + default => sub { Bar->new() }, + # add attribute level metadata + description => { + node_type => 'element', + } + ); + + my $foo = Foo->new; + + $foo->meta->description; # { 'Hello' => 'World' } + + my $bar = $foo->meta->get_attribute('bar'); + + # access the desciption HASH directly + $bar->description; # { node_type => 'element' } + + # or access the instance of MooseX::MetaDescription::Description + $bar->metadescription; + + # access the original attribute metaobject from the metadesc too + $bar->metadescription->descriptor == $bar; =head1 DESCRIPTION -MooseX::MetaDescription allows you to add arbitrary out of band metadata to your Moose classes and attributes. +MooseX::MetaDescription allows you to add arbitrary out of band +metadata to your Moose classes and attributes. This will allow +you to track out of band data along with attributes, which is +very useful for say serializing Moose classes in HTML or XML. -=head1 METHODS +=head METHODS =over 4 -=item B<> +=item B + +The Moose metaclass. =back