/usr/lib/perl5/Mouse/Meta/Role/Composite.pm is in libmouse-perl 0.97-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | package Mouse::Meta::Role::Composite;
use Mouse::Util; # enables strict and warnings
use Mouse::Meta::Role;
use Mouse::Meta::Role::Application;
our @ISA = qw(Mouse::Meta::Role);
# FIXME: Mouse::Meta::Role::Composite does things in different way from Moose's
# Moose: creates a new class for the consumer, and applies roles to it.
# Mouse: creates a coposite role and apply roles to the role,
# and then applies it to the consumer.
sub new {
my $class = shift;
my $args = $class->Mouse::Object::BUILDARGS(@_);
my $roles = delete $args->{roles};
my $self = $class->create_anon_role(%{$args});
foreach my $role_spec(@{$roles}) {
my($role, $args) = ref($role_spec) eq 'ARRAY'
? @{$role_spec}
: ($role_spec, {});
$role->apply($self, %{$args});
}
return $self;
}
sub get_method_list {
my($self) = @_;
return keys %{ $self->{methods} };
}
sub add_method {
my($self, $method_name, $code, $role) = @_;
if( ($self->{methods}{$method_name} || 0) == $code){
# This role already has the same method.
return;
}
if($method_name eq 'meta'){
$self->SUPER::add_method($method_name => $code);
}
else{
# no need to add a subroutine to the stash
my $roles = $self->{composed_roles_by_method}{$method_name} ||= [];
push @{$roles}, $role;
if(@{$roles} > 1){
$self->{conflicting_methods}{$method_name}++;
}
$self->{methods}{$method_name} = $code;
}
return;
}
sub get_method_body {
my($self, $method_name) = @_;
return $self->{methods}{$method_name};
}
sub has_method {
# my($self, $method_name) = @_;
return 0; # to fool apply_methods() in combine()
}
sub has_attribute {
# my($self, $method_name) = @_;
return 0; # to fool appply_attributes() in combine()
}
sub has_override_method_modifier {
# my($self, $method_name) = @_;
return 0; # to fool apply_modifiers() in combine()
}
sub add_attribute {
my $self = shift;
my $attr_name = shift;
my $spec = (@_ == 1 ? $_[0] : {@_});
my $existing = $self->{attributes}{$attr_name};
if($existing && $existing != $spec){
$self->throw_error("We have encountered an attribute conflict with '$attr_name' "
. "during composition. This is fatal error and cannot be disambiguated.");
}
$self->SUPER::add_attribute($attr_name, $spec);
return;
}
sub add_override_method_modifier {
my($self, $method_name, $code) = @_;
my $existing = $self->{override_method_modifiers}{$method_name};
if($existing && $existing != $code){
$self->throw_error( "We have encountered an 'override' method conflict with '$method_name' during "
. "composition (Two 'override' methods of the same name encountered). "
. "This is fatal error.")
}
$self->SUPER::add_override_method_modifier($method_name, $code);
return;
}
sub apply {
my $self = shift;
my $consumer = shift;
Mouse::Meta::Role::Application::RoleSummation->new(@_)->apply($self, $consumer);
return;
}
package Mouse::Meta::Role::Application::RoleSummation;
our @ISA = qw(Mouse::Meta::Role::Application);
sub apply_methods {
my($self, $role, $consumer, @extra) = @_;
if(exists $role->{conflicting_methods}){
my $consumer_class_name = $consumer->name;
my @conflicting = grep{ !$consumer_class_name->can($_) }
keys %{ $role->{conflicting_methods} };
if(@conflicting) {
my $method_name_conflict = (@conflicting == 1
? 'a method name conflict'
: 'method name conflicts');
my %seen;
my $roles = Mouse::Util::quoted_english_list(
grep{ !$seen{$_}++ } # uniq
map { $_->name }
map { @{$_} }
@{ $role->{composed_roles_by_method} }{@conflicting}
);
$self->throw_error(sprintf
q{Due to %s in roles %s,}
. q{ the method%s %s must be implemented or excluded by '%s'},
$method_name_conflict,
$roles,
(@conflicting > 1 ? 's' : ''),
Mouse::Util::quoted_english_list(@conflicting),
$consumer_class_name);
}
}
$self->SUPER::apply_methods($role, $consumer, @extra);
return;
}
package Mouse::Meta::Role::Composite;
1;
__END__
=head1 NAME
Mouse::Meta::Role::Composite - An object to represent the set of roles
=head1 VERSION
This document describes Mouse version 0.97
=head1 SEE ALSO
L<Moose::Meta::Role::Composite>
=cut
|