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 ($_->isa('Moose::Meta::Role'))
37 || Moose->throw_error("The list of roles must be instances of Moose::Meta::Role, not $_")
38 foreach @{$params{roles}};
39 # and the name is created from the
40 # roles if one has not been provided
41 $params{name} ||= (join "|" => map { $_->name } @{$params{roles}});
42 $class->_new(\%params);
45 # This is largely a cope of what's in Moose::Meta::Role (itself
46 # largely a copy of Class::MOP::Class). However, we can't actually
47 # call add_package_symbol, because there's no package to which which
50 my ($self, $method_name, $method) = @_;
51 (defined $method_name && $method_name)
52 || Moose->throw_error("You must define a method name");
55 if (blessed($method)) {
56 $body = $method->body;
57 if ($method->package_name ne $self->name) {
58 $method = $method->clone(
59 package_name => $self->name,
61 ) if $method->can('clone');
66 $method = $self->wrap_method_body( body => $body, name => $method_name );
69 $self->get_method_map->{$method_name} = $method;
80 Moose::Meta::Role::Composite - An object to represent the set of roles
94 =item B<get_method_map>
102 All complex software has bugs lurking in it, and this module is no
103 exception. If you find a bug please either email me, or add the bug
108 Stevan Little E<lt>stevan@iinteractive.comE<gt>
110 =head1 COPYRIGHT AND LICENSE
112 Copyright 2006-2008 by Infinity Interactive, Inc.
114 L<http://www.iinteractive.com>
116 This library is free software; you can redistribute it and/or modify
117 it under the same terms as Perl itself.