bump version
[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
3543f4d4 15our $VERSION = '1.23';
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
7c7ab486 456# reinitialization support
457
458sub _restore_metaobjects_from {
459 my $self = shift;
460 my ($old_meta) = @_;
461
462 $self->SUPER::_restore_metaobjects_from($old_meta);
463
464 for my $role ( @{ $old_meta->roles } ) {
465 $self->add_role($role);
466 }
467
468 for my $application ( @{ $old_meta->_get_role_applications } ) {
469 $application->class($self);
470 $self->add_role_application ($application);
471 }
472}
473
948cd189 474## Immutability
475
476sub _immutable_options {
477 my ( $self, @args ) = @_;
478
479 $self->SUPER::_immutable_options(
480 inline_destructor => 1,
948cd189 481
482 # Moose always does this when an attribute is created
483 inline_accessors => 0,
484
485 @args,
486 );
487}
488
5cf3dbcf 489## -------------------------------------------------
490
bf6fa6b3 491our $error_level;
11c86f15 492
493sub throw_error {
494 my ( $self, @args ) = @_;
bf6fa6b3 495 local $error_level = ($error_level || 0) + 1;
11c86f15 496 $self->raise_error($self->create_error(@args));
497}
498
499sub raise_error {
500 my ( $self, @args ) = @_;
501 die @args;
502}
503
504sub create_error {
505 my ( $self, @args ) = @_;
506
18748ad6 507 require Carp::Heavy;
508
bf6fa6b3 509 local $error_level = ($error_level || 0 ) + 1;
18748ad6 510
11c86f15 511 if ( @args % 2 == 1 ) {
512 unshift @args, "message";
513 }
514
fcab1742 515 my %args = ( metaclass => $self, last_error => $@, @args );
11c86f15 516
bf6fa6b3 517 $args{depth} += $error_level;
11c86f15 518
bf6fa6b3 519 my $class = ref $self ? $self->error_class : "Moose::Error::Default";
11c86f15 520
a810a01f 521 Class::MOP::load_class($class);
522
11c86f15 523 $class->new(
bf6fa6b3 524 Carp::caller_info($args{depth}),
525 %args
11c86f15 526 );
527}
528
c0e30cf5 5291;
530
531__END__
532
533=pod
534
535=head1 NAME
536
e522431d 537Moose::Meta::Class - The Moose metaclass
c0e30cf5 538
c0e30cf5 539=head1 DESCRIPTION
540
70bb0f97 541This class is a subclass of L<Class::MOP::Class> that provides
542additional Moose-specific functionality.
e522431d 543
7854b409 544To really understand this class, you will need to start with the
545L<Class::MOP::Class> documentation. This class can be understood as a
546set of additional features on top of the basic feature provided by
547that parent class.
6ba6d68c 548
d4b1449e 549=head1 INHERITANCE
550
551C<Moose::Meta::Class> is a subclass of L<Class::MOP::Class>.
552
c0e30cf5 553=head1 METHODS
554
555=over 4
556
70bb0f97 557=item B<< Moose::Meta::Class->initialize($package_name, %options) >>
590868a3 558
70bb0f97 559This overrides the parent's method in order to provide its own
560defaults for the C<attribute_metaclass>, C<instance_metaclass>, and
561C<method_metaclass> options.
61bdd94f 562
70bb0f97 563These all default to the appropriate Moose class.
61bdd94f 564
70bb0f97 565=item B<< Moose::Meta::Class->create($package_name, %options) >>
17594769 566
70bb0f97 567This overrides the parent's method in order to accept a C<roles>
9e25a72a 568option. This should be an array reference containing roles
569that the class does, each optionally followed by a hashref of options
570(C<-excludes> and C<-alias>).
17594769 571
70bb0f97 572 my $metaclass = Moose::Meta::Class->create( 'New::Class', roles => [...] );
17594769 573
70bb0f97 574=item B<< Moose::Meta::Class->create_anon_class >>
17594769 575
70bb0f97 576This overrides the parent's method to accept a C<roles> option, just
577as C<create> does.
5cf3dbcf 578
70bb0f97 579It also accepts a C<cache> option. If this is true, then the anonymous
580class will be cached based on its superclasses and roles. If an
581existing anonymous class in the cache has the same superclasses and
582roles, it will be reused.
ac2dc464 583
70bb0f97 584 my $metaclass = Moose::Meta::Class->create_anon_class(
585 superclasses => ['Foo'],
586 roles => [qw/Some Roles Go Here/],
587 cache => 1,
588 );
ac2dc464 589
2e7f6cf4 590Each entry in both the C<superclasses> and the C<roles> option can be
b2d54db8 591followed by a hash reference with arguments. The C<superclasses>
2e7f6cf4 592option can be supplied with a L<-version|Class::MOP/Class Loading
593Options> option that ensures the loaded superclass satisfies the
594required version. The C<role> option also takes the C<-version> as an
595argument, but the option hash reference can also contain any other
596role relevant values like exclusions or parameterized role arguments.
597
70bb0f97 598=item B<< $metaclass->make_immutable(%options) >>
ac2dc464 599
70bb0f97 600This overrides the parent's method to add a few options. Specifically,
601it uses the Moose-specific constructor and destructor classes, and
602enables inlining the destructor.
8c9d74e7 603
dcdceb38 604Since Moose always inlines attributes, it sets the C<inline_accessors> option
605to false.
606
70bb0f97 607=item B<< $metaclass->new_object(%params) >>
a15dff8d 608
70bb0f97 609This overrides the parent's method in order to add support for
610attribute triggers.
6ba6d68c 611
2e7f6cf4 612=item B<< $metaclass->superclasses(@superclasses) >>
613
6b958a3e 614This is the accessor allowing you to read or change the parents of
2e7f6cf4 615the class.
616
617Each superclass can be followed by a hash reference containing a
618L<-version|Class::MOP/Class Loading Options> value. If the version
619requirement is not satisfied an error will be thrown.
620
70bb0f97 621=item B<< $metaclass->add_override_method_modifier($name, $sub) >>
ef1d5f4b 622
70bb0f97 623This adds an C<override> method modifier to the package.
e9ec68d6 624
70bb0f97 625=item B<< $metaclass->add_augment_method_modifier($name, $sub) >>
e9ec68d6 626
70bb0f97 627This adds an C<augment> method modifier to the package.
78cd1d3b 628
70bb0f97 629=item B<< $metaclass->calculate_all_roles >>
02a0fb52 630
70bb0f97 631This will return a unique array of C<Moose::Meta::Role> instances
632which are attached to this class.
78cd1d3b 633
9f83eb5d 634=item B<< $metaclass->calculate_all_roles_with_inheritance >>
635
636This will return a unique array of C<Moose::Meta::Role> instances
637which are attached to this class, and each of this class's ancestors.
638
70bb0f97 639=item B<< $metaclass->add_role($role) >>
02a0fb52 640
70bb0f97 641This takes a L<Moose::Meta::Role> object, and adds it to the class's
642list of roles. This I<does not> actually apply the role to the class.
2b14ac61 643
b90dd4ef 644=item B<< $metaclass->role_applications >>
645
639f9a1a 646Returns a list of L<Moose::Meta::Role::Application::ToClass>
b90dd4ef 647objects, which contain the arguments to role application.
648
649=item B<< $metaclass->add_role_application($application) >>
650
651This takes a L<Moose::Meta::Role::Application::ToClass> object, and
652adds it to the class's list of role applications. This I<does not>
653actually apply any role to the class; it is only for tracking role
654applications.
655
560c498d 656=item B<< $metaclass->does_role($role) >>
ef333f17 657
560c498d 658This returns a boolean indicating whether or not the class does the specified
659role. The role provided can be either a role name or a L<Moose::Meta::Role>
660object. This tests both the class and its parents.
02a0fb52 661
70bb0f97 662=item B<< $metaclass->excludes_role($role_name) >>
ef333f17 663
70bb0f97 664A class excludes a role if it has already composed a role which
665excludes the named role. This tests both the class and its parents.
02a0fb52 666
70bb0f97 667=item B<< $metaclass->add_attribute($attr_name, %params|$params) >>
ef333f17 668
70bb0f97 669This overrides the parent's method in order to allow the parameters to
670be provided as a hash reference.
02a0fb52 671
9f9fdd08 672=item B<< $metaclass->constructor_class($class_name) >>
d79e62fd 673
9f9fdd08 674=item B<< $metaclass->destructor_class($class_name) >>
e606ae5f 675
948cd189 676These are the names of classes used when making a class immutable. These
90a49845 677default to L<Moose::Meta::Method::Constructor> and
678L<Moose::Meta::Method::Destructor> respectively. These accessors are
679read-write, so you can use them to change the class name.
e606ae5f 680
70bb0f97 681=item B<< $metaclass->error_class($class_name) >>
8b1d510f 682
70bb0f97 683The name of the class used to throw errors. This defaults to
8b1d510f 684L<Moose::Error::Default>, which generates an error with a stacktrace
685just like C<Carp::confess>.
686
70bb0f97 687=item B<< $metaclass->throw_error($message, %extra) >>
11c86f15 688
689Throws the error created by C<create_error> using C<raise_error>
690
c0e30cf5 691=back
692
693=head1 BUGS
694
d4048ef3 695See L<Moose/BUGS> for details on reporting bugs.
c0e30cf5 696
c0e30cf5 697=head1 AUTHOR
698
699Stevan Little E<lt>stevan@iinteractive.comE<gt>
700
701=head1 COPYRIGHT AND LICENSE
702
7e0492d3 703Copyright 2006-2010 by Infinity Interactive, Inc.
c0e30cf5 704
705L<http://www.iinteractive.com>
706
707This library is free software; you can redistribute it and/or modify
ac2dc464 708it under the same terms as Perl itself.
c0e30cf5 709
8a7a9c53 710=cut
1a563243 711