Skip to content

Commit 1036e30

Browse files
committed
Demolish warnings-removal tweaks
Per pull request moose#167, add comments better explaining why these changes are necessary, and use Test::Warnings
1 parent 885f2b3 commit 1036e30

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

lib/Moose/Object.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ sub DEMOLISHALL {
7878

7979
foreach my $class (@isa) {
8080
no strict 'refs';
81+
# If a child module implements DEMOLISH and its parent does not
82+
# then the access below can be the only reference to that parent's sub
8183
my $demolish = do {
8284
no warnings 'once';
8385
*{"${class}::DEMOLISH"}{CODE};

t/bugs/DEMOLISH_warnings.t

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ use strict;
22
use warnings;
33

44
use lib 't/lib';
5-
use Test::More tests => 1;
6-
7-
my @warnings;
8-
BEGIN {
9-
$SIG{__WARN__} = sub { push @warnings, @_ };
10-
}
5+
use Test::More tests => 2; # Test::Warnings re-tests had_no_warnings implicitly
6+
use Test::Requires qw(Test::Warnings);
117

128
use Demolition::OnceRemoved;
13-
14-
is scalar @warnings, 0, "No warnings"
15-
or diag explain \@warnings;
9+
Test::Warnings::had_no_warnings("No DEMOLISH warnings");

t/lib/Demolition/OnceRemoved.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use strict;
33
use warnings;
44
use Demolition::Demolisher;
55

6+
# This variable is only in scope during the initial `use`
7+
# As it leaves scope, Perl will call DESTROY on it
8+
# (and Moose::Object will then go through its DEMOLISHALL method)
69
my $d = Demolition::Demolisher->new;
7-
$d->DEMOLISH;
810

911
1;

0 commit comments

Comments
 (0)