summaryrefslogtreecommitdiffstats
path: root/t/moose-late-load.t
blob: 241f58e00e35a58ce0721c2f2d32552f7e2e2bbf (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
63
64
65
66
67
68
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use lib 't/lib';
use Test::Class::Refresh;

use Class::Refresh track_require => 1;

my $dir;
BEGIN {
    $dir = prepare_temp_dir_for('moose-late-load');
    push @INC, $dir->dirname;

    Class::Refresh->refresh;
}

# have to do this later
use Test::Requires 'Moose';

require Foo;
require Foo::Immutable;

is_deeply([Foo->meta->get_attribute_list], ['foo'],
          "correct starting attr list");
can_ok('Foo', 'meth');
ok(!Foo->can('other_meth'), "!Foo->can('other_meth')");

is_deeply([Foo::Immutable->meta->get_attribute_list], ['foo'],
          "correct starting attr list");
can_ok('Foo::Immutable', 'meth');
ok(!Foo::Immutable->can('other_meth'), "!Foo::Immutable->can('other_meth')");


sleep 2;
update_temp_dir_for('moose-late-load', $dir, 'middle');

Class::Refresh->refresh;

is_deeply([Foo->meta->get_attribute_list], ['bar'],
          "correct refreshed attr list");
can_ok('Foo', 'other_meth');
ok(!Foo->can('meth'), "!Foo->can('meth')");

is_deeply([Foo::Immutable->meta->get_attribute_list], ['bar'],
          "correct refreshed attr list");
can_ok('Foo::Immutable', 'other_meth');
ok(!Foo::Immutable->can('meth'), "!Foo::Immutable->can('meth')");


sleep 2;
update_temp_dir_for('moose-late-load', $dir, 'after');

Class::Refresh->refresh;

is_deeply([Foo->meta->get_attribute_list], ['baz'],
          "correct refreshed attr list");
can_ok('Foo', 'other_other_meth');
ok(!Foo->can('meth'), "!Foo->can('meth')");
ok(!Foo->can('other_meth'), "!Foo->can('other_meth')");

is_deeply([Foo::Immutable->meta->get_attribute_list], ['baz'],
          "correct refreshed attr list");
can_ok('Foo::Immutable', 'other_other_meth');
ok(!Foo::Immutable->can('meth'), "!Foo::Immutable->can('meth')");
ok(!Foo::Immutable->can('other_meth'), "!Foo::Immutable->can('other_meth')");

done_testing;