2 use Mouse::Exporter; # enables strict and warnings
7 use Scalar::Util qw(blessed);
11 Mouse::Exporter->setup_import_methods(
21 \&Scalar::Util::blessed,
28 Carp::croak "Roles do not support 'extends'";
32 Mouse::Util::apply_all_roles(scalar(caller), @_);
37 my $meta = Mouse::Meta::Role->initialize(scalar caller);
40 $meta->throw_error(q{Usage: has 'name' => ( key => value, ... )})
41 if @_ % 2; # odd number of arguments
43 for my $n(ref($name) ? @{$name} : $name){
44 $meta->add_attribute($n => @_);
50 my $meta = Mouse::Meta::Role->initialize(scalar caller);
52 for my $name($meta->_collect_methods(@_)) {
53 $meta->add_before_method_modifier($name => $code);
59 my $meta = Mouse::Meta::Role->initialize(scalar caller);
61 for my $name($meta->_collect_methods(@_)) {
62 $meta->add_after_method_modifier($name => $code);
68 my $meta = Mouse::Meta::Role->initialize(scalar caller);
70 for my $name($meta->_collect_methods(@_)) {
71 $meta->add_around_method_modifier($name => $code);
78 return if !defined $Mouse::SUPER_BODY;
79 $Mouse::SUPER_BODY->(@Mouse::SUPER_ARGS);
83 # my($name, $code) = @_;
84 Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_);
88 # We keep the same errors messages as Moose::Role emits, here.
90 Carp::croak "Roles cannot support 'inner'";
94 Carp::croak "Roles cannot support 'augment'";
98 my $meta = Mouse::Meta::Role->initialize(scalar caller);
99 $meta->throw_error("Must specify at least one method") unless @_;
100 $meta->add_required_methods(@_);
105 Mouse::Util::not_supported();
112 my $class = $args{for_class}
113 or Carp::confess("Cannot call init_meta without specifying a for_class");
115 my $metaclass = $args{metaclass} || 'Mouse::Meta::Role';
117 my $meta = $metaclass->initialize($class);
119 $meta->add_method(meta => sub{
120 $metaclass->initialize(ref($_[0]) || $_[0]);
123 # make a role type for each Mouse role
124 Mouse::Util::TypeConstraints::role_type($class)
125 unless Mouse::Util::TypeConstraints::find_type_constraint($class);
136 Mouse::Role - The Mouse Role
140 This document describes Mouse version 0.76
149 =head2 C<< meta -> Mouse::Meta::Role >>
151 Returns this role's metaclass instance.
153 =head2 C<< before (method|methods|regexp) -> CodeRef >>
155 Sets up a B<before> method modifier. See L<Moose/before>.
157 =head2 C<< after (method|methods|regexp) => CodeRef >>
159 Sets up an B<after> method modifier. See L<Moose/after>.
161 =head2 C<< around (method|methods|regexp) => CodeRef >>
163 Sets up an B<around> method modifier. See L<Moose/around>.
167 Sets up the B<super> keyword. See L<Moose/super>.
169 =head2 C<< override method => CodeRef >>
171 Sets up an B<override> method modifier. See L<Moose/Role/override>.
175 This is not supported in roles and emits an error. See L<Moose/Role>.
177 =head2 C<< augment method => CodeRef >>
179 This is not supported in roles and emits an error. See L<Moose/Role>.
181 =head2 C<< has (name|names) => parameters >>
183 Sets up an attribute (or if passed an arrayref of names, multiple attributes) to
184 this role. See L<Mouse/has>.
186 =head2 C<< confess(error) -> BOOM >>
188 L<Carp/confess> for your convenience.
190 =head2 C<< blessed(value) -> ClassName | undef >>
192 L<Scalar::Util/blessed> for your convenience.
198 Importing Mouse::Role will give you sugar.
202 Please unimport (C<< no Mouse::Role >>) so that if someone calls one of the
203 keywords (such as L</has>) it will break loudly instead breaking subtly.