Skip to content

Instantly share code, notes, and snippets.

@preaction
Created January 2, 2010 18:39
Show Gist options
  • Save preaction/267600 to your computer and use it in GitHub Desktop.
Save preaction/267600 to your computer and use it in GitHub Desktop.
package t::Destroy;
use Moose;
use Test::Sweet;
use Try::Tiny;
test something {
my $do;
try {
# Works, because DESTROY doesn't run
#$do = t::DestroyObject->new;
# Doesn't work, because DESTROY causes $@ to get clobbered
my $do = t::DestroyObject->new;
$do->dies;
}
catch {
is( $_, "This is the message I want\n" );
}
}
package t::DestroyObject;
use Moose;
sub dies {
die "This is the message I want\n";
}
sub DESTROY {
# Under no circumstances can we allow this to run!
eval { die "This is NOT the message I want\n" };
}
use strict;
use warnings;
use t::Destroy;
exit t::Destroy->new->run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment