blob: c7b2e444f68a3573b06e2870c5268e9ea47ee202 (
plain) (
blame)
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
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 7;
our $foo_constructed = 0;
package Foo;
sub new {
my $class = shift;
bless {}, $class;
}
package Foo::Moose;
use Moose;
use MooseX::NonMoose;
extends 'Foo';
after new => sub {
$main::foo_constructed = 1;
};
package Foo::Moose2;
use Moose;
use MooseX::NonMoose;
extends 'Foo';
sub new {
my $class = shift;
$main::foo_constructed = 1;
return $class->meta->new_object(@_);
}
package main;
my $method = Foo::Moose->meta->get_method('new');
isa_ok($method, 'Class::MOP::Method::Wrapped');
my $foo = Foo::Moose->new;
ok($foo_constructed, 'method modifier called for the constructor');
$foo_constructed = 0;
{
# we don't care about the warning that moose isn't going to inline our
# constructor - this is the behavior we're testing
local $SIG{__WARN__} = sub {};
Foo::Moose->meta->make_immutable;
}
is($method, Foo::Moose->meta->get_method('new'),
'make_immutable doesn\'t overwrite constructor with method modifiers');
$foo = Foo::Moose->new;
ok($foo_constructed, 'method modifier called for the constructor (immutable)');
$foo_constructed = 0;
$method = Foo::Moose2->meta->get_method('new');
$foo = Foo::Moose2->new;
ok($foo_constructed, 'custom constructor called');
$foo_constructed = 0;
# still need to specify inline_constructor => 0 when overriding new manually
Foo::Moose2->meta->make_immutable(inline_constructor => 0);
is($method, Foo::Moose2->meta->get_method('new'),
'make_immutable doesn\'t overwrite custom constructor');
$foo = Foo::Moose2->new;
ok($foo_constructed, 'custom constructor called (immutable)');
|