line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mason::Plugin::Cache::t::Basic; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
417
|
$Mason::Plugin::Cache::t::Basic::VERSION = '0.05'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
474
|
use Test::Class::Most parent => 'Mason::Test::Class'; |
|
1
|
|
|
|
|
28524
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->default_plugins( [ '@Default', 'Cache' ] ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub test_cache_defaults : Tests { |
10
|
|
|
|
|
|
|
my $self = shift; |
11
|
|
|
|
|
|
|
$self->run_test_in_comp( |
12
|
|
|
|
|
|
|
path => '/cache/defaults.mc', |
13
|
|
|
|
|
|
|
test => sub { |
14
|
|
|
|
|
|
|
my $comp = shift; |
15
|
|
|
|
|
|
|
foreach my $cache ( $comp->cache, $comp->m->cache ) { |
16
|
|
|
|
|
|
|
is( $cache->label, 'File', 'cache->label' ); |
17
|
|
|
|
|
|
|
is( $cache->namespace, $comp->cmeta->path, 'cache->namespace' ); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub test_cache_method : Tests { |
24
|
|
|
|
|
|
|
my $self = shift; |
25
|
|
|
|
|
|
|
$self->test_comp( |
26
|
|
|
|
|
|
|
path => '/cache.mc', |
27
|
|
|
|
|
|
|
src => ' |
28
|
|
|
|
|
|
|
<%shared> |
29
|
|
|
|
|
|
|
$.count => 0 |
30
|
|
|
|
|
|
|
</%shared> |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
<%method getset ($key)> |
33
|
|
|
|
|
|
|
<%perl>$.count($.count+1);</%perl> |
34
|
|
|
|
|
|
|
<% $.cache->compute($key, sub { $key . $.count }) %> |
35
|
|
|
|
|
|
|
</%method> |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
namespace: <% $m->cache->namespace %> |
38
|
|
|
|
|
|
|
<% $.getset("foo") %> |
39
|
|
|
|
|
|
|
<% $.getset("bar") %> |
40
|
|
|
|
|
|
|
<% $.getset("bar") %> |
41
|
|
|
|
|
|
|
<% $.getset("foo") %> |
42
|
|
|
|
|
|
|
', |
43
|
|
|
|
|
|
|
expect => ' |
44
|
|
|
|
|
|
|
namespace: /cache.mc |
45
|
|
|
|
|
|
|
foo1 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
bar2 |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
bar2 |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
foo1 |
52
|
|
|
|
|
|
|
', |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub test_cache_filter : Tests { |
57
|
|
|
|
|
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->test_comp( |
60
|
|
|
|
|
|
|
src => ' |
61
|
|
|
|
|
|
|
% my $i = 1; |
62
|
|
|
|
|
|
|
% foreach my $key (qw(foo bar)) { |
63
|
|
|
|
|
|
|
% $.Repeat(3), $.Cache($key) {{ |
64
|
|
|
|
|
|
|
i = <% $i++ %> |
65
|
|
|
|
|
|
|
% }} |
66
|
|
|
|
|
|
|
% } |
67
|
|
|
|
|
|
|
', |
68
|
|
|
|
|
|
|
expect => ' |
69
|
|
|
|
|
|
|
i = 1 |
70
|
|
|
|
|
|
|
i = 1 |
71
|
|
|
|
|
|
|
i = 1 |
72
|
|
|
|
|
|
|
i = 2 |
73
|
|
|
|
|
|
|
i = 2 |
74
|
|
|
|
|
|
|
i = 2 |
75
|
|
|
|
|
|
|
', |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$self->test_comp( |
79
|
|
|
|
|
|
|
src => ' |
80
|
|
|
|
|
|
|
% my $i = 1; |
81
|
|
|
|
|
|
|
% foreach my $key (qw(foo foo)) { |
82
|
|
|
|
|
|
|
% $.Cache($key), $.Repeat(3) {{ |
83
|
|
|
|
|
|
|
i = <% $i++ %> |
84
|
|
|
|
|
|
|
% }} |
85
|
|
|
|
|
|
|
% } |
86
|
|
|
|
|
|
|
', |
87
|
|
|
|
|
|
|
expect => ' |
88
|
|
|
|
|
|
|
i = 1 |
89
|
|
|
|
|
|
|
i = 2 |
90
|
|
|
|
|
|
|
i = 3 |
91
|
|
|
|
|
|
|
i = 1 |
92
|
|
|
|
|
|
|
i = 2 |
93
|
|
|
|
|
|
|
i = 3 |
94
|
|
|
|
|
|
|
' |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub test_cache_with_defer : Tests { |
99
|
|
|
|
|
|
|
return "not yet implemented"; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $self = shift; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $path = '/cache/defer.mc'; |
104
|
|
|
|
|
|
|
$self->add_comp( |
105
|
|
|
|
|
|
|
path => $path, |
106
|
|
|
|
|
|
|
src => ' |
107
|
|
|
|
|
|
|
% $.Cache("all") {{ |
108
|
|
|
|
|
|
|
foo = <% $m->defer(sub { $Foo::foo }) %> |
109
|
|
|
|
|
|
|
% $Foo::foo++; |
110
|
|
|
|
|
|
|
% }} |
111
|
|
|
|
|
|
|
' |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
$Foo::foo = 5; |
114
|
|
|
|
|
|
|
$self->test_existing_comp( path => $path, expect => 'foo = 6' ); |
115
|
|
|
|
|
|
|
$Foo::foo = 10; |
116
|
|
|
|
|
|
|
$self->test_existing_comp( path => $path, expect => 'foo = 6' ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub test_cache_memoization : Tests { |
120
|
|
|
|
|
|
|
my $self = shift; |
121
|
|
|
|
|
|
|
$self->run_test_in_comp( |
122
|
|
|
|
|
|
|
path => '/cache/memoize.mc', |
123
|
|
|
|
|
|
|
test => sub { |
124
|
|
|
|
|
|
|
my $comp = shift; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
is( $comp->cache_memoized, undef, 'Cache not memoized by default' ); |
127
|
|
|
|
|
|
|
$comp->cache_memoized('buu!'); |
128
|
|
|
|
|
|
|
is( $comp->cache_memoized, 'buu!', 'Memoization updated' ); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$self->run_test_in_comp( |
133
|
|
|
|
|
|
|
path => '/cache/memoize.mc', |
134
|
|
|
|
|
|
|
test => sub { |
135
|
|
|
|
|
|
|
my $comp = shift; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
is( $comp->cache_memoized, 'buu!', 'Cache memoization works across requests' ); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
} |