1 package Mouse::Meta::Role::Composite;
2 use Mouse::Util qw(english_list); # enables strict and warnings
4 our @ISA = qw(Mouse::Meta::Role);
8 return keys %{ $self->{methods} };
12 my($self, $method_name, $code, $role) = @_;
14 if( ($self->{methods}{$method_name} || 0) == $code){
15 # This role already has the same method.
19 if($method_name ne 'meta'){
20 my $roles = $self->{composed_roles_by_method}{$method_name} ||= [];
21 push @{$roles}, $role;
23 $self->{conflicting_methods}{$method_name}++;
27 $self->{methods}{$method_name} = $code;
28 # no need to add a subroutine to the stash
33 my($self, $method_name) = @_;
34 return $self->{methods}{$method_name};
38 # my($self, $method_name) = @_;
39 return 0; # to fool _apply_methods() in combine()
43 # my($self, $method_name) = @_;
44 return 0; # to fool _appply_attributes() in combine()
47 sub has_override_method_modifier{
48 # my($self, $method_name) = @_;
49 return 0; # to fool _apply_modifiers() in combine()
54 my $attr_name = shift;
55 my $spec = (@_ == 1 ? $_[0] : {@_});
57 my $existing = $self->{attributes}{$attr_name};
58 if($existing && $existing != $spec){
59 $self->throw_error("We have encountered an attribute conflict with '$attr_name' "
60 . "during composition. This is fatal error and cannot be disambiguated.");
62 $self->SUPER::add_attribute($attr_name, $spec);
66 sub add_override_method_modifier{
67 my($self, $method_name, $code) = @_;
69 my $existing = $self->{override_method_modifiers}{$method_name};
70 if($existing && $existing != $code){
71 $self->throw_error( "We have encountered an 'override' method conflict with '$method_name' during "
72 . "composition (Two 'override' methods of the same name encountered). "
73 . "This is fatal error.")
75 $self->SUPER::add_override_method_modifier($method_name, $code);
79 # components of apply()
82 my($self, $applicant, $args) = @_;
84 if(exists $self->{conflicting_methods}){
85 my $applicant_class_name = $applicant->name;
87 my @conflicting = sort grep{ !$applicant_class_name->can($_) } keys %{ $self->{conflicting_methods} };
89 if(@conflicting == 1){
90 my $method_name = $conflicting[0];
91 my @roles = sort @{ $self->{composed_roles_by_method}{$method_name} };
93 sprintf q{Due to a method name conflict in roles %s, the method '%s' must be implemented or excluded by '%s'},
94 english_list(map{ sprintf q{'%s'}, $_->name } @roles), $method_name, $applicant->name
97 elsif(@conflicting > 1){
98 my $methods = english_list(map{ sprintf q{'%s'}, $_ } @conflicting);
101 my $roles = english_list(
102 sort map{ my $name = $_->name; $seen{$name}++ ? () : sprintf q{'%s'}, $name }
103 map{ @{$_} } @{ $self->{composed_roles_by_method} }{@conflicting}
107 sprintf q{Due to method name conflicts in roles %s, the methods %s must be implemented or excluded by '%s'},
108 $roles, $methods, $applicant->name
113 $self->SUPER::_apply_methods($applicant, $args);
121 Mouse::Meta::Role::Composite - An object to represent the set of roles
125 This document describes Mouse version 0.48
129 L<Moose::Meta::Role::Composite>