line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Socialtext::Resting::Mock; |
2
|
8
|
|
|
8
|
|
126463
|
use strict; |
|
8
|
|
|
|
|
38
|
|
|
8
|
|
|
|
|
583
|
|
3
|
8
|
|
|
8
|
|
44
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
229
|
|
4
|
8
|
|
|
8
|
|
7050
|
use HTTP::Response; |
|
8
|
|
|
|
|
299581
|
|
|
8
|
|
|
|
|
10624
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Socialtext::Resting::Mock - Fake rester |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $rester = Socialtext::Resting::Mock->(file => 'foo'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# returns content of 'foo' |
15
|
|
|
|
|
|
|
$rester->get_page('bar'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 FUNCTIONS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 new( %opts ) |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Create a new fake rester object. Options: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over 4 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=item file |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
File to return the contents of. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=back |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
38
|
23
|
|
|
23
|
1
|
33581
|
my ($class, %opts) = @_; |
39
|
23
|
50
|
|
|
|
156
|
if ($opts{file}) { |
40
|
0
|
0
|
|
|
|
0
|
die "not a file: $opts{file}" unless -f $opts{file}; |
41
|
|
|
|
|
|
|
} |
42
|
23
|
|
|
|
|
56
|
my $self = \%opts; |
43
|
23
|
|
|
|
|
103
|
bless $self, $class; |
44
|
23
|
|
|
|
|
119
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 server( $new_server ) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Get or set the server. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub server { |
54
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
55
|
0
|
|
|
|
|
0
|
my $server = shift; |
56
|
0
|
0
|
|
|
|
0
|
$self->{server} = $server if $server; |
57
|
0
|
|
|
|
|
0
|
return $self->{server}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 username( $new_username ) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Get or set the username. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub username { |
67
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
68
|
0
|
|
|
|
|
0
|
my $username = shift; |
69
|
0
|
0
|
|
|
|
0
|
$self->{username} = $username if $username; |
70
|
0
|
|
|
|
|
0
|
return $self->{username}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 password( $new_password ) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Get or set the password. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub password { |
80
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
81
|
0
|
|
|
|
|
0
|
my $password = shift; |
82
|
0
|
0
|
|
|
|
0
|
$self->{password} = $password if $password; |
83
|
0
|
|
|
|
|
0
|
return $self->{password}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 workspace( $new_workspace ) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Get or set the workspace. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub workspace { |
93
|
16
|
|
|
16
|
1
|
35
|
my $self = shift; |
94
|
16
|
|
|
|
|
32
|
my $workspace = shift; |
95
|
16
|
100
|
|
|
|
55
|
$self->{workspace} = $workspace if $workspace; |
96
|
16
|
|
|
|
|
343
|
return $self->{workspace}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 get_page( $page_name ) |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Returns the content of the specified file or the page stored |
102
|
|
|
|
|
|
|
locally in the object. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub get_page { |
107
|
56
|
|
|
56
|
1
|
1532
|
my $self = shift; |
108
|
56
|
|
|
|
|
139
|
my $page_name = shift; |
109
|
|
|
|
|
|
|
|
110
|
56
|
50
|
|
|
|
422
|
if ($self->{file}) { |
111
|
0
|
|
|
|
|
0
|
warn "Mock rester: returning content of $self->{file} for page ($page_name)\n"; |
112
|
0
|
0
|
|
|
|
0
|
open(my $fh, $self->{file}) or die "Can't open $self->{file}: $!"; |
113
|
0
|
|
|
|
|
0
|
local $/; |
114
|
0
|
|
|
|
|
0
|
my $page = <$fh>; |
115
|
0
|
|
|
|
|
0
|
close $fh; |
116
|
0
|
|
|
|
|
0
|
return $page; |
117
|
|
|
|
|
|
|
} |
118
|
56
|
|
|
|
|
80
|
my $text = shift @{ $self->{page}{$page_name} }; |
|
56
|
|
|
|
|
237
|
|
119
|
56
|
100
|
|
|
|
189
|
unless (defined $text) { |
120
|
4
|
|
|
|
|
23
|
$text = "$page_name not found"; |
121
|
|
|
|
|
|
|
} |
122
|
56
|
|
|
|
|
512
|
return $text; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 get_pages |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Retrieve a list of pages in the current workspace. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub get_pages { |
132
|
4
|
|
|
4
|
1
|
107
|
my ($self) = @_; |
133
|
4
|
100
|
|
|
|
20
|
return $self->{_get_pages} if $self->{_get_pages}; # testing shortcut |
134
|
1
|
|
|
|
|
2
|
return keys %{ $self->{page} }; |
|
1
|
|
|
|
|
5
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 put_page( $page_name ) |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Stores the page content in the object. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub put_page { |
145
|
54
|
|
|
54
|
|
40699
|
my ($self, $page, $content) = @_; |
146
|
54
|
50
|
|
|
|
283
|
die delete $self->{die_on_put} if $self->{die_on_put}; |
147
|
54
|
|
|
|
|
131
|
push @{ $self->{page}{$page} }, $content; |
|
54
|
|
|
|
|
394
|
|
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 put_pagetag( $page, $tag ) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Stores the page tags in the object. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub put_pagetag { |
157
|
11
|
|
|
11
|
1
|
59
|
my ($self, $page, $tag) = @_; |
158
|
11
|
|
|
|
|
32
|
push @{$self->{page_tags}{$page}}, $tag; |
|
11
|
|
|
|
|
89
|
|
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 get_pagetags( $page ) |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Retrieves page tags stored in the object. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub get_pagetags { |
168
|
8
|
|
|
8
|
1
|
32
|
my ($self, $page) = @_; |
169
|
8
|
|
100
|
|
|
72
|
my $tags = $self->{page_tags}{$page} || []; |
170
|
8
|
50
|
|
|
|
102
|
return @$tags if wantarray; |
171
|
0
|
|
|
|
|
0
|
return join ' ', @$tags; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 die_on_put( $rc ) |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Tells the next put_page() to die with the supplied return code. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub die_on_put { |
181
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
182
|
0
|
|
|
|
|
0
|
my $rc = shift; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
0
|
$self->{die_on_put} = $rc; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 accept( $mime_type ) |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Stores the requested mime type. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub accept { |
194
|
28
|
|
|
28
|
1
|
40
|
my $self = shift; |
195
|
28
|
|
|
|
|
154
|
$self->{accept} = shift; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 order( $order ) |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Stores the requested order. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub order { |
205
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
206
|
0
|
|
|
|
|
0
|
$self->{order} = shift; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head2 get_taggedpages( $tag ) |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Retrieves the taggedpages stored in the object. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub get_taggedpages { |
216
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
217
|
2
|
|
|
|
|
12
|
my $tag = shift; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
# makes testing easier |
220
|
2
|
|
|
|
|
7
|
my $mock_return = $self->{taggedpages}{$tag}; |
221
|
2
|
100
|
|
|
|
43
|
return $mock_return if defined $mock_return; |
222
|
|
|
|
|
|
|
|
223
|
1
|
|
|
|
|
2
|
my @taggedpages; |
224
|
1
|
|
|
|
|
2
|
for my $page (keys %{$self->{page_tags}}) { |
|
1
|
|
|
|
|
4
|
|
225
|
2
|
|
|
|
|
3
|
my $tags = $self->{page_tags}{$page}; |
226
|
2
|
100
|
|
|
|
4
|
next unless grep { $_ eq $tag } @$tags; |
|
2
|
|
|
|
|
8
|
|
227
|
1
|
|
|
|
|
2
|
push @taggedpages, $page; |
228
|
|
|
|
|
|
|
} |
229
|
1
|
50
|
|
|
|
6
|
return @taggedpages if wantarray; |
230
|
0
|
|
|
|
|
0
|
return join ' ', @taggedpages; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 set_taggedpages( $tag, $return ) |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Store the taggedpages return value in the object. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
This is not a real function, but it can make testing easier. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub set_taggedpages { |
242
|
1
|
|
|
1
|
1
|
70
|
my $self = shift; |
243
|
1
|
|
|
|
|
4
|
my $tag = shift; |
244
|
1
|
|
|
|
|
13
|
$self->{taggedpages}{$tag} = shift; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head2 json_verbose |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Set the json_verbose flag. |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |
252
|
|
|
|
|
|
|
|
253
|
2
|
|
|
2
|
1
|
7
|
sub json_verbose { $_[0]->{json_verbose} = $_[1] } |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head2 response |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Retrieve a fake response object. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=cut |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
sub response { |
262
|
4
|
|
|
4
|
1
|
30
|
my $self = shift; |
263
|
4
|
50
|
|
|
|
20
|
$self->{response} = shift if @_; |
264
|
4
|
|
66
|
|
|
86
|
$self->{response} ||= HTTP::Response->new(200); |
265
|
4
|
|
|
|
|
376
|
return $self->{response}; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=head1 AUTHOR |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
Luke Closs, C<< >> |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Copyright 2006 Luke Closs, all rights reserved. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
277
|
|
|
|
|
|
|
under the same terms as Perl itself. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=cut |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
1; |