use strict;
use warnings;
-use Test::More tests => 7;
+use Test::More;
use Test::Exception;
use Moose;
sub DEMOLISH {
- $@ = 1;
$? = 0;
- $! = 0;
}
}
{
+ local $@ = 42;
+ local $? = 84;
+
+ {
+ Baz->new;
+ }
+
+ is( $@, 42, '$@ is still 42 after object is demolished without dying' );
+ is( $?, 84, '$? is still 84 after object is demolished without dying' );
+
local $@ = 0;
- local $? = 42;
- local $! = 84;
{
Baz->new;
}
- is( $@, 0, '$@ is still 0 after object is demolished' );
- is( $?, 42, '$? is still 42 after object is demolished' );
- is( $! + 0, 84, '$! is still 84 after object is demolished' );
+ is( $@, 0, '$@ is still 0 after object is demolished without dying' );
+
+ Baz->meta->make_immutable, redo
+ if Baz->meta->is_mutable
+}
+
+{
+ package Quux;
+ use Moose;
+
+ sub DEMOLISH {
+ die "foo\n";
+ }
+}
+
+{
+ local $@ = 42;
+
+ eval { my $obj = Quux->new };
+
+ like( $@, qr/foo/, '$@ contains error from demolish when demolish dies' );
+
+ Quux->meta->make_immutable, redo
+ if Quux->meta->is_mutable
}
+done_testing;