Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic/demolish warnings #167

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/Moose/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ sub DEMOLISHALL {

foreach my $class (@isa) {
no strict 'refs';
my $demolish = *{"${class}::DEMOLISH"}{CODE};
# 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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment explaining why this is necessary would be good.

*{"${class}::DEMOLISH"}{CODE};
};
$self->$demolish($in_global_destruction)
if defined $demolish;
}
Expand Down
15 changes: 15 additions & 0 deletions t/bugs/DEMOLISH_warnings.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use strict;
use warnings;

use lib 't/lib';
use Test::More;
use Test::Requires qw(Test::Warnings);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you add Test::Warnings->import(':no_end_test') here then it will only run one test.

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");

done_testing();
6 changes: 6 additions & 0 deletions t/lib/Demolition/Demolisher.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package Demolition::Demolisher;
use Moose;

sub DEMOLISH { }

1;
8 changes: 8 additions & 0 deletions t/lib/Demolition/OnceRemoved.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package Demolition::OnceRemoved;
use strict;
use warnings;
use Demolition::Demolisher;

my $d = Demolition::Demolisher->new;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this into a block in the .t file? I think that'd make it a bit clearer.


1;