moving stuff around and some cleanup
[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
57 my $body = (blessed($method) ? $method->body : $method);
58 ('CODE' eq (reftype($body) || ''))
59 || confess "Your code block must be a CODE reference";
60
61 $self->get_method_map->{$method_name} = $body;
62}
63
641;
65
66__END__
67
68=pod
69
70=head1 NAME
71
72Moose::Meta::Role::Composite - An object to represent the set of roles
73
74=head1 DESCRIPTION
75
76=head2 METHODS
77
78=over 4
79
80=item B<new>
81
82=item B<meta>
83
84=item B<name>
85
86=item B<get_method_map>
87
88=item B<alias_method>
89
90=back
91
92=head1 BUGS
93
94All complex software has bugs lurking in it, and this module is no
95exception. If you find a bug please either email me, or add the bug
96to cpan-RT.
97
98=head1 AUTHOR
99
100Stevan Little E<lt>stevan@iinteractive.comE<gt>
101
102=head1 COPYRIGHT AND LICENSE
103
104Copyright 2006, 2007 by Infinity Interactive, Inc.
105
106L<http://www.iinteractive.com>
107
108This library is free software; you can redistribute it and/or modify
109it under the same terms as Perl itself.
110
111=cut