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 my $meta = Mouse::Meta::Role->initialize(scalar caller);
35 Mouse::Util::apply_all_roles($meta->name, @_);
40 my $meta = Mouse::Meta::Role->initialize(scalar caller);
43 $meta->throw_error(q{Usage: has 'name' => ( key => value, ... )})
44 if @_ % 2; # odd number of arguments
46 if(ref $name){ # has [qw(foo bar)] => (...)
48 $meta->add_attribute($_ => @_);
51 else{ # has foo => (...)
52 $meta->add_attribute($name => @_);
58 my $meta = Mouse::Meta::Role->initialize(scalar caller);
62 $meta->add_before_method_modifier($_ => $code);
68 my $meta = Mouse::Meta::Role->initialize(scalar caller);
72 $meta->add_after_method_modifier($_ => $code);
78 my $meta = Mouse::Meta::Role->initialize(scalar caller);
82 $meta->add_around_method_modifier($_ => $code);
89 return if !defined $Mouse::SUPER_BODY;
90 $Mouse::SUPER_BODY->(@Mouse::SUPER_ARGS);
94 # my($name, $code) = @_;
95 Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_);
99 # We keep the same errors messages as Moose::Role emits, here.
101 Carp::croak "Roles cannot support 'inner'";
105 Carp::croak "Roles cannot support 'augment'";
109 my $meta = Mouse::Meta::Role->initialize(scalar caller);
110 $meta->throw_error("Must specify at least one method") unless @_;
111 $meta->add_required_methods(@_);
123 my $class = $args{for_class}
124 or Carp::confess("Cannot call init_meta without specifying a for_class");
126 my $metaclass = $args{metaclass} || 'Mouse::Meta::Role';
128 my $meta = $metaclass->initialize($class);
130 $meta->add_method(meta => sub{
131 $metaclass->initialize(ref($_[0]) || $_[0]);
134 # make a role type for each Mouse role
135 Mouse::Util::TypeConstraints::role_type($class)
136 unless Mouse::Util::TypeConstraints::find_type_constraint($class);
147 Mouse::Role - The Mouse Role
151 This document describes Mouse version 0.49
160 =head2 C<< meta -> Mouse::Meta::Role >>
162 Returns this role's metaclass instance.
164 =head2 C<< before (method|methods) -> CodeRef >>
166 Sets up a B<before> method modifier. See L<Moose/before>.
168 =head2 C<< after (method|methods) => CodeRef >>
170 Sets up an B<after> method modifier. See L<Moose/after>.
172 =head2 C<< around (method|methods) => CodeRef >>
174 Sets up an B<around> method modifier. See L<Moose/around>.
178 Sets up the B<super> keyword. See L<Moose/super>.
180 =head2 C<< override method => CodeRef >>
182 Sets up an B<override> method modifier. See L<Moose/Role/override>.
186 This is not supported in roles and emits an error. See L<Moose/Role>.
188 =head2 C<< augment method => CodeRef >>
190 This is not supported in roles and emits an error. See L<Moose/Role>.
192 =head2 C<< has (name|names) => parameters >>
194 Sets up an attribute (or if passed an arrayref of names, multiple attributes) to
195 this role. See L<Mouse/has>.
197 =head2 C<< confess(error) -> BOOM >>
199 L<Carp/confess> for your convenience.
201 =head2 C<< blessed(value) -> ClassName | undef >>
203 L<Scalar::Util/blessed> for your convenience.
209 Importing Mouse::Role will give you sugar.
213 Please unimport (C<< no Mouse::Role >>) so that if someone calls one of the
214 keywords (such as L</has>) it will break loudly instead breaking subtly.