Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

48 lines (35 sloc) 1.111 kb
use v6;
use Test;
plan 6;
# L<S12/"Semantics of C<bless>"/"DESTROY and DESTROYALL work the
# same way, only in reverse">
my $in_destructor = 0;
my @destructor_order;
class Foo
{
submethod DESTROY { $in_destructor++ }
}
class Parent
{
submethod DESTROY { push @destructor_order, 'Parent' }
}
class Child is Parent
{
submethod DESTROY { push @destructor_order, 'Child' }
}
my $foo = Foo.new();
isa_ok($foo, Foo, 'basic instantiation of declared class' );
ok( ! $in_destructor, 'destructor should not fire while object is active' );
my $child = Child.new();
undefine $child;
# no guaranteed timely destruction, so replace $a and try to force some GC here
for 1 .. 100
{
$foo = Foo.new();
}
#?pugs 2 skip 'broken after Object -> Mu conversion'
ok( $in_destructor, '... only when object goes away everywhere' );
is( +@destructor_order, 2, '... only as many as available DESTROY submethods' );
is( @destructor_order[0], 'Child', 'Child DESTROY should fire first' );
is( @destructor_order[1], 'Parent', '... then parent' );
# vim: ft=perl6
Jump to Line
Something went wrong with that request. Please try again.