Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 100_bugs / 012_DEMOLISH_eats_mini.t
CommitLineData
4c98ebb0 1#!/usr/bin/perl
ee5e6a03 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
4c98ebb0 5
6use strict;
7use warnings;
8
07e8d647 9use Test::More;
4c98ebb0 10use Test::Exception;
11
12
13{
14 package Foo;
15 use Mouse;
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 Mouse::Object->new was done before.
24 sub DEMOLISH {
25 my ( $self ) = @_;
26 # ... Mouse (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{
53 package Baz;
54 use Mouse;
55
56 sub DEMOLISH {
57 $? = 0;
58 }
59}
60
61{
62 local $@ = 42;
63 local $? = 84;
64
65 {
66 Baz->new;
67 }
68
69 is( $@, 42, '$@ is still 42 after object is demolished without dying' );
70 is( $?, 84, '$? is still 84 after object is demolished without dying' );
71
72 local $@ = 0;
73
74 {
75 Baz->new;
76 }
77
78 is( $@, 0, '$@ is still 0 after object is demolished without dying' );
79
80 Baz->meta->make_immutable, redo
81 if Baz->meta->is_mutable
82}
83
d6ae4e2b 84done_testing;