Commit | Line | Data |
fb1e11d5 |
1 | package Moose::Meta::Role::Composite; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use metaclass; |
6 | |
7 | use Carp 'confess'; |
8 | use Scalar::Util 'blessed', 'reftype'; |
9 | |
10 | use Data::Dumper; |
11 | |
12 | our $VERSION = '0.01'; |
13 | our $AUTHORITY = 'cpan:STEVAN'; |
14 | |
15 | use base 'Moose::Meta::Role'; |
16 | |
17 | # NOTE: |
18 | # we need to override the ->name |
19 | # method from Class::MOP::Package |
20 | # since we don't have an actual |
21 | # package for this. |
22 | # - SL |
23 | __PACKAGE__->meta->add_attribute('name' => (reader => 'name')); |
24 | |
25 | # NOTE: |
26 | # Again, since we don't have a real |
27 | # package to store our methods in, |
28 | # we use a HASH ref instead. |
29 | # - SL |
30 | __PACKAGE__->meta->add_attribute('methods' => ( |
31 | reader => 'get_method_map', |
32 | default => sub { {} } |
33 | )); |
34 | |
35 | sub new { |
36 | my ($class, %params) = @_; |
37 | # the roles param is required ... |
38 | ($_->isa('Moose::Meta::Role')) |
39 | || confess "The list of roles must be instances of Moose::Meta::Role, not $_" |
40 | foreach @{$params{roles}}; |
41 | # and the name is created from the |
42 | # roles if one has not been provided |
43 | $params{name} ||= (join "|" => map { $_->name } @{$params{roles}}); |
44 | $class->meta->new_object(%params); |
45 | } |
46 | |
47 | # NOTE: |
48 | # we need to override this cause |
49 | # we dont have that package I was |
50 | # talking about above. |
51 | # - SL |
52 | sub alias_method { |
53 | my ($self, $method_name, $method) = @_; |
54 | (defined $method_name && $method_name) |
55 | || confess "You must define a method name"; |
56 | |
c4538447 |
57 | # make sure to bless the |
58 | # method if nessecary |
59 | $method = $self->method_metaclass->wrap($method) |
60 | if !blessed($method); |
fb1e11d5 |
61 | |
c4538447 |
62 | $self->get_method_map->{$method_name} = $method; |
fb1e11d5 |
63 | } |
64 | |
65 | 1; |
66 | |
67 | __END__ |
68 | |
69 | =pod |
70 | |
71 | =head1 NAME |
72 | |
73 | Moose::Meta::Role::Composite - An object to represent the set of roles |
74 | |
75 | =head1 DESCRIPTION |
76 | |
77 | =head2 METHODS |
78 | |
79 | =over 4 |
80 | |
81 | =item B<new> |
82 | |
83 | =item B<meta> |
84 | |
85 | =item B<name> |
86 | |
87 | =item B<get_method_map> |
88 | |
89 | =item B<alias_method> |
90 | |
91 | =back |
92 | |
93 | =head1 BUGS |
94 | |
95 | All complex software has bugs lurking in it, and this module is no |
96 | exception. If you find a bug please either email me, or add the bug |
97 | to cpan-RT. |
98 | |
99 | =head1 AUTHOR |
100 | |
101 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
102 | |
103 | =head1 COPYRIGHT AND LICENSE |
104 | |
778db3ac |
105 | Copyright 2006-2008 by Infinity Interactive, Inc. |
fb1e11d5 |
106 | |
107 | L<http://www.iinteractive.com> |
108 | |
109 | This library is free software; you can redistribute it and/or modify |
110 | it under the same terms as Perl itself. |
111 | |
112 | =cut |