1 package Moose::Meta::Role::Composite;
8 use Scalar::Util 'blessed', 'reftype';
12 our $VERSION = '0.01';
13 our $AUTHORITY = 'cpan:STEVAN';
15 use base 'Moose::Meta::Role';
18 # we need to override the ->name
19 # method from Class::MOP::Package
20 # since we don't have an actual
23 __PACKAGE__->meta->add_attribute('name' => (reader => 'name'));
26 # Again, since we don't have a real
27 # package to store our methods in,
28 # we use a HASH ref instead.
30 __PACKAGE__->meta->add_attribute('methods' => (
31 reader => 'get_method_map',
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);
48 # we need to override this cause
49 # we dont have that package I was
50 # talking about above.
53 my ($self, $method_name, $method) = @_;
54 (defined $method_name && $method_name)
55 || confess "You must define a method name";
57 my $body = (blessed($method) ? $method->body : $method);
58 ('CODE' eq (reftype($body) || ''))
59 || confess "Your code block must be a CODE reference";
61 $self->get_method_map->{$method_name} = $body;
72 Moose::Meta::Role::Composite - An object to represent the set of roles
86 =item B<get_method_map>
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
100 Stevan Little E<lt>stevan@iinteractive.comE<gt>
102 =head1 COPYRIGHT AND LICENSE
104 Copyright 2006-2008 by Infinity Interactive, Inc.
106 L<http://www.iinteractive.com>
108 This library is free software; you can redistribute it and/or modify
109 it under the same terms as Perl itself.