blob: 24b72b7552ca6b8f1fd8db321453cfc1b0acefb4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Class::MOP;
{
package My::Meta;
use strict;
use warnings;
use parent 'Class::MOP::Class';
sub initialize {
shift->SUPER::initialize(
@_,
immutable_trait => 'My::Meta::Class::Immutable::Trait',
);
}
}
{
package My::Meta::Class::Immutable::Trait;
use MRO::Compat;
use parent 'Class::MOP::Class::Immutable::Trait';
sub another_method { 42 }
sub superclasses {
my $orig = shift;
my $self = shift;
$self->$orig(@_);
}
}
{
package Foo;
use strict;
use warnings;
use metaclass;
__PACKAGE__->meta->add_attribute('foo');
__PACKAGE__->meta->make_immutable;
}
{
package Bar;
use strict;
use warnings;
use metaclass 'My::Meta';
use parent -norequire => 'Foo';
__PACKAGE__->meta->add_attribute('bar');
::is( ::exception { __PACKAGE__->meta->make_immutable }, undef, 'can safely make a class immutable when it has a custom metaclass and immutable trait' );
}
{
can_ok( Bar->meta, 'another_method' );
is( Bar->meta->another_method, 42, 'another_method returns expected value' );
is_deeply(
[ Bar->meta->superclasses ], ['Foo'],
'Bar->meta->superclasses returns expected value after immutabilization'
);
}
done_testing;
|