Perltidy this code a bit.
[gitmo/Moose.git] / t / 100_bugs / 012_DEMOLISH_eats_mini.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5;
7 use Test::Exception;
8
9 BEGIN {
10      use_ok('Moose');
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 ) = @_;
26         # ... Moose (kinda) eats exceptions in DESTROY/DEMOLISH";    
27     }
28 }
29
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 }
51
52 1;
53