Skip to content

Commit

Permalink
Demolish warnings-removal tweaks
Browse files Browse the repository at this point in the history
Per pull request #167, add comments better explaining why these changes
are necessary, and use Test::Warnings
  • Loading branch information
jrubinator committed Jul 10, 2018
1 parent 885f2b3 commit 1f0ebe4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/Moose/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
12 changes: 3 additions & 9 deletions t/bugs/DEMOLISH_warnings.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ use strict;
use warnings;

use lib 't/lib';
use Test::More tests => 1;

my @warnings;
BEGIN {
$SIG{__WARN__} = sub { push @warnings, @_ };
}
use Test::More tests => 2; # Test::Warnings re-tests had_no_warnings implicitly
use Test::Requires qw(Test::Warnings);

use Demolition::OnceRemoved;

is scalar @warnings, 0, "No warnings"
or diag explain \@warnings;
Test::Warnings::had_no_warnings("No DEMOLISH warnings");
4 changes: 3 additions & 1 deletion t/lib/Demolition/OnceRemoved.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use strict;
use warnings;
use Demolition::Demolisher;

# This variable is 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)
my $d = Demolition::Demolisher->new;
$d->DEMOLISH;

1;

0 comments on commit 1f0ebe4

Please sign in to comment.