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 | |
57 | my $body = (blessed($method) ? $method->body : $method); |
58 | ('CODE' eq (reftype($body) || '')) |
59 | || confess "Your code block must be a CODE reference"; |
60 | |
61 | $self->get_method_map->{$method_name} = $body; |
62 | } |
63 | |
64 | 1; |
65 | |
66 | __END__ |
67 | |
68 | =pod |
69 | |
70 | =head1 NAME |
71 | |
72 | Moose::Meta::Role::Composite - An object to represent the set of roles |
73 | |
74 | =head1 DESCRIPTION |
75 | |
76 | =head2 METHODS |
77 | |
78 | =over 4 |
79 | |
80 | =item B<new> |
81 | |
82 | =item B<meta> |
83 | |
84 | =item B<name> |
85 | |
86 | =item B<get_method_map> |
87 | |
88 | =item B<alias_method> |
89 | |
90 | =back |
91 | |
92 | =head1 BUGS |
93 | |
94 | All complex software has bugs lurking in it, and this module is no |
95 | exception. If you find a bug please either email me, or add the bug |
96 | to cpan-RT. |
97 | |
98 | =head1 AUTHOR |
99 | |
100 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
101 | |
102 | =head1 COPYRIGHT AND LICENSE |
103 | |
778db3ac |
104 | Copyright 2006-2008 by Infinity Interactive, Inc. |
fb1e11d5 |
105 | |
106 | L<http://www.iinteractive.com> |
107 | |
108 | This library is free software; you can redistribute it and/or modify |
109 | it under the same terms as Perl itself. |
110 | |
111 | =cut |