Perltidy this code a bit.
[gitmo/Moose.git] / t / 100_bugs / 012_DEMOLISH_eats_mini.t
CommitLineData
3a0c064a 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
ca0e380d 6use Test::More tests => 5;
3a0c064a 7use Test::Exception;
8
9BEGIN {
10 use_ok('Moose');
3a0c064a 11}
12
13{
14 package Foo;
15 use Moose;
16
17 has 'bar' => (
18 is => 'ro',
19 required => 1,
20 );
21
22 # Defining this causes the FIRST call to Baz->new w/o param to fail,
23 # if no call to ANY Moose::Object->new was done before.
24 sub DEMOLISH {
25 my ( $self ) = @_;
ca0e380d 26 # ... Moose (kinda) eats exceptions in DESTROY/DEMOLISH";
3a0c064a 27 }
28}
29
ca0e380d 30{
31 my $obj = eval { Foo->new; };
32 ::like( $@, qr/is required/, "... Foo plain" );
33 ::is( $obj, undef, "... the object is undef" );
34}
35
36{
37 package Bar;
38
39 sub new { die "Bar died"; }
40
41 sub DESTROY {
42 die "Vanilla Perl eats exceptions in DESTROY too";
43 }
44}
45
46{
47 my $obj = eval { Bar->new; };
48 ::like( $@, qr/Bar died/, "... Bar plain" );
49 ::is( $obj, undef, "... the object is undef" );
50}
3a0c064a 51
521;
53