merge trunk to pluggable errors
[gitmo/Moose.git] / lib / Moose / Meta / Role / Composite.pm
CommitLineData
fb1e11d5 1package Moose::Meta::Role::Composite;
2
3use strict;
4use warnings;
5use metaclass;
6
28412c0b 7use Carp 'confess';
21f1e231 8use Scalar::Util 'blessed';
fb1e11d5 9
e606ae5f 10our $VERSION = '0.57';
11$VERSION = eval $VERSION;
fb1e11d5 12our $AUTHORITY = 'cpan:STEVAN';
13
14use base 'Moose::Meta::Role';
15
16# NOTE:
17# we need to override the ->name
18# method from Class::MOP::Package
19# since we don't have an actual
20# package for this.
21# - SL
22__PACKAGE__->meta->add_attribute('name' => (reader => 'name'));
23
24# NOTE:
25# Again, since we don't have a real
26# package to store our methods in,
27# we use a HASH ref instead.
28# - SL
29__PACKAGE__->meta->add_attribute('methods' => (
30 reader => 'get_method_map',
31 default => sub { {} }
32));
33
34sub new {
35 my ($class, %params) = @_;
36 # the roles param is required ...
37 ($_->isa('Moose::Meta::Role'))
38 || confess "The list of roles must be instances of Moose::Meta::Role, not $_"
39 foreach @{$params{roles}};
40 # and the name is created from the
41 # roles if one has not been provided
42 $params{name} ||= (join "|" => map { $_->name } @{$params{roles}});
e606ae5f 43 $class->_new(\%params);
fb1e11d5 44}
45
46# NOTE:
47# we need to override this cause
48# we dont have that package I was
49# talking about above.
50# - SL
51sub alias_method {
52 my ($self, $method_name, $method) = @_;
53 (defined $method_name && $method_name)
54 || confess "You must define a method name";
55
c4538447 56 # make sure to bless the
57 # method if nessecary
1b2aea39 58 $method = $self->method_metaclass->wrap(
59 $method,
60 package_name => $self->name,
61 name => $method_name
62 ) if !blessed($method);
fb1e11d5 63
c4538447 64 $self->get_method_map->{$method_name} = $method;
fb1e11d5 65}
66
671;
68
69__END__
70
71=pod
72
73=head1 NAME
74
75Moose::Meta::Role::Composite - An object to represent the set of roles
76
77=head1 DESCRIPTION
78
79=head2 METHODS
80
81=over 4
82
83=item B<new>
84
85=item B<meta>
86
87=item B<name>
88
89=item B<get_method_map>
90
91=item B<alias_method>
92
93=back
94
95=head1 BUGS
96
97All complex software has bugs lurking in it, and this module is no
98exception. If you find a bug please either email me, or add the bug
99to cpan-RT.
100
101=head1 AUTHOR
102
103Stevan Little E<lt>stevan@iinteractive.comE<gt>
104
105=head1 COPYRIGHT AND LICENSE
106
778db3ac 107Copyright 2006-2008 by Infinity Interactive, Inc.
fb1e11d5 108
109L<http://www.iinteractive.com>
110
111This library is free software; you can redistribute it and/or modify
112it under the same terms as Perl itself.
113
e606ae5f 114=cut