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(@_);
112 my($class, %args) = @_;
114 my $for_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($for_class);
121 $meta->add_method(meta => sub{
122 $metaclass->initialize(ref($_[0]) || $_[0]);
134 Mouse::Role - The Mouse Role
143 =head2 C<< meta -> Mouse::Meta::Role >>
145 Returns this role's metaclass instance.
147 =head2 C<< before (method|methods) -> CodeRef >>
149 Sets up a B<before> method modifier. See L<Moose/before> or
150 L<Class::Method::Modifiers/before>.
152 =head2 C<< after (method|methods) => CodeRef >>
154 Sets up an B<after> method modifier. See L<Moose/after> or
155 L<Class::Method::Modifiers/after>.
157 =head2 C<< around (method|methods) => CodeRef >>
159 Sets up an B<around> method modifier. See L<Moose/around> or
160 L<Class::Method::Modifiers/around>.
164 Sets up the B<super> keyword. See L<Moose/super>.
166 =head2 C<< override method => CodeRef >>
168 Sets up an B<override> method modifier. See L<Moose/Role/override>.
172 This is not supported in roles and emits an error. See L<Moose/Role>.
174 =head2 C<< augment method => CodeRef >>
176 This is not supported in roles and emits an error. See L<Moose/Role>.
178 =head2 C<< has (name|names) => parameters >>
180 Sets up an attribute (or if passed an arrayref of names, multiple attributes) to
181 this role. See L<Mouse/has>.
183 =head2 C<< confess(error) -> BOOM >>
185 L<Carp/confess> for your convenience.
187 =head2 C<< blessed(value) -> ClassName | undef >>
189 L<Scalar::Util/blessed> for your convenience.
195 Importing Mouse::Role will give you sugar.
199 Please unimport (C<< no Mouse::Role >>) so that if someone calls one of the
200 keywords (such as L</has>) it will break loudly instead breaking subtly.