/usr/lib/perl5/Mouse/Role.pm is in libmouse-perl 2.1.0-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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | package Mouse::Role;
use Mouse::Exporter; # enables strict and warnings
our $VERSION = '2.1.0';
use Carp ();
use Scalar::Util ();
use Mouse ();
Mouse::Exporter->setup_import_methods(
as_is => [qw(
extends with
has
before after around
override super
augment inner
requires excludes
),
\&Scalar::Util::blessed,
\&Carp::confess,
],
);
sub extends {
Carp::croak "Roles do not support 'extends'";
}
sub with {
Mouse::Util::apply_all_roles(scalar(caller), @_);
return;
}
sub has {
my $meta = Mouse::Meta::Role->initialize(scalar caller);
my $name = shift;
$meta->throw_error(q{Usage: has 'name' => ( key => value, ... )})
if @_ % 2; # odd number of arguments
for my $n(ref($name) ? @{$name} : $name){
$meta->add_attribute($n => @_);
}
return;
}
sub before {
my $meta = Mouse::Meta::Role->initialize(scalar caller);
my $code = pop;
for my $name($meta->_collect_methods(@_)) {
$meta->add_before_method_modifier($name => $code);
}
return;
}
sub after {
my $meta = Mouse::Meta::Role->initialize(scalar caller);
my $code = pop;
for my $name($meta->_collect_methods(@_)) {
$meta->add_after_method_modifier($name => $code);
}
return;
}
sub around {
my $meta = Mouse::Meta::Role->initialize(scalar caller);
my $code = pop;
for my $name($meta->_collect_methods(@_)) {
$meta->add_around_method_modifier($name => $code);
}
return;
}
sub super {
return if !defined $Mouse::SUPER_BODY;
$Mouse::SUPER_BODY->(@Mouse::SUPER_ARGS);
}
sub override {
# my($name, $code) = @_;
Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_);
return;
}
# We keep the same errors messages as Moose::Role emits, here.
sub inner {
Carp::croak "Roles cannot support 'inner'";
}
sub augment {
Carp::croak "Roles cannot support 'augment'";
}
sub requires {
my $meta = Mouse::Meta::Role->initialize(scalar caller);
$meta->throw_error("Must specify at least one method") unless @_;
$meta->add_required_methods(@_);
return;
}
sub excludes {
Mouse::Util::not_supported();
}
sub init_meta{
shift;
my %args = @_;
my $class = $args{for_class}
or Carp::confess("Cannot call init_meta without specifying a for_class");
my $metaclass = $args{metaclass} || 'Mouse::Meta::Role';
my $meta = $metaclass->initialize($class);
$meta->add_method(meta => sub{
$metaclass->initialize(ref($_[0]) || $_[0]);
});
# make a role type for each Mouse role
Mouse::Util::TypeConstraints::role_type($class)
unless Mouse::Util::TypeConstraints::find_type_constraint($class);
return $meta;
}
1;
__END__
=head1 NAME
Mouse::Role - The Mouse Role
=head1 VERSION
This document describes Mouse version 2.1.0
=head1 SYNOPSIS
package Comparable;
use Mouse::Role; # the package is now a Mouse role
# Declare methods that are required by this role
requires qw(compare);
# Define methods this role provides
sub equals {
my($self, $other) = @_;
return $self->compare($other) == 0;
}
# and later
package MyObject;
use Mouse;
with qw(Comparable); # Now MyObject can equals()
sub compare {
# ...
}
my $foo = MyObject->new();
my $bar = MyObject->new();
$obj->equals($bar); # yes, it is comparable
=head1 DESCRIPTION
This module declares the caller class to be a Mouse role.
The concept of roles is documented in L<Moose::Manual::Roles>.
This document serves as API documentation.
=head1 EXPORTED FUNCTIONS
Mouse::Role supports all of the functions that Mouse exports, but
differs slightly in how some items are handled (see L</CAVEATS> below
for details).
Mouse::Role also offers two role-specific keywords:
=head2 C<< requires(@method_names) >>
Roles can require that certain methods are implemented by any class which
C<does> the role.
Note that attribute accessors also count as methods for the purposes of
satisfying the requirements of a role.
=head2 C<< excludes(@role_names) >>
This is exported but not implemented in Mouse.
=head1 IMPORT AND UNIMPORT
=head2 import
Importing Mouse::Role will give you sugar. C<-traits> are also supported.
=head2 unimport
Please unimport (C<< no Mouse::Role >>) so that if someone calls one of the
keywords (such as L</has>) it will break loudly instead breaking subtly.
=head1 CAVEATS
Role support has only a few caveats:
=over
=item *
Roles cannot use the C<extends> keyword; it will throw an exception for now.
The same is true of the C<augment> and C<inner> keywords (not sure those
really make sense for roles). All other Mouse keywords will be I<deferred>
so that they can be applied to the consuming class.
=item *
Role composition does its best to B<not> be order-sensitive when it comes to
conflict resolution and requirements detection. However, it is order-sensitive
when it comes to method modifiers. All before/around/after modifiers are
included whenever a role is composed into a class, and then applied in the order
in which the roles are used. This also means that there is no conflict for
before/around/after modifiers.
In most cases, this will be a non-issue; however, it is something to keep in
mind when using method modifiers in a role. You should never assume any
ordering.
=back
=head1 SEE ALSO
L<Mouse>
L<Moose::Role>
L<Moose::Manual::Roles>
L<Moose::Spec::Role>
=cut
|