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 for my $n(ref($name) ? @{$name} : $name){
47 $meta->add_attribute($n => @_);
53 my $meta = Mouse::Meta::Role->initialize(scalar caller);
55 for my $name($meta->_collect_methods(@_)) {
56 $meta->add_before_method_modifier($name => $code);
62 my $meta = Mouse::Meta::Role->initialize(scalar caller);
64 for my $name($meta->_collect_methods(@_)) {
65 $meta->add_after_method_modifier($name => $code);
71 my $meta = Mouse::Meta::Role->initialize(scalar caller);
73 for my $name($meta->_collect_methods(@_)) {
74 $meta->add_around_method_modifier($name => $code);
81 return if !defined $Mouse::SUPER_BODY;
82 $Mouse::SUPER_BODY->(@Mouse::SUPER_ARGS);
86 # my($name, $code) = @_;
87 Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_);
91 # We keep the same errors messages as Moose::Role emits, here.
93 Carp::croak "Roles cannot support 'inner'";
97 Carp::croak "Roles cannot support 'augment'";
101 my $meta = Mouse::Meta::Role->initialize(scalar caller);
102 $meta->throw_error("Must specify at least one method") unless @_;
103 $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
143 This document describes Mouse version 0.70
152 =head2 C<< meta -> Mouse::Meta::Role >>
154 Returns this role's metaclass instance.
156 =head2 C<< before (method|methods|regexp) -> CodeRef >>
158 Sets up a B<before> method modifier. See L<Moose/before>.
160 =head2 C<< after (method|methods|regexp) => CodeRef >>
162 Sets up an B<after> method modifier. See L<Moose/after>.
164 =head2 C<< around (method|methods|regexp) => CodeRef >>
166 Sets up an B<around> method modifier. See L<Moose/around>.
170 Sets up the B<super> keyword. See L<Moose/super>.
172 =head2 C<< override method => CodeRef >>
174 Sets up an B<override> method modifier. See L<Moose/Role/override>.
178 This is not supported in roles and emits an error. See L<Moose/Role>.
180 =head2 C<< augment method => CodeRef >>
182 This is not supported in roles and emits an error. See L<Moose/Role>.
184 =head2 C<< has (name|names) => parameters >>
186 Sets up an attribute (or if passed an arrayref of names, multiple attributes) to
187 this role. See L<Mouse/has>.
189 =head2 C<< confess(error) -> BOOM >>
191 L<Carp/confess> for your convenience.
193 =head2 C<< blessed(value) -> ClassName | undef >>
195 L<Scalar::Util/blessed> for your convenience.
201 Importing Mouse::Role will give you sugar.
205 Please unimport (C<< no Mouse::Role >>) so that if someone calls one of the
206 keywords (such as L</has>) it will break loudly instead breaking subtly.