Commit | Line | Data |
b70e06c6 |
1 | package MooseX::MetaDescription::Meta::Trait; |
c13295c8 |
2 | use Moose::Role; |
3 | |
c13295c8 |
4 | our $VERSION = '0.01'; |
5 | our $AUTHORITY = 'cpan:STEVAN'; |
6 | |
7591e02c |
7 | has 'description' => ( |
8 | is => 'ro', |
9 | isa => 'HashRef', |
10 | lazy => 1, |
11 | default => sub { +{} }, |
12 | ); |
13 | |
14 | has 'metadescription_classname' => ( |
15 | is => 'ro', |
16 | isa => 'Str', |
91297cb4 |
17 | lazy => 1, |
7591e02c |
18 | default => sub { |
19 | 'MooseX::MetaDescription::Description' |
20 | } |
21 | ); |
c13295c8 |
22 | |
7591e02c |
23 | has 'metadescription' => ( |
24 | is => 'ro', |
25 | isa => 'MooseX::MetaDescription::Description', |
26 | lazy => 1, |
27 | default => sub { |
28 | my $self = shift; |
8a18d249 |
29 | |
30 | my $metadesc_class = $self->metadescription_classname; |
31 | my $desc = $self->description; |
32 | |
33 | if (my $traits = delete $desc->{traits}) { |
34 | my $meta = Moose::Meta::Class->create_anon_class( |
35 | superclasses => [ $metadesc_class ], |
36 | roles => $traits, |
37 | ); |
38 | $meta->add_method('meta' => sub { $meta }); |
39 | $metadesc_class = $meta->name; |
40 | } |
41 | |
42 | return $metadesc_class->new(%$desc, descriptor => $self); |
c13295c8 |
43 | }, |
44 | ); |
45 | |
46 | no Moose::Role; 1; |
47 | |
48 | __END__ |
49 | |
50 | =pod |
51 | |
52 | =head1 NAME |
53 | |
b70e06c6 |
54 | MooseX::MetaDescription::Meta::Trait - A Moosey solution to this problem |
c13295c8 |
55 | |
56 | =head1 SYNOPSIS |
57 | |
b70e06c6 |
58 | use MooseX::MetaDescription::Meta::Trait; |
c13295c8 |
59 | |
60 | =head1 DESCRIPTION |
61 | |
62 | =head1 METHODS |
63 | |
64 | =over 4 |
65 | |
66 | =item B<> |
67 | |
68 | =back |
69 | |
70 | =head1 BUGS |
71 | |
72 | All complex software has bugs lurking in it, and this module is no |
73 | exception. If you find a bug please either email me, or add the bug |
74 | to cpan-RT. |
75 | |
76 | =head1 AUTHOR |
77 | |
78 | Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
79 | |
80 | =head1 COPYRIGHT AND LICENSE |
81 | |
82 | Copyright 2008 Infinity Interactive, Inc. |
83 | |
84 | L<http://www.iinteractive.com> |
85 | |
86 | This library is free software; you can redistribute it and/or modify |
87 | it under the same terms as Perl itself. |
88 | |
89 | =cut |