2 use Mouse::Exporter; # enables strict and warnings
7 use Scalar::Util qw(blessed);
9 use Mouse::Util qw(not_supported);
10 use Mouse::Meta::Role;
13 Mouse::Exporter->setup_import_methods(
23 \&Scalar::Util::blessed,
30 Carp::croak "Roles do not support 'extends'";
34 Mouse::Util::apply_all_roles(scalar(caller), @_);
39 my $meta = Mouse::Meta::Role->initialize(scalar caller);
42 $meta->throw_error(q{Usage: has 'name' => ( key => value, ... )})
43 if @_ % 2; # odd number of arguments
45 for my $n(ref($name) ? @{$name} : $name){
46 $meta->add_attribute($n => @_);
52 my $meta = Mouse::Meta::Role->initialize(scalar caller);
54 for my $name($meta->_collect_methods(@_)) {
55 $meta->add_before_method_modifier($name => $code);
61 my $meta = Mouse::Meta::Role->initialize(scalar caller);
63 for my $name($meta->_collect_methods(@_)) {
64 $meta->add_after_method_modifier($name => $code);
70 my $meta = Mouse::Meta::Role->initialize(scalar caller);
72 for my $name($meta->_collect_methods(@_)) {
73 $meta->add_around_method_modifier($name => $code);
80 return if !defined $Mouse::SUPER_BODY;
81 $Mouse::SUPER_BODY->(@Mouse::SUPER_ARGS);
85 # my($name, $code) = @_;
86 Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_);
90 # We keep the same errors messages as Moose::Role emits, here.
92 Carp::croak "Roles cannot support 'inner'";
96 Carp::croak "Roles cannot support 'augment'";
100 my $meta = Mouse::Meta::Role->initialize(scalar caller);
101 $meta->throw_error("Must specify at least one method") unless @_;
102 $meta->add_required_methods(@_);
114 my $class = $args{for_class}
115 or Carp::confess("Cannot call init_meta without specifying a for_class");
117 my $metaclass = $args{metaclass} || 'Mouse::Meta::Role';
119 my $meta = $metaclass->initialize($class);
121 $meta->add_method(meta => sub{
122 $metaclass->initialize(ref($_[0]) || $_[0]);
125 # make a role type for each Mouse role
126 Mouse::Util::TypeConstraints::role_type($class)
127 unless Mouse::Util::TypeConstraints::find_type_constraint($class);
138 Mouse::Role - The Mouse Role
142 This document describes Mouse version 0.72
151 =head2 C<< meta -> Mouse::Meta::Role >>
153 Returns this role's metaclass instance.
155 =head2 C<< before (method|methods|regexp) -> CodeRef >>
157 Sets up a B<before> method modifier. See L<Moose/before>.
159 =head2 C<< after (method|methods|regexp) => CodeRef >>
161 Sets up an B<after> method modifier. See L<Moose/after>.
163 =head2 C<< around (method|methods|regexp) => CodeRef >>
165 Sets up an B<around> method modifier. See L<Moose/around>.
169 Sets up the B<super> keyword. See L<Moose/super>.
171 =head2 C<< override method => CodeRef >>
173 Sets up an B<override> method modifier. See L<Moose/Role/override>.
177 This is not supported in roles and emits an error. See L<Moose/Role>.
179 =head2 C<< augment method => CodeRef >>
181 This is not supported in roles and emits an error. See L<Moose/Role>.
183 =head2 C<< has (name|names) => parameters >>
185 Sets up an attribute (or if passed an arrayref of names, multiple attributes) to
186 this role. See L<Mouse/has>.
188 =head2 C<< confess(error) -> BOOM >>
190 L<Carp/confess> for your convenience.
192 =head2 C<< blessed(value) -> ClassName | undef >>
194 L<Scalar::Util/blessed> for your convenience.
200 Importing Mouse::Role will give you sugar.
204 Please unimport (C<< no Mouse::Role >>) so that if someone calls one of the
205 keywords (such as L</has>) it will break loudly instead breaking subtly.