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