bump version to 1.19
[gitmo/Moose.git] / lib / Moose / Meta / Class.pm
CommitLineData
c0e30cf5 1
2package Moose::Meta::Class;
3
4use strict;
5use warnings;
6
0addec44 7use Class::MOP;
648e79ae 8
590e8894 9use Carp qw( confess );
2e7f6cf4 10use Data::OptList;
f8b6827f 11use List::Util qw( first );
349cda54 12use List::MoreUtils qw( any all uniq first_index );
21f1e231 13use Scalar::Util 'weaken', 'blessed';
a15dff8d 14
245478d5 15our $VERSION = '1.19';
e606ae5f 16$VERSION = eval $VERSION;
d44714be 17our $AUTHORITY = 'cpan:STEVAN';
bc1e29b5 18
74862722 19use Moose::Meta::Method::Overridden;
3f9e4b0a 20use Moose::Meta::Method::Augmented;
77f14411 21use Moose::Error::Default;
0fa70d03 22use Moose::Meta::Class::Immutable::Trait;
23use Moose::Meta::Method::Constructor;
24use Moose::Meta::Method::Destructor;
699a2e32 25use Moose::Meta::Method::Meta;
61907a02 26use Moose::Util;
d2782813 27use Class::MOP::MiniTrait;
8ee73eeb 28
c0e30cf5 29use base 'Class::MOP::Class';
30
d2782813 31Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
32
598340d5 33__PACKAGE__->meta->add_attribute('roles' => (
ef333f17 34 reader => 'roles',
35 default => sub { [] }
36));
37
a9b63d79 38__PACKAGE__->meta->add_attribute('role_applications' => (
639f9a1a 39 reader => '_get_role_applications',
a9b63d79 40 default => sub { [] }
41));
42
0fa70d03 43__PACKAGE__->meta->add_attribute(
44 Class::MOP::Attribute->new('immutable_trait' => (
45 accessor => "immutable_trait",
46 default => 'Moose::Meta::Class::Immutable::Trait',
47 ))
48);
49
e606ae5f 50__PACKAGE__->meta->add_attribute('constructor_class' => (
51 accessor => 'constructor_class',
e0001338 52 default => 'Moose::Meta::Method::Constructor',
e606ae5f 53));
54
55__PACKAGE__->meta->add_attribute('destructor_class' => (
56 accessor => 'destructor_class',
e0001338 57 default => 'Moose::Meta::Method::Destructor',
e606ae5f 58));
59
11c86f15 60__PACKAGE__->meta->add_attribute('error_class' => (
bf6fa6b3 61 accessor => 'error_class',
62 default => 'Moose::Error::Default',
11c86f15 63));
64
590868a3 65sub initialize {
66 my $class = shift;
67 my $pkg = shift;
d03bd989 68 return Class::MOP::get_metaclass_by_name($pkg)
685f7e44 69 || $class->SUPER::initialize($pkg,
70 'attribute_metaclass' => 'Moose::Meta::Attribute',
71 'method_metaclass' => 'Moose::Meta::Method',
72 'instance_metaclass' => 'Moose::Meta::Instance',
73 @_
d03bd989 74 );
ac2dc464 75}
590868a3 76
61bdd94f 77sub create {
7d4035ae 78 my ($class, $package_name, %options) = @_;
d03bd989 79
61bdd94f 80 (ref $options{roles} eq 'ARRAY')
7d4035ae 81 || $class->throw_error("You must pass an ARRAY ref of roles", data => $options{roles})
61bdd94f 82 if exists $options{roles};
310ba883 83 my $roles = delete $options{roles};
dd37a5be 84
7d4035ae 85 my $new_meta = $class->SUPER::create($package_name, %options);
dd37a5be 86
310ba883 87 if ($roles) {
7d4035ae 88 Moose::Util::apply_all_roles( $new_meta, @$roles );
61bdd94f 89 }
d03bd989 90
7d4035ae 91 return $new_meta;
61bdd94f 92}
93
17594769 94my %ANON_CLASSES;
95
96sub create_anon_class {
97 my ($self, %options) = @_;
98
99 my $cache_ok = delete $options{cache};
d03bd989 100
cf600c83 101 my $cache_key
102 = _anon_cache_key( $options{superclasses}, $options{roles} );
d03bd989 103
6d5cbd2b 104 if ($cache_ok && defined $ANON_CLASSES{$cache_key}) {
17594769 105 return $ANON_CLASSES{$cache_key};
106 }
d03bd989 107
dcc8dc06 108 $options{weaken} = !$cache_ok
109 unless exists $options{weaken};
110
17594769 111 my $new_class = $self->SUPER::create_anon_class(%options);
112
dcc8dc06 113 if ($cache_ok) {
114 $ANON_CLASSES{$cache_key} = $new_class;
115 weaken($ANON_CLASSES{$cache_key});
116 }
17594769 117
118 return $new_class;
119}
120
699a2e32 121sub _meta_method_class { 'Moose::Meta::Method::Meta' }
122
cf600c83 123sub _anon_cache_key {
124 # Makes something like Super::Class|Super::Class::2=Role|Role::1
125 return join '=' => (
126 join( '|', @{ $_[0] || [] } ),
127 join( '|', sort @{ $_[1] || [] } ),
128 );
129}
130
131sub reinitialize {
132 my $self = shift;
133 my $pkg = shift;
134
135 my $meta = blessed $pkg ? $pkg : Class::MOP::class_of($pkg);
136
137 my $cache_key;
138
139 my %existing_classes;
140 if ($meta) {
141 %existing_classes = map { $_ => $meta->$_() } qw(
142 attribute_metaclass
143 method_metaclass
144 wrapped_method_metaclass
145 instance_metaclass
146 constructor_class
147 destructor_class
148 error_class
149 );
150
151 $cache_key = _anon_cache_key(
152 [ $meta->superclasses ],
153 [ map { $_->name } @{ $meta->roles } ],
154 ) if $meta->is_anon_class;
155 }
156
157 my $new_meta = $self->SUPER::reinitialize(
158 $pkg,
159 %existing_classes,
160 @_,
161 );
162
163 return $new_meta unless defined $cache_key;
164
165 my $new_cache_key = _anon_cache_key(
166 [ $meta->superclasses ],
167 [ map { $_->name } @{ $meta->roles } ],
168 );
169
170 delete $ANON_CLASSES{$cache_key};
171 $ANON_CLASSES{$new_cache_key} = $new_meta;
dcc8dc06 172 weaken($ANON_CLASSES{$new_cache_key});
cf600c83 173
174 return $new_meta;
175}
176
ef333f17 177sub add_role {
178 my ($self, $role) = @_;
179 (blessed($role) && $role->isa('Moose::Meta::Role'))
11c86f15 180 || $self->throw_error("Roles must be instances of Moose::Meta::Role", data => $role);
ef333f17 181 push @{$self->roles} => $role;
182}
183
639f9a1a 184sub role_applications {
185 my ($self) = @_;
186
187 return @{$self->_get_role_applications};
188}
189
a9b63d79 190sub add_role_application {
191 my ($self, $application) = @_;
192 (blessed($application) && $application->isa('Moose::Meta::Role::Application::ToClass'))
193 || $self->throw_error("Role applications must be instances of Moose::Meta::Role::Application::ToClass", data => $application);
639f9a1a 194 push @{$self->_get_role_applications} => $application;
a9b63d79 195}
196
b8aeb4dc 197sub calculate_all_roles {
198 my $self = shift;
199 my %seen;
200 grep { !$seen{$_->name}++ } map { $_->calculate_all_roles } @{ $self->roles };
201}
202
9f83eb5d 203sub calculate_all_roles_with_inheritance {
204 my $self = shift;
205 my %seen;
206 grep { !$seen{$_->name}++ }
207 map { Class::MOP::class_of($_)->can('calculate_all_roles')
208 ? Class::MOP::class_of($_)->calculate_all_roles
209 : () }
210 $self->linearized_isa;
211}
212
ef333f17 213sub does_role {
214 my ($self, $role_name) = @_;
322abb07 215
ef333f17 216 (defined $role_name)
11c86f15 217 || $self->throw_error("You must supply a role name to look for");
322abb07 218
9c429218 219 foreach my $class ($self->class_precedence_list) {
322abb07 220 my $meta = Class::MOP::class_of($class);
3d0f5a27 221 # when a Moose metaclass is itself extended with a role,
222 # this check needs to be done since some items in the
223 # class_precedence_list might in fact be Class::MOP
224 # based still.
322abb07 225 next unless $meta && $meta->can('roles');
226 foreach my $role (@{$meta->roles}) {
9c429218 227 return 1 if $role->does_role($role_name);
228 }
ef333f17 229 }
230 return 0;
231}
232
d79e62fd 233sub excludes_role {
234 my ($self, $role_name) = @_;
ebfc4d0f 235
d79e62fd 236 (defined $role_name)
11c86f15 237 || $self->throw_error("You must supply a role name to look for");
ebfc4d0f 238
ac2dc464 239 foreach my $class ($self->class_precedence_list) {
ebfc4d0f 240 my $meta = Class::MOP::class_of($class);
241 # when a Moose metaclass is itself extended with a role,
242 # this check needs to be done since some items in the
243 # class_precedence_list might in fact be Class::MOP
244 # based still.
245 next unless $meta && $meta->can('roles');
246 foreach my $role (@{$meta->roles}) {
9c429218 247 return 1 if $role->excludes_role($role_name);
248 }
d79e62fd 249 }
250 return 0;
251}
252
8c9d74e7 253sub new_object {
7d4035ae 254 my $self = shift;
e606ae5f 255 my $params = @_ == 1 ? $_[0] : {@_};
7d4035ae 256 my $object = $self->SUPER::new_object($params);
1308deb4 257
7d4035ae 258 foreach my $attr ( $self->get_all_attributes() ) {
1308deb4 259
260 next unless $attr->can('has_trigger') && $attr->has_trigger;
261
262 my $init_arg = $attr->init_arg;
263
264 next unless defined $init_arg;
265
266 next unless exists $params->{$init_arg};
267
268 $attr->trigger->(
7d4035ae 269 $object,
1308deb4 270 (
271 $attr->should_coerce
7d4035ae 272 ? $attr->get_read_method_ref->($object)
1308deb4 273 : $params->{$init_arg}
274 ),
1308deb4 275 );
8c9d74e7 276 }
1308deb4 277
7d4035ae 278 $object->BUILDALL($params) if $object->can('BUILDALL');
a19ae3d7 279
7d4035ae 280 return $object;
8c9d74e7 281}
282
e2eef3a5 283sub superclasses {
284 my $self = shift;
2e7f6cf4 285 my $supers = Data::OptList::mkopt(\@_);
286 foreach my $super (@{ $supers }) {
287 my ($name, $opts) = @{ $super };
288 Class::MOP::load_class($name, $opts);
289 my $meta = Class::MOP::class_of($name);
290 $self->throw_error("You cannot inherit from a Moose Role ($name)")
e2eef3a5 291 if $meta && $meta->isa('Moose::Meta::Role')
292 }
2e7f6cf4 293 return $self->SUPER::superclasses(map { $_->[0] } @{ $supers });
e2eef3a5 294}
295
093b12c2 296### ---------------------------------------------
297
a2eec5e7 298sub add_attribute {
299 my $self = shift;
28af3424 300 my $attr =
e472c9a5 301 (blessed $_[0] && $_[0]->isa('Class::MOP::Attribute')
d03bd989 302 ? $_[0]
28af3424 303 : $self->_process_attribute(@_));
304 $self->SUPER::add_attribute($attr);
305 # it may be a Class::MOP::Attribute, theoretically, which doesn't have
306 # 'bare' and doesn't implement this method
9340e346 307 if ($attr->can('_check_associated_methods')) {
308 $attr->_check_associated_methods;
28af3424 309 }
310 return $attr;
a2eec5e7 311}
312
78cd1d3b 313sub add_override_method_modifier {
314 my ($self, $name, $method, $_super_package) = @_;
18c2ec0e 315
d05cd563 316 (!$self->has_method($name))
11c86f15 317 || $self->throw_error("Cannot add an override method if a local method is already present");
18c2ec0e 318
74862722 319 $self->add_method($name => Moose::Meta::Method::Overridden->new(
3f9e4b0a 320 method => $method,
321 class => $self,
322 package => $_super_package, # need this for roles
323 name => $name,
18c2ec0e 324 ));
78cd1d3b 325}
326
327sub add_augment_method_modifier {
ac2dc464 328 my ($self, $name, $method) = @_;
d05cd563 329 (!$self->has_method($name))
11c86f15 330 || $self->throw_error("Cannot add an augment method if a local method is already present");
3f9e4b0a 331
332 $self->add_method($name => Moose::Meta::Method::Augmented->new(
333 method => $method,
334 class => $self,
335 name => $name,
336 ));
78cd1d3b 337}
338
1341f10c 339## Private Utility methods ...
340
05d9eaf6 341sub _find_next_method_by_name_which_is_not_overridden {
342 my ($self, $name) = @_;
68efb014 343 foreach my $method ($self->find_all_methods_by_name($name)) {
ac2dc464 344 return $method->{code}
74862722 345 if blessed($method->{code}) && !$method->{code}->isa('Moose::Meta::Method::Overridden');
05d9eaf6 346 }
347 return undef;
348}
349
f6df97ae 350## Metaclass compatibility
f8b6827f 351
f6df97ae 352sub _base_metaclasses {
353 my $self = shift;
354 my %metaclasses = $self->SUPER::_base_metaclasses;
355 for my $class (keys %metaclasses) {
356 $metaclasses{$class} =~ s/^Class::MOP/Moose::Meta/;
1341f10c 357 }
f6df97ae 358 return (
359 %metaclasses,
360 error_class => 'Moose::Error::Default',
f8b6827f 361 );
f8b6827f 362}
363
f6df97ae 364sub _fix_class_metaclass_incompatibility {
365 my $self = shift;
366 my ($super_meta) = @_;
f8b6827f 367
f6df97ae 368 $self->SUPER::_fix_class_metaclass_incompatibility(@_);
f8b6827f 369
88f2e008 370 if ($self->_class_metaclass_can_be_made_compatible($super_meta)) {
590e8894 371 ($self->is_pristine)
372 || confess "Can't fix metaclass incompatibility for "
373 . $self->name
374 . " because it is not pristine.";
a907317a 375 my $super_meta_name = $super_meta->_real_ref_name;
61907a02 376 my $class_meta_subclass_meta_name = Moose::Util::_reconcile_roles_for_metaclass(blessed($self), $super_meta_name);
8450b001 377 my $new_self = $class_meta_subclass_meta_name->reinitialize(
cf7febc7 378 $self->name,
379 );
6a52b083 380
8450b001 381 $self->_replace_self( $new_self, $class_meta_subclass_meta_name );
f8b6827f 382 }
f6df97ae 383}
f8b6827f 384
f6df97ae 385sub _fix_single_metaclass_incompatibility {
386 my $self = shift;
387 my ($metaclass_type, $super_meta) = @_;
f8b6827f 388
f6df97ae 389 $self->SUPER::_fix_single_metaclass_incompatibility(@_);
f8b6827f 390
88f2e008 391 if ($self->_single_metaclass_can_be_made_compatible($super_meta, $metaclass_type)) {
590e8894 392 ($self->is_pristine)
393 || confess "Can't fix metaclass incompatibility for "
394 . $self->name
395 . " because it is not pristine.";
7f6c8567 396 my $super_meta_name = $super_meta->_real_ref_name;
61907a02 397 my $class_specific_meta_subclass_meta_name = Moose::Util::_reconcile_roles_for_metaclass($self->$metaclass_type, $super_meta->$metaclass_type);
cf7febc7 398 my $new_self = $super_meta->reinitialize(
399 $self->name,
8450b001 400 $metaclass_type => $class_specific_meta_subclass_meta_name,
cf7febc7 401 );
6a52b083 402
7f6c8567 403 $self->_replace_self( $new_self, $super_meta_name );
f6df97ae 404 }
f8b6827f 405}
406
6a52b083 407sub _replace_self {
408 my $self = shift;
409 my ( $new_self, $new_class) = @_;
410
411 %$self = %$new_self;
412 bless $self, $new_class;
413
414 # We need to replace the cached metaclass instance or else when it goes
415 # out of scope Class::MOP::Class destroy's the namespace for the
416 # metaclass's class, causing much havoc.
dcc8dc06 417 my $weaken = Class::MOP::metaclass_is_weak( $self->name );
6a52b083 418 Class::MOP::store_metaclass_by_name( $self->name, $self );
dcc8dc06 419 Class::MOP::weaken_metaclass( $self->name ) if $weaken;
6a52b083 420}
421
1341f10c 422sub _process_attribute {
a3738e5b 423 my ( $self, $name, @args ) = @_;
7e59b803 424
425 @args = %{$args[0]} if scalar @args == 1 && ref($args[0]) eq 'HASH';
d9bb6c63 426
f9b5f5f8 427 if (($name || '') =~ /^\+(.*)/) {
7e59b803 428 return $self->_process_inherited_attribute($1, @args);
1341f10c 429 }
430 else {
7e59b803 431 return $self->_process_new_attribute($name, @args);
432 }
433}
434
435sub _process_new_attribute {
436 my ( $self, $name, @args ) = @_;
7e59b803 437
d5c30e52 438 $self->attribute_metaclass->interpolate_class_and_new($name, @args);
1341f10c 439}
440
441sub _process_inherited_attribute {
442 my ($self, $attr_name, %options) = @_;
443 my $inherited_attr = $self->find_attribute_by_name($attr_name);
444 (defined $inherited_attr)
329c5dd4 445 || $self->throw_error("Could not find an attribute by the name of '$attr_name' to inherit from in ${\$self->name}", data => $attr_name);
1341f10c 446 if ($inherited_attr->isa('Moose::Meta::Attribute')) {
d7d8a8c7 447 return $inherited_attr->clone_and_inherit_options(%options);
1341f10c 448 }
449 else {
450 # NOTE:
451 # kind of a kludge to handle Class::MOP::Attributes
d7d8a8c7 452 return $inherited_attr->Moose::Meta::Attribute::clone_and_inherit_options(%options);
ac2dc464 453 }
1341f10c 454}
455
948cd189 456## Immutability
457
458sub _immutable_options {
459 my ( $self, @args ) = @_;
460
461 $self->SUPER::_immutable_options(
462 inline_destructor => 1,
948cd189 463
464 # Moose always does this when an attribute is created
465 inline_accessors => 0,
466
467 @args,
468 );
469}
470
5cf3dbcf 471## -------------------------------------------------
472
bf6fa6b3 473our $error_level;
11c86f15 474
475sub throw_error {
476 my ( $self, @args ) = @_;
bf6fa6b3 477 local $error_level = ($error_level || 0) + 1;
11c86f15 478 $self->raise_error($self->create_error(@args));
479}
480
481sub raise_error {
482 my ( $self, @args ) = @_;
483 die @args;
484}
485
486sub create_error {
487 my ( $self, @args ) = @_;
488
18748ad6 489 require Carp::Heavy;
490
bf6fa6b3 491 local $error_level = ($error_level || 0 ) + 1;
18748ad6 492
11c86f15 493 if ( @args % 2 == 1 ) {
494 unshift @args, "message";
495 }
496
fcab1742 497 my %args = ( metaclass => $self, last_error => $@, @args );
11c86f15 498
bf6fa6b3 499 $args{depth} += $error_level;
11c86f15 500
bf6fa6b3 501 my $class = ref $self ? $self->error_class : "Moose::Error::Default";
11c86f15 502
a810a01f 503 Class::MOP::load_class($class);
504
11c86f15 505 $class->new(
bf6fa6b3 506 Carp::caller_info($args{depth}),
507 %args
11c86f15 508 );
509}
510
c0e30cf5 5111;
512
513__END__
514
515=pod
516
517=head1 NAME
518
e522431d 519Moose::Meta::Class - The Moose metaclass
c0e30cf5 520
c0e30cf5 521=head1 DESCRIPTION
522
70bb0f97 523This class is a subclass of L<Class::MOP::Class> that provides
524additional Moose-specific functionality.
e522431d 525
7854b409 526To really understand this class, you will need to start with the
527L<Class::MOP::Class> documentation. This class can be understood as a
528set of additional features on top of the basic feature provided by
529that parent class.
6ba6d68c 530
d4b1449e 531=head1 INHERITANCE
532
533C<Moose::Meta::Class> is a subclass of L<Class::MOP::Class>.
534
c0e30cf5 535=head1 METHODS
536
537=over 4
538
70bb0f97 539=item B<< Moose::Meta::Class->initialize($package_name, %options) >>
590868a3 540
70bb0f97 541This overrides the parent's method in order to provide its own
542defaults for the C<attribute_metaclass>, C<instance_metaclass>, and
543C<method_metaclass> options.
61bdd94f 544
70bb0f97 545These all default to the appropriate Moose class.
61bdd94f 546
70bb0f97 547=item B<< Moose::Meta::Class->create($package_name, %options) >>
17594769 548
70bb0f97 549This overrides the parent's method in order to accept a C<roles>
9e25a72a 550option. This should be an array reference containing roles
551that the class does, each optionally followed by a hashref of options
552(C<-excludes> and C<-alias>).
17594769 553
70bb0f97 554 my $metaclass = Moose::Meta::Class->create( 'New::Class', roles => [...] );
17594769 555
70bb0f97 556=item B<< Moose::Meta::Class->create_anon_class >>
17594769 557
70bb0f97 558This overrides the parent's method to accept a C<roles> option, just
559as C<create> does.
5cf3dbcf 560
70bb0f97 561It also accepts a C<cache> option. If this is true, then the anonymous
562class will be cached based on its superclasses and roles. If an
563existing anonymous class in the cache has the same superclasses and
564roles, it will be reused.
ac2dc464 565
70bb0f97 566 my $metaclass = Moose::Meta::Class->create_anon_class(
567 superclasses => ['Foo'],
568 roles => [qw/Some Roles Go Here/],
569 cache => 1,
570 );
ac2dc464 571
2e7f6cf4 572Each entry in both the C<superclasses> and the C<roles> option can be
b2d54db8 573followed by a hash reference with arguments. The C<superclasses>
2e7f6cf4 574option can be supplied with a L<-version|Class::MOP/Class Loading
575Options> option that ensures the loaded superclass satisfies the
576required version. The C<role> option also takes the C<-version> as an
577argument, but the option hash reference can also contain any other
578role relevant values like exclusions or parameterized role arguments.
579
70bb0f97 580=item B<< $metaclass->make_immutable(%options) >>
ac2dc464 581
70bb0f97 582This overrides the parent's method to add a few options. Specifically,
583it uses the Moose-specific constructor and destructor classes, and
584enables inlining the destructor.
8c9d74e7 585
dcdceb38 586Since Moose always inlines attributes, it sets the C<inline_accessors> option
587to false.
588
70bb0f97 589=item B<< $metaclass->new_object(%params) >>
a15dff8d 590
70bb0f97 591This overrides the parent's method in order to add support for
592attribute triggers.
6ba6d68c 593
2e7f6cf4 594=item B<< $metaclass->superclasses(@superclasses) >>
595
6b958a3e 596This is the accessor allowing you to read or change the parents of
2e7f6cf4 597the class.
598
599Each superclass can be followed by a hash reference containing a
600L<-version|Class::MOP/Class Loading Options> value. If the version
601requirement is not satisfied an error will be thrown.
602
70bb0f97 603=item B<< $metaclass->add_override_method_modifier($name, $sub) >>
ef1d5f4b 604
70bb0f97 605This adds an C<override> method modifier to the package.
e9ec68d6 606
70bb0f97 607=item B<< $metaclass->add_augment_method_modifier($name, $sub) >>
e9ec68d6 608
70bb0f97 609This adds an C<augment> method modifier to the package.
78cd1d3b 610
70bb0f97 611=item B<< $metaclass->calculate_all_roles >>
02a0fb52 612
70bb0f97 613This will return a unique array of C<Moose::Meta::Role> instances
614which are attached to this class.
78cd1d3b 615
9f83eb5d 616=item B<< $metaclass->calculate_all_roles_with_inheritance >>
617
618This will return a unique array of C<Moose::Meta::Role> instances
619which are attached to this class, and each of this class's ancestors.
620
70bb0f97 621=item B<< $metaclass->add_role($role) >>
02a0fb52 622
70bb0f97 623This takes a L<Moose::Meta::Role> object, and adds it to the class's
624list of roles. This I<does not> actually apply the role to the class.
2b14ac61 625
b90dd4ef 626=item B<< $metaclass->role_applications >>
627
639f9a1a 628Returns a list of L<Moose::Meta::Role::Application::ToClass>
b90dd4ef 629objects, which contain the arguments to role application.
630
631=item B<< $metaclass->add_role_application($application) >>
632
633This takes a L<Moose::Meta::Role::Application::ToClass> object, and
634adds it to the class's list of role applications. This I<does not>
635actually apply any role to the class; it is only for tracking role
636applications.
637
560c498d 638=item B<< $metaclass->does_role($role) >>
ef333f17 639
560c498d 640This returns a boolean indicating whether or not the class does the specified
641role. The role provided can be either a role name or a L<Moose::Meta::Role>
642object. This tests both the class and its parents.
02a0fb52 643
70bb0f97 644=item B<< $metaclass->excludes_role($role_name) >>
ef333f17 645
70bb0f97 646A class excludes a role if it has already composed a role which
647excludes the named role. This tests both the class and its parents.
02a0fb52 648
70bb0f97 649=item B<< $metaclass->add_attribute($attr_name, %params|$params) >>
ef333f17 650
70bb0f97 651This overrides the parent's method in order to allow the parameters to
652be provided as a hash reference.
02a0fb52 653
9f9fdd08 654=item B<< $metaclass->constructor_class($class_name) >>
d79e62fd 655
9f9fdd08 656=item B<< $metaclass->destructor_class($class_name) >>
e606ae5f 657
948cd189 658These are the names of classes used when making a class immutable. These
90a49845 659default to L<Moose::Meta::Method::Constructor> and
660L<Moose::Meta::Method::Destructor> respectively. These accessors are
661read-write, so you can use them to change the class name.
e606ae5f 662
70bb0f97 663=item B<< $metaclass->error_class($class_name) >>
8b1d510f 664
70bb0f97 665The name of the class used to throw errors. This defaults to
8b1d510f 666L<Moose::Error::Default>, which generates an error with a stacktrace
667just like C<Carp::confess>.
668
70bb0f97 669=item B<< $metaclass->throw_error($message, %extra) >>
11c86f15 670
671Throws the error created by C<create_error> using C<raise_error>
672
c0e30cf5 673=back
674
675=head1 BUGS
676
d4048ef3 677See L<Moose/BUGS> for details on reporting bugs.
c0e30cf5 678
c0e30cf5 679=head1 AUTHOR
680
681Stevan Little E<lt>stevan@iinteractive.comE<gt>
682
683=head1 COPYRIGHT AND LICENSE
684
7e0492d3 685Copyright 2006-2010 by Infinity Interactive, Inc.
c0e30cf5 686
687L<http://www.iinteractive.com>
688
689This library is free software; you can redistribute it and/or modify
ac2dc464 690it under the same terms as Perl itself.
c0e30cf5 691
8a7a9c53 692=cut
1a563243 693