2 use Mouse::Exporter; # enables strict and warnings
7 use Scalar::Util qw(blessed);
9 use Mouse::Util qw(not_supported);
13 Mouse::Exporter->setup_import_methods(
23 \&Scalar::Util::blessed,
28 # XXX: for backward compatibility
42 my $meta = Mouse::Meta::Role->initialize(scalar caller);
46 $meta->add_before_method_modifier($_ => $code);
51 my $meta = Mouse::Meta::Role->initialize(scalar caller);
55 $meta->add_after_method_modifier($_ => $code);
60 my $meta = Mouse::Meta::Role->initialize(scalar caller);
64 $meta->add_around_method_modifier($_ => $code);
70 return if !defined $Mouse::SUPER_BODY;
71 $Mouse::SUPER_BODY->(@Mouse::SUPER_ARGS);
75 # my($name, $code) = @_;
76 Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_);
79 # We keep the same errors messages as Moose::Role emits, here.
81 Carp::croak "Roles cannot support 'inner'";
85 Carp::croak "Roles cannot support 'augment'";
89 my $meta = Mouse::Meta::Role->initialize(scalar caller);
92 $meta->add_attribute($_ => @_) for ref($name) ? @{$name} : $name;
96 Carp::croak "Roles do not support 'extends'"
100 my $meta = Mouse::Meta::Role->initialize(scalar caller);
101 Mouse::Util::apply_all_roles($meta->name, @_);
105 my $meta = Mouse::Meta::Role->initialize(scalar caller);
106 $meta->throw_error("Must specify at least one method") unless @_;
107 $meta->add_required_methods(@_);
118 my $class = $args{for_class}
119 or Carp::confess("Cannot call init_meta without specifying a for_class");
121 my $metaclass = $args{metaclass} || 'Mouse::Meta::Role';
123 my $meta = $metaclass->initialize($class);
125 $meta->add_method(meta => sub{
126 $metaclass->initialize(ref($_[0]) || $_[0]);
129 # make a role type for each Mouse role
130 Mouse::Util::TypeConstraints::role_type($class)
131 unless Mouse::Util::TypeConstraints::find_type_constraint($class);
142 Mouse::Role - The Mouse Role
146 This document describes Mouse version 0.40
155 =head2 C<< meta -> Mouse::Meta::Role >>
157 Returns this role's metaclass instance.
159 =head2 C<< before (method|methods) -> CodeRef >>
161 Sets up a B<before> method modifier. See L<Moose/before> or
162 L<Class::Method::Modifiers/before>.
164 =head2 C<< after (method|methods) => CodeRef >>
166 Sets up an B<after> method modifier. See L<Moose/after> or
167 L<Class::Method::Modifiers/after>.
169 =head2 C<< around (method|methods) => CodeRef >>
171 Sets up an B<around> method modifier. See L<Moose/around> or
172 L<Class::Method::Modifiers/around>.
176 Sets up the B<super> keyword. See L<Moose/super>.
178 =head2 C<< override method => CodeRef >>
180 Sets up an B<override> method modifier. See L<Moose/Role/override>.
184 This is not supported in roles and emits an error. See L<Moose/Role>.
186 =head2 C<< augment method => CodeRef >>
188 This is not supported in roles and emits an error. See L<Moose/Role>.
190 =head2 C<< has (name|names) => parameters >>
192 Sets up an attribute (or if passed an arrayref of names, multiple attributes) to
193 this role. See L<Mouse/has>.
195 =head2 C<< confess(error) -> BOOM >>
197 L<Carp/confess> for your convenience.
199 =head2 C<< blessed(value) -> ClassName | undef >>
201 L<Scalar::Util/blessed> for your convenience.
207 Importing Mouse::Role will give you sugar.
211 Please unimport (C<< no Mouse::Role >>) so that if someone calls one of the
212 keywords (such as L</has>) it will break loudly instead breaking subtly.