2 use Mouse::Util qw(not_supported); # enables strict and warnings
5 use Scalar::Util qw(blessed);
10 Mouse::Exporter->setup_import_methods(
20 \&Scalar::Util::blessed,
25 # XXX: for backward compatibility
39 my $meta = Mouse::Meta::Role->initialize(scalar caller);
43 $meta->add_before_method_modifier($_ => $code);
48 my $meta = Mouse::Meta::Role->initialize(scalar caller);
52 $meta->add_after_method_modifier($_ => $code);
57 my $meta = Mouse::Meta::Role->initialize(scalar caller);
61 $meta->add_around_method_modifier($_ => $code);
67 return if !defined $Mouse::SUPER_BODY;
68 $Mouse::SUPER_BODY->(@Mouse::SUPER_ARGS);
72 # my($name, $code) = @_;
73 Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_);
76 # We keep the same errors messages as Moose::Role emits, here.
78 Carp::croak "Roles cannot support 'inner'";
82 Carp::croak "Roles cannot support 'augment'";
86 my $meta = Mouse::Meta::Role->initialize(scalar caller);
89 $meta->add_attribute($_ => @_) for ref($name) ? @{$name} : $name;
93 Carp::croak "Roles do not support 'extends'"
97 my $meta = Mouse::Meta::Role->initialize(scalar caller);
98 Mouse::Util::apply_all_roles($meta->name, @_);
102 my $meta = Mouse::Meta::Role->initialize(scalar caller);
103 $meta->throw_error("Must specify at least one method") unless @_;
104 $meta->add_required_methods(@_);
115 my $class = $args{for_class}
116 or Carp::confess("Cannot call init_meta without specifying a for_class");
118 my $metaclass = $args{metaclass} || 'Mouse::Meta::Role';
120 my $meta = $metaclass->initialize($class);
122 $meta->add_method(meta => sub{
123 $metaclass->initialize(ref($_[0]) || $_[0]);
126 # make a role type for each Mouse role
127 Mouse::Util::TypeConstraints::role_type($class)
128 unless Mouse::Util::TypeConstraints::find_type_constraint($class);
139 Mouse::Role - The Mouse Role
148 =head2 C<< meta -> Mouse::Meta::Role >>
150 Returns this role's metaclass instance.
152 =head2 C<< before (method|methods) -> CodeRef >>
154 Sets up a B<before> method modifier. See L<Moose/before> or
155 L<Class::Method::Modifiers/before>.
157 =head2 C<< after (method|methods) => CodeRef >>
159 Sets up an B<after> method modifier. See L<Moose/after> or
160 L<Class::Method::Modifiers/after>.
162 =head2 C<< around (method|methods) => CodeRef >>
164 Sets up an B<around> method modifier. See L<Moose/around> or
165 L<Class::Method::Modifiers/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.