--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+our @demolished;
+package Foo;
+use Moose;
+
+sub DEMOLISH {
+ my $self = shift;
+ push @::demolished, __PACKAGE__;
+}
+
+package Foo::Sub;
+use Moose;
+extends 'Foo';
+
+sub DEMOLISH {
+ my $self = shift;
+ push @::demolished, __PACKAGE__;
+}
+
+package Foo::Sub::Sub;
+use Moose;
+extends 'Foo::Sub';
+
+sub DEMOLISH {
+ my $self = shift;
+ push @::demolished, __PACKAGE__;
+}
+
+package main;
+{
+ my $foo = Foo->new;
+}
+is_deeply(\@demolished, ['Foo'], "Foo demolished properly");
+@demolished = ();
+{
+ my $foo_sub = Foo::Sub->new;
+}
+is_deeply(\@demolished, ['Foo::Sub', 'Foo'], "Foo::Sub demolished properly");
+@demolished = ();
+{
+ my $foo_sub_sub = Foo::Sub::Sub->new;
+}
+is_deeply(\@demolished, ['Foo::Sub::Sub', 'Foo::Sub', 'Foo'],
+ "Foo::Sub::Sub demolished properly");
+@demolished = ();
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+our $expected_igd = 0;
+package Foo;
+use Moose;
+
+sub DEMOLISH {
+ my $self = shift;
+ my ($igd) = @_;
+ ::is($igd, $::expected_igd,
+ "in_global_destruction state is passed to DEMOLISH properly");
+}
+
+package main;
+{
+ my $foo = Foo->new;
+}
+$expected_igd = 1;
+# Test::Builder checks for a valid plan at END time, which is before global
+# destruction, so need to test that in a subprocess
+unless (fork) {
+ our $foo = Foo->new;
+ exit;
+}
+wait;
+# but stuff that happens in a subprocess doesn't update Test::Builder's state
+# in this process, so do that manually here
+my $builder = Test::More->builder;
+$builder->current_test($builder->current_test + 1);