Merge 'Moose-moosex_compile_support' into 'trunk'
[gitmo/Moose.git] / lib / Moose / Meta / Role / Composite.pm
CommitLineData
fb1e11d5 1package Moose::Meta::Role::Composite;
2
3use strict;
4use warnings;
5use metaclass;
6
7use Carp 'confess';
8use Scalar::Util 'blessed', 'reftype';
9
10use Data::Dumper;
11
12our $VERSION = '0.01';
13our $AUTHORITY = 'cpan:STEVAN';
14
15use 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
35sub 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
52sub 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
651;
66
67__END__
68
69=pod
70
71=head1 NAME
72
73Moose::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
95All complex software has bugs lurking in it, and this module is no
96exception. If you find a bug please either email me, or add the bug
97to cpan-RT.
98
99=head1 AUTHOR
100
101Stevan Little E<lt>stevan@iinteractive.comE<gt>
102
103=head1 COPYRIGHT AND LICENSE
104
778db3ac 105Copyright 2006-2008 by Infinity Interactive, Inc.
fb1e11d5 106
107L<http://www.iinteractive.com>
108
109This library is free software; you can redistribute it and/or modify
110it under the same terms as Perl itself.
111
112=cut