1 package Moose::Meta::Role::Composite;
7 use Scalar::Util 'blessed';
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Moose::Meta::Role';
16 # we need to override the ->name
17 # method from Class::MOP::Package
18 # since we don't have an actual
21 __PACKAGE__->meta->add_attribute('name' => (reader => 'name'));
24 # Again, since we don't have a real
25 # package to store our methods in,
26 # we use a HASH ref instead.
28 __PACKAGE__->meta->add_attribute('methods' => (
29 reader => 'get_method_map',
34 my ($class, %params) = @_;
35 # the roles param is required ...
36 foreach ( @{$params{roles}} ) {
37 unless ( $_->isa('Moose::Meta::Role') ) {
39 Moose->throw_error("The list of roles must be instances of Moose::Meta::Role, not $_");
42 # and the name is created from the
43 # roles if one has not been provided
44 $params{name} ||= (join "|" => map { $_->name } @{$params{roles}});
45 $class->_new(\%params);
48 # This is largely a cope of what's in Moose::Meta::Role (itself
49 # largely a copy of Class::MOP::Class). However, we can't actually
50 # call add_package_symbol, because there's no package to which which
53 my ($self, $method_name, $method) = @_;
55 unless ( defined $method_name && $method_name ) {
56 Moose->throw_error("You must define a method name");
60 if (blessed($method)) {
61 $body = $method->body;
62 if ($method->package_name ne $self->name) {
63 $method = $method->clone(
64 package_name => $self->name,
66 ) if $method->can('clone');
71 $method = $self->wrap_method_body( body => $body, name => $method_name );
74 $self->get_method_map->{$method_name} = $method;
85 Moose::Meta::Role::Composite - An object to represent the set of roles
89 A composite is a role that consists of a set of two or more roles.
91 The API of a composite role is almost identical to that of a regular
96 C<Moose::Meta::Role::Composite> is a subclass of L<Moose::Meta::Role>.
102 =item B<< Moose::Meta::Role::Composite->new(%options) >>
104 This returns a new composite role object. It accepts the same
105 options as its parent class, with a few changes:
111 This option is an array reference containing a list of
112 L<Moose::Meta::Role> object. This is a required option.
116 If a name is not given, one is generated from the roles provided.
124 All complex software has bugs lurking in it, and this module is no
125 exception. If you find a bug please either email me, or add the bug
130 Stevan Little E<lt>stevan@iinteractive.comE<gt>
132 =head1 COPYRIGHT AND LICENSE
134 Copyright 2006-2009 by Infinity Interactive, Inc.
136 L<http://www.iinteractive.com>
138 This library is free software; you can redistribute it and/or modify
139 it under the same terms as Perl itself.