bump version to 0.56 and update changes for release
[gitmo/Moose.git] / lib / Moose / Meta / Role / Composite.pm
1 package Moose::Meta::Role::Composite;
2
3 use strict;
4 use warnings;
5 use metaclass;
6
7 use Carp         'confess';
8 use Scalar::Util 'blessed';
9
10 our $VERSION   = '0.56';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
13
14 use 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
34 sub 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}});
43     $class->_new(\%params);
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
51 sub alias_method {
52     my ($self, $method_name, $method) = @_;
53     (defined $method_name && $method_name)
54         || confess "You must define a method name";
55
56     # make sure to bless the 
57     # method if nessecary 
58     $method = $self->method_metaclass->wrap(
59         $method,
60         package_name => $self->name,
61         name         => $method_name
62     ) if !blessed($method);
63
64     $self->get_method_map->{$method_name} = $method;
65 }
66
67 1;
68
69 __END__
70
71 =pod
72
73 =head1 NAME
74
75 Moose::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
97 All complex software has bugs lurking in it, and this module is no
98 exception. If you find a bug please either email me, or add the bug
99 to cpan-RT.
100
101 =head1 AUTHOR
102
103 Stevan Little E<lt>stevan@iinteractive.comE<gt>
104
105 =head1 COPYRIGHT AND LICENSE
106
107 Copyright 2006-2008 by Infinity Interactive, Inc.
108
109 L<http://www.iinteractive.com>
110
111 This library is free software; you can redistribute it and/or modify
112 it under the same terms as Perl itself.
113
114 =cut