line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mason::t::Reload; |
2
|
|
|
|
|
|
|
$Mason::t::Reload::VERSION = '2.22'; |
3
|
1
|
|
|
1
|
|
1609
|
use Test::Class::Most parent => 'Mason::Test::Class'; |
|
1
|
|
|
|
|
49619
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub test_reload : Tests { |
6
|
|
|
|
|
|
|
my $self = shift; |
7
|
|
|
|
|
|
|
my $class; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$self->add_comp( |
10
|
|
|
|
|
|
|
path => "/reload.mc", |
11
|
|
|
|
|
|
|
src => <<'EOF', |
12
|
|
|
|
|
|
|
<%class> |
13
|
|
|
|
|
|
|
sub foo { 'foo' } |
14
|
|
|
|
|
|
|
sub baz { 'baz1' } |
15
|
|
|
|
|
|
|
</%class> |
16
|
|
|
|
|
|
|
Foo |
17
|
|
|
|
|
|
|
EOF |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
is( $self->interp->run("/reload")->output, "Foo\n", "before reload" ); |
20
|
|
|
|
|
|
|
$class = $self->interp->load("/reload.mc"); |
21
|
|
|
|
|
|
|
is( $class->foo(), 'foo', "method foo" ); |
22
|
|
|
|
|
|
|
is( $class->baz(), 'baz1', "method baz" ); |
23
|
|
|
|
|
|
|
ok( $class->can('foo'), "can call foo before reload" ); |
24
|
|
|
|
|
|
|
ok( !$class->can('bar'), "cannot call bar before reload" ); |
25
|
|
|
|
|
|
|
ok( $class->can('baz'), "can call baz before reload" ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sleep(1); # so timestamp will be different |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$self->add_comp( |
30
|
|
|
|
|
|
|
path => "/reload.mc", |
31
|
|
|
|
|
|
|
src => <<'EOF', |
32
|
|
|
|
|
|
|
<%class> |
33
|
|
|
|
|
|
|
sub bar { 'bar' } |
34
|
|
|
|
|
|
|
sub baz { 'baz2' } |
35
|
|
|
|
|
|
|
</%class> |
36
|
|
|
|
|
|
|
Bar |
37
|
|
|
|
|
|
|
EOF |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
is( $self->interp->run("/reload")->output, "Bar\n", "after reload" ); |
40
|
|
|
|
|
|
|
is( $class->bar(), 'bar', "method bar" ); |
41
|
|
|
|
|
|
|
is( $class->baz(), 'baz2', "method baz" ); |
42
|
|
|
|
|
|
|
ok( $class->can('bar'), "can call bar after reload" ); |
43
|
|
|
|
|
|
|
ok( !$class->can('foo'), "cannot call foo after reload" ); |
44
|
|
|
|
|
|
|
ok( $class->can('baz'), "can call baz after reload" ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub test_reload_parent : Tests { |
48
|
|
|
|
|
|
|
my $self = shift; |
49
|
|
|
|
|
|
|
my $interp = $self->interp; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->add_comp( path => '/foo/bar/baz.mc', src => '<% $.num1 %> <% $.num2 %>' ); |
52
|
|
|
|
|
|
|
$self->add_comp( path => '/foo/Base.mc', src => '<%class>method num1 { 5 }</%class>' ); |
53
|
|
|
|
|
|
|
$self->add_comp( path => '/Base.mc', src => '<%class>method num2 { 6 }</%class>' ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$self->test_existing_comp( path => '/foo/bar/baz.mc', expect => '5 6' ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->interp->_flush_load_cache(); |
58
|
|
|
|
|
|
|
sleep(1); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$self->add_comp( path => '/foo/Base.mc', src => "<%class>method num1 { 7 }</%class>" ); |
61
|
|
|
|
|
|
|
$self->add_comp( path => '/Base.mc', src => "<%class>method num2 { 8 }</%class>" ); |
62
|
|
|
|
|
|
|
$self->test_existing_comp( path => '/foo/bar/baz.mc', expect => '7 8' ); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$self->interp->_flush_load_cache(); |
65
|
|
|
|
|
|
|
sleep(1); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$self->add_comp( |
68
|
|
|
|
|
|
|
path => '/Base.mc', |
69
|
|
|
|
|
|
|
src => "<%class>method num1 { 10 }\nmethod num2 { 11 }\n</%class>" |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
$self->test_existing_comp( path => '/foo/bar/baz.mc', expect => '7 11' ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$self->interp->_flush_load_cache(); |
74
|
|
|
|
|
|
|
sleep(1); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$self->remove_comp( path => '/foo/Base.mc' ); |
77
|
|
|
|
|
|
|
$self->test_existing_comp( path => '/foo/bar/baz.mc', expect => '10 11' ); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$self->interp->_flush_load_cache(); |
80
|
|
|
|
|
|
|
sleep(1); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$self->remove_comp( path => '/foo/Base.mc' ); |
83
|
|
|
|
|
|
|
$self->add_comp( path => '/foo/bar/baz.mc', src => 'hi' ); |
84
|
|
|
|
|
|
|
$self->add_comp( path => '/Base.mp', src => 'method wrap { print "wrap1" }' ); |
85
|
|
|
|
|
|
|
$self->test_existing_comp( path => '/foo/bar/baz.mc', expect => 'wrap1' ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$self->interp->_flush_load_cache(); |
88
|
|
|
|
|
|
|
sleep(1); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$self->add_comp( path => '/Base.mp', src => 'method wrap { print "wrap2" }' ); |
91
|
|
|
|
|
|
|
$self->test_existing_comp( path => '/foo/bar/baz.mc', expect => 'wrap2' ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub test_no_unnecessary_reload : Tests { |
95
|
|
|
|
|
|
|
my $self = shift; |
96
|
|
|
|
|
|
|
my $interp = $self->interp; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$self->add_comp( path => '/foo.mc', src => ' ' ); |
99
|
|
|
|
|
|
|
my $id1 = $interp->load('/foo.mc')->cmeta->id; |
100
|
|
|
|
|
|
|
$self->interp->_flush_load_cache(); |
101
|
|
|
|
|
|
|
my $id2 = $interp->load('/foo.mc')->cmeta->id; |
102
|
|
|
|
|
|
|
ok( $id1 == $id2 ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |