line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mason::t::Request; |
2
|
|
|
|
|
|
|
$Mason::t::Request::VERSION = '2.24'; |
3
|
1
|
|
|
1
|
|
902
|
use Test::Class::Most parent => 'Mason::Test::Class'; |
|
1
|
|
|
|
|
28112
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
527
|
use Log::Any::Test; |
|
1
|
|
|
|
|
3277
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
5
|
use Log::Any qw($log); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub _get_current_comp_class { |
8
|
1
|
|
|
1
|
|
2
|
my $m = shift; |
9
|
1
|
|
|
|
|
6
|
return $m->current_comp_class; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub test_add_cleanup : Tests { |
13
|
1
|
|
|
1
|
0
|
1511
|
my $self = shift; |
14
|
1
|
|
|
|
|
2
|
my $foo = 1; |
15
|
1
|
|
|
|
|
11
|
$self->test_comp( |
16
|
|
|
|
|
|
|
src => ' |
17
|
|
|
|
|
|
|
% my $ref = $.args->{ref}; |
18
|
|
|
|
|
|
|
% $m->add_cleanup(sub { $$ref++ }); |
19
|
|
|
|
|
|
|
foo = <% $$ref %> |
20
|
|
|
|
|
|
|
', |
21
|
|
|
|
|
|
|
args => { ref => \$foo }, |
22
|
|
|
|
|
|
|
expect => 'foo = 1' |
23
|
|
|
|
|
|
|
); |
24
|
1
|
|
|
|
|
7
|
is( $foo, 2, "foo now 2" ); |
25
|
1
|
|
|
1
|
|
144
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub test_capture : Tests { |
28
|
1
|
|
|
1
|
0
|
815
|
my $self = shift; |
29
|
|
|
|
|
|
|
$self->run_test_in_comp( |
30
|
|
|
|
|
|
|
test => sub { |
31
|
1
|
|
|
1
|
|
3
|
my $comp = shift; |
32
|
1
|
|
|
|
|
43
|
my $m = $comp->m; |
33
|
1
|
|
|
|
|
17
|
is( $m->capture( sub { print "abcde" } ), 'abcde' ); |
|
1
|
|
|
|
|
6
|
|
34
|
|
|
|
|
|
|
} |
35
|
1
|
|
|
|
|
16
|
); |
36
|
1
|
|
|
1
|
|
309
|
} |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub test_comp_exists : Tests { |
39
|
1
|
|
|
1
|
0
|
152
|
my $self = shift; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
9
|
$self->add_comp( path => '/comp_exists/one.mc', src => 'hi' ); |
42
|
1
|
|
|
|
|
11
|
$self->test_comp( |
43
|
|
|
|
|
|
|
path => '/comp_exists/two.mc', |
44
|
|
|
|
|
|
|
src => ' |
45
|
|
|
|
|
|
|
% foreach my $path (qw(/comp_exists/one.mc /comp_exists/two.mc /comp_exists/three.mc one.mc two.mc three.mc)) { |
46
|
|
|
|
|
|
|
<% $path %>: <% $m->comp_exists($path) ? "yes" : "no" %> |
47
|
|
|
|
|
|
|
% } |
48
|
|
|
|
|
|
|
', |
49
|
|
|
|
|
|
|
expect => ' |
50
|
|
|
|
|
|
|
/comp_exists/one.mc: yes |
51
|
|
|
|
|
|
|
/comp_exists/two.mc: yes |
52
|
|
|
|
|
|
|
/comp_exists/three.mc: no |
53
|
|
|
|
|
|
|
one.mc: yes |
54
|
|
|
|
|
|
|
two.mc: yes |
55
|
|
|
|
|
|
|
three.mc: no |
56
|
|
|
|
|
|
|
', |
57
|
|
|
|
|
|
|
); |
58
|
1
|
|
|
1
|
|
234
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub test_current_comp_class : Tests { |
61
|
|
|
|
|
|
|
shift->test_comp( |
62
|
1
|
|
|
1
|
0
|
226
|
path => '/current_comp_class.mc', |
63
|
|
|
|
|
|
|
src => '<% ' . __PACKAGE__ . '::_get_current_comp_class($m)->cmeta->path %>', |
64
|
|
|
|
|
|
|
expect => '/current_comp_class.mc' |
65
|
|
|
|
|
|
|
); |
66
|
1
|
|
|
1
|
|
241
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub test_id : Tests { |
69
|
1
|
|
|
1
|
0
|
224
|
my $self = shift; |
70
|
1
|
|
|
|
|
8
|
$self->setup_dirs; |
71
|
1
|
|
|
|
|
27
|
$self->add_comp( path => '/id.mc', src => 'id=<% $m->id %>' ); |
72
|
1
|
|
|
|
|
8
|
my ($id1) = ( $self->interp->run('/id')->output =~ /id=(\d+)/ ); |
73
|
1
|
|
|
|
|
33
|
my ($id2) = ( $self->interp->run('/id')->output =~ /id=(\d+)/ ); |
74
|
1
|
|
|
|
|
30
|
ok( $id1 != $id2 ); |
75
|
1
|
|
|
1
|
|
349
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub test_log : Tests { |
78
|
1
|
|
|
1
|
0
|
812
|
my $self = shift; |
79
|
1
|
|
|
|
|
8
|
$self->add_comp( path => '/log/one.mc', src => '% $m->log->info("message one")' ); |
80
|
|
|
|
|
|
|
$self->run_test_in_comp( |
81
|
|
|
|
|
|
|
path => '/log.mc', |
82
|
|
|
|
|
|
|
test => sub { |
83
|
1
|
|
|
1
|
|
2
|
my $comp = shift; |
84
|
1
|
|
|
|
|
23
|
my $m = $comp->m; |
85
|
1
|
|
|
|
|
1642
|
$m->comp('/log/one.mc'); |
86
|
1
|
|
|
|
|
25
|
$log->contains_ok("message one"); |
87
|
|
|
|
|
|
|
}, |
88
|
1
|
|
|
|
|
12
|
); |
89
|
1
|
|
|
1
|
|
255
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub test_notes : Tests { |
92
|
1
|
|
|
1
|
0
|
105
|
my $self = shift; |
93
|
1
|
|
|
|
|
9
|
$self->add_comp( |
94
|
|
|
|
|
|
|
path => '/show', |
95
|
|
|
|
|
|
|
src => ' |
96
|
|
|
|
|
|
|
<% $m->notes("foo") %> |
97
|
|
|
|
|
|
|
% $m->notes("foo", 3); |
98
|
|
|
|
|
|
|
', |
99
|
|
|
|
|
|
|
); |
100
|
1
|
|
|
|
|
8
|
$self->test_comp( |
101
|
|
|
|
|
|
|
src => ' |
102
|
|
|
|
|
|
|
% $m->notes("foo", 2); |
103
|
|
|
|
|
|
|
<% $m->notes("foo") %> |
104
|
|
|
|
|
|
|
<& /show &> |
105
|
|
|
|
|
|
|
<% $m->notes("foo") %> |
106
|
|
|
|
|
|
|
', |
107
|
|
|
|
|
|
|
expect => "2\n\n2\n\n3\n", |
108
|
|
|
|
|
|
|
); |
109
|
1
|
|
|
1
|
|
234
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub test_page : Tests { |
112
|
1
|
|
|
1
|
0
|
259
|
my $self = shift; |
113
|
1
|
|
|
|
|
8
|
$self->add_comp( path => '/page/other.mi', src => '<% $m->page->cmeta->path %>' ); |
114
|
1
|
|
|
|
|
9
|
$self->test_comp( |
115
|
|
|
|
|
|
|
path => '/page/first.mc', |
116
|
|
|
|
|
|
|
src => '<% $m->page->cmeta->path %>; <& other.mi &>', |
117
|
|
|
|
|
|
|
expect => '/page/first.mc; /page/first.mc' |
118
|
|
|
|
|
|
|
); |
119
|
1
|
|
|
1
|
|
232
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub test_result_data : Tests { |
122
|
1
|
|
|
1
|
0
|
226
|
my $self = shift; |
123
|
1
|
|
|
|
|
9
|
$self->test_comp( |
124
|
|
|
|
|
|
|
src => '% $m->result->data->{color} = "red"', |
125
|
|
|
|
|
|
|
expect_data => { color => "red" } |
126
|
|
|
|
|
|
|
); |
127
|
1
|
|
|
1
|
|
213
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub test_scomp : Tests { |
130
|
1
|
|
|
1
|
0
|
236
|
my $self = shift; |
131
|
1
|
|
|
|
|
7
|
$self->add_comp( path => '/str', src => 'abcde' ); |
132
|
|
|
|
|
|
|
$self->run_test_in_comp( |
133
|
|
|
|
|
|
|
test => sub { |
134
|
1
|
|
|
1
|
|
2
|
my $comp = shift; |
135
|
1
|
|
|
|
|
25
|
my $m = $comp->m; |
136
|
1
|
|
|
|
|
9
|
is( $m->scomp('/str'), 'abcde' ); |
137
|
1
|
|
|
|
|
572
|
is( $m->capture( sub { $m->scomp('/str') } ), '' ); |
|
1
|
|
|
|
|
4
|
|
138
|
|
|
|
|
|
|
} |
139
|
1
|
|
|
|
|
11
|
); |
140
|
1
|
|
|
1
|
|
273
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub test_go : Tests { |
143
|
1
|
|
|
1
|
0
|
221
|
my $self = shift; |
144
|
|
|
|
|
|
|
|
145
|
1
|
|
|
|
|
1
|
my ( $buf, $result ); |
146
|
|
|
|
|
|
|
|
147
|
1
|
|
|
|
|
4
|
reset_id(); |
148
|
1
|
|
|
|
|
6
|
$self->add_comp( |
149
|
|
|
|
|
|
|
path => '/subreq/other.mc', |
150
|
|
|
|
|
|
|
src => ' |
151
|
|
|
|
|
|
|
id=<% $m->id %> |
152
|
|
|
|
|
|
|
<% $m->page->cmeta->path %> |
153
|
|
|
|
|
|
|
<% $m->request_path %> |
154
|
|
|
|
|
|
|
args: <% Mason::Util::dump_one_line($m->request_args) %> |
155
|
|
|
|
|
|
|
', |
156
|
|
|
|
|
|
|
); |
157
|
1
|
|
|
|
|
7
|
$self->test_comp( |
158
|
|
|
|
|
|
|
path => '/subreq/go.mc', |
159
|
|
|
|
|
|
|
src => ' |
160
|
|
|
|
|
|
|
This should not get printed. |
161
|
|
|
|
|
|
|
<%perl>$m->go("/subreq/other", foo => 5);</%perl>', |
162
|
|
|
|
|
|
|
expect => ' |
163
|
|
|
|
|
|
|
id=1 |
164
|
|
|
|
|
|
|
/subreq/other.mc |
165
|
|
|
|
|
|
|
/subreq/other |
166
|
|
|
|
|
|
|
args: {foo => 5} |
167
|
|
|
|
|
|
|
', |
168
|
|
|
|
|
|
|
); |
169
|
1
|
|
|
|
|
4
|
reset_id(); |
170
|
1
|
|
|
|
|
4
|
$self->test_comp( |
171
|
|
|
|
|
|
|
path => '/subreq/go_with_req_params.mc', |
172
|
|
|
|
|
|
|
src => ' |
173
|
|
|
|
|
|
|
This should not get printed. |
174
|
|
|
|
|
|
|
<%perl>my $buf; $m->go({out_method => \$buf}, "/subreq/other", foo => 5)</%perl>', |
175
|
|
|
|
|
|
|
expect => '', |
176
|
|
|
|
|
|
|
); |
177
|
|
|
|
|
|
|
|
178
|
1
|
|
|
|
|
5
|
reset_id(); |
179
|
1
|
|
|
|
|
4
|
$result = $self->interp->run( { out_method => \$buf }, '/subreq/go' ); |
180
|
1
|
|
|
|
|
33
|
is( $result->output, '', 'no output' ); |
181
|
1
|
|
|
|
|
519
|
is( |
182
|
|
|
|
|
|
|
$buf, ' |
183
|
|
|
|
|
|
|
id=1 |
184
|
|
|
|
|
|
|
/subreq/other.mc |
185
|
|
|
|
|
|
|
/subreq/other |
186
|
|
|
|
|
|
|
args: {foo => 5} |
187
|
|
|
|
|
|
|
', 'output in buf' |
188
|
|
|
|
|
|
|
); |
189
|
1
|
|
|
1
|
|
304
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub test_visit : Tests { |
192
|
1
|
|
|
1
|
0
|
118
|
my $self = shift; |
193
|
|
|
|
|
|
|
|
194
|
1
|
|
|
|
|
2
|
my ( $buf, $result ); |
195
|
|
|
|
|
|
|
|
196
|
1
|
|
|
|
|
3
|
reset_id(); |
197
|
1
|
|
|
|
|
9
|
$self->add_comp( |
198
|
|
|
|
|
|
|
path => '/subreq/other.mc', |
199
|
|
|
|
|
|
|
src => ' |
200
|
|
|
|
|
|
|
id=<% $m->id %> |
201
|
|
|
|
|
|
|
<% $m->page->cmeta->path %> |
202
|
|
|
|
|
|
|
<% $m->request_path %> |
203
|
|
|
|
|
|
|
args: <% Mason::Util::dump_one_line($m->request_args) %> |
204
|
|
|
|
|
|
|
', |
205
|
|
|
|
|
|
|
); |
206
|
1
|
|
|
|
|
8
|
$self->test_comp( |
207
|
|
|
|
|
|
|
path => '/subreq/visit.mc', |
208
|
|
|
|
|
|
|
src => ' |
209
|
|
|
|
|
|
|
begin |
210
|
|
|
|
|
|
|
id=<% $m->id %> |
211
|
|
|
|
|
|
|
<%perl>$m->visit("/subreq/other", foo => 5);</%perl> |
212
|
|
|
|
|
|
|
id=<% $m->id %> |
213
|
|
|
|
|
|
|
end |
214
|
|
|
|
|
|
|
', |
215
|
|
|
|
|
|
|
expect => ' |
216
|
|
|
|
|
|
|
begin |
217
|
|
|
|
|
|
|
id=0 |
218
|
|
|
|
|
|
|
id=1 |
219
|
|
|
|
|
|
|
/subreq/other.mc |
220
|
|
|
|
|
|
|
/subreq/other |
221
|
|
|
|
|
|
|
args: {foo => 5} |
222
|
|
|
|
|
|
|
id=0 |
223
|
|
|
|
|
|
|
end |
224
|
|
|
|
|
|
|
', |
225
|
|
|
|
|
|
|
); |
226
|
|
|
|
|
|
|
|
227
|
1
|
|
|
|
|
5
|
reset_id(); |
228
|
1
|
|
|
|
|
6
|
$self->test_comp( |
229
|
|
|
|
|
|
|
path => '/subreq/visit_with_req_params.mc', |
230
|
|
|
|
|
|
|
src => ' |
231
|
|
|
|
|
|
|
begin |
232
|
|
|
|
|
|
|
id=<% $m->id %> |
233
|
|
|
|
|
|
|
<%perl>my $buf; $m->visit({out_method => \$buf}, "/subreq/other", foo => 5); print uc($buf);</%perl> |
234
|
|
|
|
|
|
|
id=<% $m->id %> |
235
|
|
|
|
|
|
|
end |
236
|
|
|
|
|
|
|
', |
237
|
|
|
|
|
|
|
expect => ' |
238
|
|
|
|
|
|
|
begin |
239
|
|
|
|
|
|
|
id=0 |
240
|
|
|
|
|
|
|
ID=1 |
241
|
|
|
|
|
|
|
/SUBREQ/OTHER.MC |
242
|
|
|
|
|
|
|
/SUBREQ/OTHER |
243
|
|
|
|
|
|
|
ARGS: {FOO => 5} |
244
|
|
|
|
|
|
|
id=0 |
245
|
|
|
|
|
|
|
end |
246
|
|
|
|
|
|
|
', |
247
|
|
|
|
|
|
|
); |
248
|
|
|
|
|
|
|
|
249
|
1
|
|
|
|
|
4
|
reset_id(); |
250
|
1
|
|
|
|
|
4
|
$result = $self->interp->run( { out_method => \$buf }, '/subreq/visit' ); |
251
|
1
|
|
|
|
|
40
|
is( $result->output, '', 'no output' ); |
252
|
1
|
|
|
|
|
525
|
is( |
253
|
|
|
|
|
|
|
$buf, ' |
254
|
|
|
|
|
|
|
begin |
255
|
|
|
|
|
|
|
id=0 |
256
|
|
|
|
|
|
|
id=1 |
257
|
|
|
|
|
|
|
/subreq/other.mc |
258
|
|
|
|
|
|
|
/subreq/other |
259
|
|
|
|
|
|
|
args: {foo => 5} |
260
|
|
|
|
|
|
|
id=0 |
261
|
|
|
|
|
|
|
end |
262
|
|
|
|
|
|
|
', 'visit with initial out_method' |
263
|
|
|
|
|
|
|
); |
264
|
1
|
|
|
1
|
|
296
|
} |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
4
|
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub reset_id { |
267
|
6
|
|
|
6
|
0
|
39
|
Mason::Request->_reset_next_id; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
1; |