Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / lib / Mouse / PurePerl.pm
CommitLineData
ccb38d0b 1package Mouse::PurePerl;
4bef84ef 2# The pure Perl backend for Mouse
6fffa617 3package Mouse::Util;
df6dd016 4use strict;
5use warnings;
4bef84ef 6use warnings FATAL => 'redefine'; # to avoid to load Mouse::PurePerl twice
df6dd016 7
18cab6b8 8use Scalar::Util ();
df6dd016 9use B ();
10
4bef84ef 11require Mouse::Util;
12
0ffc4183 13# taken from Class/MOP.pm
14sub is_valid_class_name {
15 my $class = shift;
16
17 return 0 if ref($class);
18 return 0 unless defined($class);
19
20 return 1 if $class =~ /\A \w+ (?: :: \w+ )* \z/xms;
21
22 return 0;
23}
24
df6dd016 25sub is_class_loaded {
26 my $class = shift;
27
28 return 0 if ref($class) || !defined($class) || !length($class);
29
30 # walk the symbol table tree to avoid autovififying
3bb9e54e 31 # \*{${main::}{"Foo::"}{"Bar::"}} == \*main::Foo::Bar::
df6dd016 32
33 my $pack = \%::;
34 foreach my $part (split('::', $class)) {
3bb9e54e 35 $part .= '::';
36 return 0 if !exists $pack->{$part};
37
38 my $entry = \$pack->{$part};
df6dd016 39 return 0 if ref($entry) ne 'GLOB';
3bb9e54e 40 $pack = *{$entry}{HASH};
df6dd016 41 }
42
3bb9e54e 43 return 0 if !%{$pack};
44
df6dd016 45 # check for $VERSION or @ISA
46 return 1 if exists $pack->{VERSION}
47 && defined *{$pack->{VERSION}}{SCALAR} && defined ${ $pack->{VERSION} };
48 return 1 if exists $pack->{ISA}
49 && defined *{$pack->{ISA}}{ARRAY} && @{ $pack->{ISA} } != 0;
50
51 # check for any method
52 foreach my $name( keys %{$pack} ) {
53 my $entry = \$pack->{$name};
54 return 1 if ref($entry) ne 'GLOB' || defined *{$entry}{CODE};
55 }
56
57 # fail
58 return 0;
59}
60
61
62# taken from Sub::Identify
63sub get_code_info {
64 my ($coderef) = @_;
65 ref($coderef) or return;
66
67 my $cv = B::svref_2object($coderef);
68 $cv->isa('B::CV') or return;
69
70 my $gv = $cv->GV;
71 $gv->isa('B::GV') or return;
72
73 return ($gv->STASH->NAME, $gv->NAME);
74}
75
76sub get_code_package{
77 my($coderef) = @_;
78
79 my $cv = B::svref_2object($coderef);
80 $cv->isa('B::CV') or return '';
81
82 my $gv = $cv->GV;
83 $gv->isa('B::GV') or return '';
84
85 return $gv->STASH->NAME;
86}
87
7d96ae4d 88sub get_code_ref{
89 my($package, $name) = @_;
90 no strict 'refs';
91 no warnings 'once';
92 use warnings FATAL => 'uninitialized';
93 return *{$package . '::' . $name}{CODE};
94}
95
e3540312 96sub generate_isa_predicate_for {
1d5ecd5f 97 my($for_class, $name) = @_;
98
f48920c1 99 my $predicate = sub{ Scalar::Util::blessed($_[0]) && $_[0]->isa($for_class) };
1d5ecd5f 100
101 if(defined $name){
1194aede 102 Mouse::Util::install_subroutines(scalar caller, $name => $predicate);
1d5ecd5f 103 return;
104 }
105
106 return $predicate;
107}
108
ebe91068 109sub generate_can_predicate_for {
110 my($methods_ref, $name) = @_;
111
112 my @methods = @{$methods_ref};
113
114 my $predicate = sub{
115 my($instance) = @_;
116 if(Scalar::Util::blessed($instance)){
117 foreach my $method(@methods){
118 if(!$instance->can($method)){
119 return 0;
120 }
121 }
122 return 1;
123 }
124 return 0;
125 };
126
127 if(defined $name){
1194aede 128 Mouse::Util::install_subroutines(scalar caller, $name => $predicate);
ebe91068 129 return;
130 }
131
132 return $predicate;
133}
1d5ecd5f 134
6fffa617 135package Mouse::Util::TypeConstraints;
f48920c1 136
f48920c1 137
7d96ae4d 138sub Any { 1 }
139sub Item { 1 }
7d96ae4d 140
18cab6b8 141sub Bool { !$_[0] || $_[0] eq '1' }
7d96ae4d 142sub Undef { !defined($_[0]) }
143sub Defined { defined($_[0]) }
144sub Value { defined($_[0]) && !ref($_[0]) }
1d76ae62 145sub Num { Scalar::Util::looks_like_number($_[0]) }
9848d3e1 146sub Str {
4b58033d 147 # We need to use a copy here to flatten MAGICs, for instance as in
148 # Str( substr($_, 0, 42) ).
9848d3e1 149 my($value) = @_;
150 return defined($value) && ref(\$value) eq 'SCALAR';
151}
4b58033d 152sub Int {
153 # We need to use a copy here to save the original internal SV flags.
154 my($value) = @_;
155 return defined($value) && $value =~ /\A -? [0-9]+ \z/xms;
156}
7d96ae4d 157
158sub Ref { ref($_[0]) }
9848d3e1 159sub ScalarRef {
160 my($value) = @_;
4068a8f6 161 return ref($value) eq 'SCALAR' || ref($value) eq 'REF';
9848d3e1 162}
7d96ae4d 163sub ArrayRef { ref($_[0]) eq 'ARRAY' }
164sub HashRef { ref($_[0]) eq 'HASH' }
165sub CodeRef { ref($_[0]) eq 'CODE' }
166sub RegexpRef { ref($_[0]) eq 'Regexp' }
167sub GlobRef { ref($_[0]) eq 'GLOB' }
168
169sub FileHandle {
1d76ae62 170 my($value) = @_;
171 return Scalar::Util::openhandle($value)
172 || (Scalar::Util::blessed($value) && $value->isa("IO::Handle"))
7d96ae4d 173}
174
1d76ae62 175sub Object { Scalar::Util::blessed($_[0]) && ref($_[0]) ne 'Regexp' }
7d96ae4d 176
177sub ClassName { Mouse::Util::is_class_loaded($_[0]) }
178sub RoleName { (Mouse::Util::class_of($_[0]) || return 0)->isa('Mouse::Meta::Role') }
179
619338ac 180sub _parameterize_ArrayRef_for {
181 my($type_parameter) = @_;
182 my $check = $type_parameter->_compiled_type_constraint;
183
184 return sub {
185 foreach my $value (@{$_}) {
186 return undef unless $check->($value);
187 }
188 return 1;
189 }
190}
191
192sub _parameterize_HashRef_for {
193 my($type_parameter) = @_;
194 my $check = $type_parameter->_compiled_type_constraint;
195
196 return sub {
197 foreach my $value(values %{$_}){
198 return undef unless $check->($value);
199 }
200 return 1;
201 };
202}
203
204# 'Maybe' type accepts 'Any', so it requires parameters
205sub _parameterize_Maybe_for {
206 my($type_parameter) = @_;
207 my $check = $type_parameter->_compiled_type_constraint;
208
209 return sub{
210 return !defined($_) || $check->($_);
211 };
9b923ac8 212}
7d96ae4d 213
6fffa617 214package Mouse::Meta::Module;
43165725 215
926404f2 216sub name { $_[0]->{package} }
217
218sub _method_map { $_[0]->{methods} }
c5f6ad05 219sub _attribute_map{ $_[0]->{attributes} }
43165725 220
2591e962 221sub namespace{
222 my $name = $_[0]->{package};
223 no strict 'refs';
224 return \%{ $name . '::' };
225}
226
3e44140b 227sub add_method {
228 my($self, $name, $code) = @_;
229
230 if(!defined $name){
231 $self->throw_error('You must pass a defined name');
232 }
233 if(!defined $code){
234 $self->throw_error('You must pass a defined code');
235 }
236
237 if(ref($code) ne 'CODE'){
238 $code = \&{$code}; # coerce
239 }
240
241 $self->{methods}->{$name} = $code; # Moose stores meta object here.
242
1194aede 243 Mouse::Util::install_subroutines($self->name,
244 $name => $code,
245 );
3e44140b 246 return;
247}
248
b4dc9315 249my $generate_class_accessor = sub {
250 my($name) = @_;
251 return sub {
252 my $self = shift;
253 if(@_) {
254 return $self->{$name} = shift;
255 }
256
257 foreach my $class($self->linearized_isa) {
258 my $meta = Mouse::Util::get_metaclass_by_name($class)
259 or next;
260
261 if(exists $meta->{$name}) {
262 return $meta->{$name};
263 }
264 }
265 return undef;
266 };
267};
268
269
6fffa617 270package Mouse::Meta::Class;
43165725 271
e088c5fc 272use Mouse::Meta::Method::Constructor;
273use Mouse::Meta::Method::Destructor;
274
e058b279 275sub method_metaclass { $_[0]->{method_metaclass} || 'Mouse::Meta::Method' }
276sub attribute_metaclass { $_[0]->{attribute_metaclass} || 'Mouse::Meta::Attribute' }
277
278sub constructor_class { $_[0]->{constructor_class} || 'Mouse::Meta::Method::Constructor' }
279sub destructor_class { $_[0]->{destructor_class} || 'Mouse::Meta::Method::Destructor' }
4e7e3250 280
43165725 281sub is_anon_class{
282 return exists $_[0]->{anon_serial_id};
283}
284
285sub roles { $_[0]->{roles} }
286
bc76ed1c 287sub linearized_isa { @{ Mouse::Util::get_linear_isa($_[0]->{package}) } }
cccb83de 288
ba153b33 289sub new_object {
b5956f03 290 my $meta = shift;
ba153b33 291 my %args = (@_ == 1 ? %{$_[0]} : @_);
292
b5956f03 293 my $object = bless {}, $meta->name;
ba153b33 294
a3a09e38 295 $meta->_initialize_object($object, \%args, 0);
b5956f03 296 # BUILDALL
297 if( $object->can('BUILD') ) {
298 for my $class (reverse $meta->linearized_isa) {
299 my $build = Mouse::Util::get_code_ref($class, 'BUILD')
300 || next;
301
302 $object->$build(\%args);
303 }
304 }
ba153b33 305 return $object;
306}
307
13b99908 308sub clone_object {
309 my $class = shift;
310 my $object = shift;
311 my $args = $object->Mouse::Object::BUILDARGS(@_);
312
1d76ae62 313 (Scalar::Util::blessed($object) && $object->isa($class->name))
13b99908 314 || $class->throw_error("You must pass an instance of the metaclass (" . $class->name . "), not ($object)");
315
316 my $cloned = bless { %$object }, ref $object;
317 $class->_initialize_object($cloned, $args, 1);
13b99908 318 return $cloned;
319}
320
4e7e3250 321sub _initialize_object{
cb6a9721 322 my($self, $object, $args, $is_cloning) = @_;
74de0f8b 323 # The initializer, which is used everywhere, must be clear
324 # when an attribute is added. See Mouse::Meta::Class::add_attribute.
abbcd124 325 my $initializer = $self->{_mouse_cache}{_initialize_object} ||=
a3a09e38 326 Mouse::Util::load_class($self->constructor_class)
327 ->_generate_initialize_object($self);
a3a09e38 328 goto &{$initializer};
4e7e3250 329}
330
abbcd124 331sub get_all_attributes {
332 my($self) = @_;
333 return @{ $self->{_mouse_cache}{all_attributes}
334 ||= $self->_calculate_all_attributes };
335}
336
80efe911 337sub is_immutable { $_[0]->{is_immutable} }
4e7e3250 338
823419c5 339sub strict_constructor;
340*strict_constructor = $generate_class_accessor->('strict_constructor');
fb4ddd88 341
6f09819f 342sub _invalidate_metaclass_cache {
343 my($self) = @_;
344 delete $self->{_mouse_cache};
345 return;
346}
347
fb4ddd88 348sub _report_unknown_args {
349 my($metaclass, $attrs, $args) = @_;
350
351 my @unknowns;
352 my %init_args;
353 foreach my $attr(@{$attrs}){
354 my $init_arg = $attr->init_arg;
355 if(defined $init_arg){
356 $init_args{$init_arg}++;
357 }
358 }
359
360 while(my $key = each %{$args}){
361 if(!exists $init_args{$key}){
362 push @unknowns, $key;
363 }
364 }
365
366 $metaclass->throw_error( sprintf
367 "Unknown attribute passed to the constructor of %s: %s",
368 $metaclass->name, Mouse::Util::english_list(@unknowns),
369 );
370}
e128626c 371
6fffa617 372package Mouse::Meta::Role;
43165725 373
e058b279 374sub method_metaclass{ $_[0]->{method_metaclass} || 'Mouse::Meta::Role::Method' }
375
43165725 376sub is_anon_role{
377 return exists $_[0]->{anon_serial_id};
378}
379
380sub get_roles { $_[0]->{roles} }
381
cb60d0b5 382sub add_before_method_modifier {
383 my ($self, $method_name, $method) = @_;
384
385 push @{ $self->{before_method_modifiers}{$method_name} ||= [] }, $method;
386 return;
387}
388sub add_around_method_modifier {
389 my ($self, $method_name, $method) = @_;
390
391 push @{ $self->{around_method_modifiers}{$method_name} ||= [] }, $method;
392 return;
393}
394sub add_after_method_modifier {
395 my ($self, $method_name, $method) = @_;
396
397 push @{ $self->{after_method_modifiers}{$method_name} ||= [] }, $method;
398 return;
399}
400
401sub get_before_method_modifiers {
402 my ($self, $method_name) = @_;
403 return @{ $self->{before_method_modifiers}{$method_name} ||= [] }
404}
405sub get_around_method_modifiers {
406 my ($self, $method_name) = @_;
407 return @{ $self->{around_method_modifiers}{$method_name} ||= [] }
408}
409sub get_after_method_modifiers {
410 my ($self, $method_name) = @_;
411 return @{ $self->{after_method_modifiers}{$method_name} ||= [] }
412}
413
b4dc9315 414sub add_metaclass_accessor { # for meta roles (a.k.a. traits)
415 my($meta, $name) = @_;
416 $meta->add_method($name => $generate_class_accessor->($name));
417 return;
418}
419
6fffa617 420package Mouse::Meta::Attribute;
43165725 421
e058b279 422require Mouse::Meta::Method::Accessor;
423
424sub accessor_metaclass{ $_[0]->{accessor_metaclass} || 'Mouse::Meta::Method::Accessor' }
43165725 425
426# readers
427
428sub name { $_[0]->{name} }
429sub associated_class { $_[0]->{associated_class} }
430
431sub accessor { $_[0]->{accessor} }
432sub reader { $_[0]->{reader} }
433sub writer { $_[0]->{writer} }
434sub predicate { $_[0]->{predicate} }
435sub clearer { $_[0]->{clearer} }
436sub handles { $_[0]->{handles} }
437
438sub _is_metadata { $_[0]->{is} }
439sub is_required { $_[0]->{required} }
440sub default { $_[0]->{default} }
441sub is_lazy { $_[0]->{lazy} }
442sub is_lazy_build { $_[0]->{lazy_build} }
443sub is_weak_ref { $_[0]->{weak_ref} }
444sub init_arg { $_[0]->{init_arg} }
445sub type_constraint { $_[0]->{type_constraint} }
446
447sub trigger { $_[0]->{trigger} }
448sub builder { $_[0]->{builder} }
449sub should_auto_deref { $_[0]->{auto_deref} }
450sub should_coerce { $_[0]->{coerce} }
451
d899d3e7 452sub documentation { $_[0]->{documentation} }
beb51b30 453sub insertion_order { $_[0]->{insertion_order} }
d899d3e7 454
43165725 455# predicates
456
457sub has_accessor { exists $_[0]->{accessor} }
458sub has_reader { exists $_[0]->{reader} }
459sub has_writer { exists $_[0]->{writer} }
460sub has_predicate { exists $_[0]->{predicate} }
461sub has_clearer { exists $_[0]->{clearer} }
462sub has_handles { exists $_[0]->{handles} }
463
464sub has_default { exists $_[0]->{default} }
465sub has_type_constraint { exists $_[0]->{type_constraint} }
466sub has_trigger { exists $_[0]->{trigger} }
467sub has_builder { exists $_[0]->{builder} }
468
d899d3e7 469sub has_documentation { exists $_[0]->{documentation} }
470
ba1f50a2 471sub _process_options{
472 my($class, $name, $args) = @_;
473
474 # taken from Class::MOP::Attribute::new
475
476 defined($name)
477 or $class->throw_error('You must provide a name for the attribute');
478
479 if(!exists $args->{init_arg}){
480 $args->{init_arg} = $name;
481 }
482
483 # 'required' requires eigher 'init_arg', 'builder', or 'default'
484 my $can_be_required = defined( $args->{init_arg} );
485
486 if(exists $args->{builder}){
487 # XXX:
488 # Moose refuses a CODE ref builder, but Mouse doesn't for backward compatibility
489 # This feature will be changed in a future. (gfx)
490 $class->throw_error('builder must be a defined scalar value which is a method name')
491 #if ref $args->{builder} || !defined $args->{builder};
492 if !defined $args->{builder};
493
494 $can_be_required++;
495 }
496 elsif(exists $args->{default}){
497 if(ref $args->{default} && ref($args->{default}) ne 'CODE'){
498 $class->throw_error("References are not allowed as default values, you must "
499 . "wrap the default of '$name' in a CODE reference (ex: sub { [] } and not [])");
500 }
501 $can_be_required++;
502 }
503
504 if( $args->{required} && !$can_be_required ) {
505 $class->throw_error("You cannot have a required attribute ($name) without a default, builder, or an init_arg");
506 }
507
508 # taken from Mouse::Meta::Attribute->new and ->_process_args
509
510 if(exists $args->{is}){
511 my $is = $args->{is};
512
513 if($is eq 'ro'){
514 $args->{reader} ||= $name;
515 }
516 elsif($is eq 'rw'){
517 if(exists $args->{writer}){
518 $args->{reader} ||= $name;
519 }
520 else{
521 $args->{accessor} ||= $name;
522 }
523 }
524 elsif($is eq 'bare'){
525 # do nothing, but don't complain (later) about missing methods
526 }
527 else{
528 $is = 'undef' if !defined $is;
529 $class->throw_error("I do not understand this option (is => $is) on attribute ($name)");
530 }
531 }
532
533 my $tc;
534 if(exists $args->{isa}){
d503a4f3 535 $tc = $args->{type_constraint} = Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint($args->{isa});
ba1f50a2 536 }
d503a4f3 537
538 if(exists $args->{does}){
539 if(defined $tc){ # both isa and does supplied
540 my $does_ok = do{
541 local $@;
e972d1c9 542 eval{ "$tc"->does($args->{does}) };
d503a4f3 543 };
544 if(!$does_ok){
545 $class->throw_error("Cannot have both an isa option and a does option because '$tc' does not do '$args->{does}' on attribute ($name)");
546 }
547 }
548 else {
549 $tc = $args->{type_constraint} = Mouse::Util::TypeConstraints::find_or_create_does_type_constraint($args->{does});
550 }
ba1f50a2 551 }
ba1f50a2 552
553 if($args->{coerce}){
554 defined($tc)
555 || $class->throw_error("You cannot have coercion without specifying a type constraint on attribute ($name)");
556
557 $args->{weak_ref}
558 && $class->throw_error("You cannot have a weak reference to a coerced value on attribute ($name)");
559 }
560
561 if ($args->{lazy_build}) {
562 exists($args->{default})
563 && $class->throw_error("You can not use lazy_build and default for the same attribute ($name)");
564
565 $args->{lazy} = 1;
566 $args->{builder} ||= "_build_${name}";
567 if ($name =~ /^_/) {
568 $args->{clearer} ||= "_clear${name}";
569 $args->{predicate} ||= "_has${name}";
570 }
571 else {
572 $args->{clearer} ||= "clear_${name}";
573 $args->{predicate} ||= "has_${name}";
574 }
575 }
576
577 if ($args->{auto_deref}) {
578 defined($tc)
579 || $class->throw_error("You cannot auto-dereference without specifying a type constraint on attribute ($name)");
580
581 ( $tc->is_a_type_of('ArrayRef') || $tc->is_a_type_of('HashRef') )
582 || $class->throw_error("You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)");
583 }
584
585 if (exists $args->{trigger}) {
586 ('CODE' eq ref $args->{trigger})
587 || $class->throw_error("Trigger must be a CODE ref on attribute ($name)");
588 }
589
590 if ($args->{lazy}) {
591 (exists $args->{default} || defined $args->{builder})
2c689df4 592 || $class->throw_error("You cannot have a lazy attribute ($name) without specifying a default value for it");
ba1f50a2 593 }
594
595 return;
596}
597
598
6fffa617 599package Mouse::Meta::TypeConstraint;
43165725 600
6e647cac 601use overload
602 '""' => '_as_string',
b4dc9315 603 '0+' => '_identity',
6e647cac 604 '|' => '_unite',
605
606 fallback => 1;
607
43165725 608sub name { $_[0]->{name} }
609sub parent { $_[0]->{parent} }
610sub message { $_[0]->{message} }
611
f6c81f00 612sub _identity { Scalar::Util::refaddr($_[0]) } # overload 0+
613
72dc2c9d 614sub type_parameter { $_[0]->{type_parameter} }
43165725 615sub _compiled_type_constraint{ $_[0]->{compiled_type_constraint} }
df6dd016 616
72dc2c9d 617sub __is_parameterized { exists $_[0]->{type_parameter} }
618sub has_coercion { exists $_[0]->{_compiled_type_coercion} }
df6dd016 619
f790c46b 620
621sub compile_type_constraint{
622 my($self) = @_;
623
624 # add parents first
625 my @checks;
626 for(my $parent = $self->{parent}; defined $parent; $parent = $parent->{parent}){
627 if($parent->{hand_optimized_type_constraint}){
628 unshift @checks, $parent->{hand_optimized_type_constraint};
629 last; # a hand optimized constraint must include all the parents
630 }
631 elsif($parent->{constraint}){
632 unshift @checks, $parent->{constraint};
633 }
634 }
635
636 # then add child
637 if($self->{constraint}){
638 push @checks, $self->{constraint};
639 }
640
641 if($self->{type_constraints}){ # Union
642 my @types = map{ $_->{compiled_type_constraint} } @{ $self->{type_constraints} };
643 push @checks, sub{
644 foreach my $c(@types){
645 return 1 if $c->($_[0]);
646 }
647 return 0;
648 };
649 }
650
651 if(@checks == 0){
652 $self->{compiled_type_constraint} = \&Mouse::Util::TypeConstraints::Any;
653 }
654 else{
655 $self->{compiled_type_constraint} = sub{
656 my(@args) = @_;
657 local $_ = $args[0];
658 foreach my $c(@checks){
659 return undef if !$c->(@args);
660 }
661 return 1;
662 };
663 }
664 return;
665}
666
c7576321 667sub check {
668 my $self = shift;
669 return $self->_compiled_type_constraint->(@_);
670}
671
672
6fffa617 673package Mouse::Object;
aa2d2e2c 674
aa2d2e2c 675sub BUILDARGS {
676 my $class = shift;
f790c46b 677
aa2d2e2c 678 if (scalar @_ == 1) {
679 (ref($_[0]) eq 'HASH')
680 || $class->meta->throw_error("Single parameters to new() must be a HASH ref");
681
682 return {%{$_[0]}};
683 }
684 else {
685 return {@_};
686 }
687}
f790c46b 688
af04626d 689sub new {
690 my $class = shift;
c83feefa 691 my $args = $class->BUILDARGS(@_);
692 return $class->meta->new_object($args);
af04626d 693}
694
a5c683f6 695sub DESTROY {
696 my $self = shift;
697
698 return unless $self->can('DEMOLISH'); # short circuit
699
a5c683f6 700 my $e = do{
a3a09e38 701 local $?;
a5c683f6 702 local $@;
703 eval{
a5c683f6 704 # DEMOLISHALL
705
706 # We cannot count on being able to retrieve a previously made
707 # metaclass, _or_ being able to make a new one during global
708 # destruction. However, we should still be able to use mro at
709 # that time (at least tests suggest so ;)
710
711 foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) {
712 my $demolish = Mouse::Util::get_code_ref($class, 'DEMOLISH')
713 || next;
714
6514735e 715 $self->$demolish($Mouse::Util::in_global_destruction);
a5c683f6 716 }
717 };
718 $@;
719 };
720
721 no warnings 'misc';
722 die $e if $e; # rethrow
723}
724
adb5eb76 725sub BUILDALL {
726 my $self = shift;
727
728 # short circuit
729 return unless $self->can('BUILD');
730
731 for my $class (reverse $self->meta->linearized_isa) {
732 my $build = Mouse::Util::get_code_ref($class, 'BUILD')
733 || next;
734
735 $self->$build(@_);
736 }
737 return;
738}
739
740sub DEMOLISHALL;
741*DEMOLISHALL = \&DESTROY;
742
df6dd016 7431;
744__END__
ccb38d0b 745
746=head1 NAME
747
748Mouse::PurePerl - A Mouse guts in pure Perl
749
750=head1 VERSION
751
14cf9b5a 752This document describes Mouse version 0.95
ccb38d0b 753
754=head1 SEE ALSO
755
756L<Mouse::XS>
757
758=cut