1 package MooseX::MetaDescription::Meta::Trait;
5 our $AUTHORITY = 'cpan:STEVAN';
11 default => sub { +{} },
14 has 'metadescription_classname' => (
19 'MooseX::MetaDescription::Description'
23 has 'metadescription' => (
25 isa => 'MooseX::MetaDescription::Description',
30 my $metadesc_class = $self->metadescription_classname;
31 my $desc = $self->description;
33 Class::MOP::load_class($metadesc_class);
35 if (my $traits = delete $desc->{traits}) {
36 my $meta = Moose::Meta::Class->create_anon_class(
37 superclasses => [ $metadesc_class ],
38 roles => $self->prepare_traits_for_application($traits),
40 $meta->add_method('meta' => sub { $meta });
41 $metadesc_class = $meta->name;
44 return $metadesc_class->new(%$desc, descriptor => $self);
48 # this is for the subclasses to use ...
49 sub prepare_traits_for_application { $_[1] }
59 MooseX::MetaDescription::Meta::Trait - Custom class meta-trait for meta-descriptions
67 # apply this as a trait to your attribute
68 traits => [ 'MooseX::MetaDescription::Meta::Trait' ],
71 default => sub { 'Foo::baz' },
73 bar => 'Foo::baz::bar',
74 gorch => 'Foo::baz::gorch',
80 This is the core of the Meta Description functionality, it is a role that is done
81 by both L<MooseX::MetaDescription::Meta::Attribute> and L<MooseX::MetaDescription::Meta::Class>
82 and can be used on it's own as a meta-attribute trait.
90 The description C<HASH> ref is stored here.
92 =item B<metadescription_classname>
94 This provides the name of the metadescription class, currently this
95 defaults to L<MooseX::MetaDescription::Description>. It is read only
96 and so can only be specified at instance construction time.
98 =item B<metadescription>
100 This is the instance of the class specified in C<metadescription_classname>
101 it is generated lazily and is also read-only. In general you will never
102 need to set this yourself, but simply set C<metadescription_classname>
103 and it will all just work.
105 =item B<prepare_traits_for_application ($traits)>
107 This is passed the ARRAY ref of trait names so that they can be pre-processed
108 before they are applied to the metadescription. It is expected to return
109 an ARRAY ref of trait names to be applied. By default it simply returns what
114 The L<Moose::Role> metaclass.
120 All complex software has bugs lurking in it, and this module is no
121 exception. If you find a bug please either email me, or add the bug
126 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
128 =head1 COPYRIGHT AND LICENSE
130 Copyright 2008 Infinity Interactive, Inc.
132 L<http://www.iinteractive.com>
134 This library is free software; you can redistribute it and/or modify
135 it under the same terms as Perl itself.