From d17ebd86834966eed56ebaf2775d240c76764842 Mon Sep 17 00:00:00 2001 From: Jonathan Rubin Date: Wed, 27 Jun 2018 10:28:36 -0400 Subject: [PATCH] Demolish warnings-removal tweaks Per pull request #167, add comments better explaining why these changes are necessary, and use Test::Warnings --- lib/Moose/Object.pm | 2 ++ t/bugs/DEMOLISH_warnings.t | 16 ++++++++-------- t/lib/Demolition/OnceRemoved.pm | 1 - 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 3e6c4fa47..69c471bf4 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -78,6 +78,8 @@ sub DEMOLISHALL { foreach my $class (@isa) { no strict 'refs'; + # If a child module implements DEMOLISH and its parent does not + # then the access below can be the only reference to that parent's sub my $demolish = do { no warnings 'once'; *{"${class}::DEMOLISH"}{CODE}; diff --git a/t/bugs/DEMOLISH_warnings.t b/t/bugs/DEMOLISH_warnings.t index 0db745374..bcb63cdf8 100644 --- a/t/bugs/DEMOLISH_warnings.t +++ b/t/bugs/DEMOLISH_warnings.t @@ -2,14 +2,14 @@ use strict; use warnings; use lib 't/lib'; -use Test::More tests => 1; - -my @warnings; -BEGIN { - $SIG{__WARN__} = sub { push @warnings, @_ }; -} +use Test::More; +use Test::Requires qw(Test::Warnings); +Test::Warnings->import(':no_end_test'); +# Demolition::OnceRemoved has a variable only in scope during the initial `use` +# As it leaves scope, Perl will call DESTROY on it +# (and Moose::Object will then go through its DEMOLISHALL method) use Demolition::OnceRemoved; +Test::Warnings::had_no_warnings("No DEMOLISH warnings"); -is scalar @warnings, 0, "No warnings" - or diag explain \@warnings; +done_testing(); diff --git a/t/lib/Demolition/OnceRemoved.pm b/t/lib/Demolition/OnceRemoved.pm index 217f95af5..8b52d126b 100644 --- a/t/lib/Demolition/OnceRemoved.pm +++ b/t/lib/Demolition/OnceRemoved.pm @@ -4,6 +4,5 @@ use warnings; use Demolition::Demolisher; my $d = Demolition::Demolisher->new; -$d->DEMOLISH; 1;