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);
60 for my $name($meta->_collect_methods(@_)) {
61 $meta->add_before_method_modifier($name => $code);
67 my $meta = Mouse::Meta::Role->initialize(scalar caller);
69 for my $name($meta->_collect_methods(@_)) {
70 $meta->add_after_method_modifier($name => $code);
76 my $meta = Mouse::Meta::Role->initialize(scalar caller);
78 for my $name($meta->_collect_methods(@_)) {
79 $meta->add_around_method_modifier($name => $code);
86 return if !defined $Mouse::SUPER_BODY;
87 $Mouse::SUPER_BODY->(@Mouse::SUPER_ARGS);
91 # my($name, $code) = @_;
92 Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_);
96 # We keep the same errors messages as Moose::Role emits, here.
98 Carp::croak "Roles cannot support 'inner'";
102 Carp::croak "Roles cannot support 'augment'";
106 my $meta = Mouse::Meta::Role->initialize(scalar caller);
107 $meta->throw_error("Must specify at least one method") unless @_;
108 $meta->add_required_methods(@_);
120 my $class = $args{for_class}
121 or Carp::confess("Cannot call init_meta without specifying a for_class");
123 my $metaclass = $args{metaclass} || 'Mouse::Meta::Role';
125 my $meta = $metaclass->initialize($class);
127 $meta->add_method(meta => sub{
128 $metaclass->initialize(ref($_[0]) || $_[0]);
131 # make a role type for each Mouse role
132 Mouse::Util::TypeConstraints::role_type($class)
133 unless Mouse::Util::TypeConstraints::find_type_constraint($class);
144 Mouse::Role - The Mouse Role
148 This document describes Mouse version 0.59
157 =head2 C<< meta -> Mouse::Meta::Role >>
159 Returns this role's metaclass instance.
161 =head2 C<< before (method|methods|regexp) -> CodeRef >>
163 Sets up a B<before> method modifier. See L<Moose/before>.
165 =head2 C<< after (method|methods|regexp) => CodeRef >>
167 Sets up an B<after> method modifier. See L<Moose/after>.
169 =head2 C<< around (method|methods|regexp) => CodeRef >>
171 Sets up an B<around> method modifier. See L<Moose/around>.
175 Sets up the B<super> keyword. See L<Moose/super>.
177 =head2 C<< override method => CodeRef >>
179 Sets up an B<override> method modifier. See L<Moose/Role/override>.
183 This is not supported in roles and emits an error. See L<Moose/Role>.
185 =head2 C<< augment method => CodeRef >>
187 This is not supported in roles and emits an error. See L<Moose/Role>.
189 =head2 C<< has (name|names) => parameters >>
191 Sets up an attribute (or if passed an arrayref of names, multiple attributes) to
192 this role. See L<Mouse/has>.
194 =head2 C<< confess(error) -> BOOM >>
196 L<Carp/confess> for your convenience.
198 =head2 C<< blessed(value) -> ClassName | undef >>
200 L<Scalar::Util/blessed> for your convenience.
206 Importing Mouse::Role will give you sugar.
210 Please unimport (C<< no Mouse::Role >>) so that if someone calls one of the
211 keywords (such as L</has>) it will break loudly instead breaking subtly.