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