This file is indexed.

/usr/share/perl5/Socialtext/Resting/Mock.pm is in libsocialtext-resting-utils-perl 0.21-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package Socialtext::Resting::Mock;
use strict;
use warnings;
use HTTP::Response;

=head1 NAME

Socialtext::Resting::Mock - Fake rester

=head1 SYNOPSIS

  my $rester = Socialtext::Resting::Mock->(file => 'foo');

  # returns content of 'foo'
  $rester->get_page('bar');

=cut

our $VERSION = '0.04';

=head1 FUNCTIONS

=head2 new( %opts )

Create a new fake rester object.  Options:

=over 4

=item file

File to return the contents of.

=back

=cut

sub new {
    my ($class, %opts) = @_;
    if ($opts{file}) {
        die "not a file: $opts{file}" unless -f $opts{file};
    }
    my $self = \%opts;
    bless $self, $class;
    return $self;
}

=head2 server( $new_server )

Get or set the server.

=cut

sub server {
    my $self = shift;
    my $server = shift;
    $self->{server} = $server if $server;
    return $self->{server};
}

=head2 username( $new_username )

Get or set the username.

=cut

sub username {
    my $self = shift;
    my $username = shift;
    $self->{username} = $username if $username;
    return $self->{username};
}

=head2 password( $new_password )

Get or set the password.

=cut

sub password {
    my $self = shift;
    my $password = shift;
    $self->{password} = $password if $password;
    return $self->{password};
}

=head2 workspace( $new_workspace )

Get or set the workspace.

=cut

sub workspace {
    my $self = shift;
    my $workspace = shift;
    $self->{workspace} = $workspace if $workspace;
    return $self->{workspace};
}

=head2 get_page( $page_name )

Returns the content of the specified file or the page stored 
locally in the object.

=cut

sub get_page {
    my $self = shift;
    my $page_name = shift;

    if ($self->{file}) {
        warn "Mock rester: returning content of $self->{file} for page ($page_name)\n";
        open(my $fh, $self->{file}) or die "Can't open $self->{file}: $!";
        local $/;
        my $page = <$fh>;
        close $fh;
        return $page;
    }
    my $text = shift @{ $self->{page}{$page_name} };
    unless (defined $text) {
        $text = "$page_name not found";
    }
    return $text;
}

=head2 get_pages

Retrieve a list of pages in the current workspace.

=cut

sub get_pages {
    my ($self) = @_;
    return $self->{_get_pages} if $self->{_get_pages}; # testing shortcut
    return keys %{ $self->{page} };
}


=head2 put_page( $page_name )

Stores the page content in the object.

=cut

sub put_page {
    my ($self, $page, $content) = @_;
    die delete $self->{die_on_put} if $self->{die_on_put};
    push @{ $self->{page}{$page} }, $content;
}

=head2 put_pagetag( $page, $tag )

Stores the page tags in the object.

=cut

sub put_pagetag {
    my ($self, $page, $tag) = @_;
    push @{$self->{page_tags}{$page}}, $tag;
}

=head2 get_pagetags( $page )

Retrieves page tags stored in the object.

=cut

sub get_pagetags {
    my ($self, $page) = @_;
    my $tags = $self->{page_tags}{$page} || [];
    return @$tags if wantarray;
    return join ' ', @$tags;
}

=head2 die_on_put( $rc )

Tells the next put_page() to die with the supplied return code.

=cut

sub die_on_put {
    my $self = shift;
    my $rc = shift;

    $self->{die_on_put} = $rc;
}

=head2 accept( $mime_type )

Stores the requested mime type.

=cut

sub accept {
    my $self = shift;
    $self->{accept} = shift;
}

=head2 order( $order )

Stores the requested order.

=cut

sub order {
    my $self = shift;
    $self->{order} = shift;
}

=head2 get_taggedpages( $tag )

Retrieves the taggedpages stored in the object.

=cut

sub get_taggedpages {
    my $self = shift;
    my $tag = shift;

    # makes testing easier
    my $mock_return = $self->{taggedpages}{$tag};
    return $mock_return if defined $mock_return;

    my @taggedpages;
    for my $page (keys %{$self->{page_tags}}) {
        my $tags = $self->{page_tags}{$page};
        next unless grep { $_ eq $tag } @$tags;
        push @taggedpages, $page;
    }
    return @taggedpages if wantarray;
    return join ' ', @taggedpages;
}

=head2 set_taggedpages( $tag, $return )

Store the taggedpages return value in the object.

This is not a real function, but it can make testing easier.

=cut

sub set_taggedpages {
    my $self = shift;
    my $tag = shift;
    $self->{taggedpages}{$tag} = shift;
}

=head2 json_verbose

Set the json_verbose flag.

=cut

sub json_verbose { $_[0]->{json_verbose} = $_[1] }

=head2 response

Retrieve a fake response object.

=cut

sub response {
    my $self = shift;
    $self->{response} = shift if @_;
    $self->{response} ||= HTTP::Response->new(200);
    return $self->{response};
}

=head1 AUTHOR

Luke Closs, C<< <luke.closs at socialtext.com> >>

=head1 COPYRIGHT & LICENSE

Copyright 2006 Luke Closs, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

1;