This file is indexed.

/usr/share/perl5/AnyEvent/HTTP/ScopedClient.pm is in libanyevent-http-scopedclient-perl 0.0.5-2.

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
package AnyEvent::HTTP::ScopedClient;
{
  $AnyEvent::HTTP::ScopedClient::VERSION = '0.0.5';
}

# ABSTRACT: L<AnyEvent> based L<https://github.com/technoweenie/node-scoped-http-client>

use Moose;
use namespace::autoclean;

use URI;
use Try::Tiny;
use MIME::Base64;
use HTTP::Request;
use Encode qw/encode_utf8/;
use AnyEvent::HTTP;
use URI::QueryParam;
use URI::Escape;

has 'options' => (
    is  => 'ro',
    isa => 'HashRef',
);

sub request {
    my ( $self, $method, $reqBody, $callback ) = @_;
    if ( 'CODE' eq ref($reqBody) ) {
        $callback = $reqBody;
        undef $reqBody;
    }

    my %options = %{ $self->options };
    try {
        my %headers = %{ $options{headers} };

        if ( 'HASH' eq ref($reqBody) ) {
            my @pair;

            # push @pair, "$_=$reqBody->{$_}" for ( keys %$reqBody );
            push @pair, "$_=" . uri_escape_utf8( $reqBody->{$_} )
                for ( keys %$reqBody );
            $reqBody = join( '&', @pair );
        }

        my $sendingData
            = ( $method =~ m/^P/ && $reqBody && length $reqBody > 0 ) ? 1 : 0;
        $headers{'Content-Length'} = length $reqBody if $sendingData;
        $headers{'Content-Type'} = 'application/x-www-form-urlencoded'
            if ( $sendingData && !$headers{'Content-Type'} );

        if ( $options{auth} ) {
            $headers{Authorization}
                = 'Basic ' . encode_base64( $options{auth}, '' );
        }

        if ( $ENV{DEBUG} ) {
            print "$method " . $self->options->{url} . "\n";
            while ( my ( $k, $v ) = each %headers ) {
                print "$k: $v\n";
            }

            print "\n";
            print "$reqBody\n" if $sendingData;
        }

        http_request(
            $method,
            $options{url},
            headers => \%headers,
            body    => $sendingData ? encode_utf8($reqBody) : undef,
            $callback
        );
    }
    catch {
        $callback->($_) if $callback;
    };

    return $self;
}

sub fullPath {
    my ( $self, $p ) = @_;
}

sub scope {
    my ( $self, $url, $options, $callback ) = @_;
}

sub join {
    my ( $self, $suffix ) = @_;
}

sub path {
    my ( $self, $p ) = @_;
}

sub query {
    my ( $self, $key, $value ) = @_;
    if ( 'HASH' eq ref $key ) {
        while ( my ( $k, $v ) = each %$key ) {
            $self->options->{url}->query_param( $k => $v );
        }
    }
    else {
        $self->options->{url}->query_param( $key => $value );
    }
    return $self;
}

sub host {
    my ( $self, $h ) = @_;
}

sub protocol {
    my ( $self, $p ) = @_;
}

sub auth {
    my ( $self, $user, $pass ) = @_;
    if ( !$user ) {
        $self->options->{auth} = undef;
    }
    elsif ( !$pass && $user =~ m/:/ ) {
        $self->options->{auth} = $user;
    }
    else {
        $self->options->{auth} = "$user:$pass";
    }

    return $self;
}

sub header {
    my ( $self, $name, $value ) = @_;
    if ( 'HASH' eq ref $name ) {
        while ( my ( $k, $v ) = each %$name ) {
            $self->options->{headers}{$k} = $v;
        }
    }
    else {
        $self->options->{headers}{$name} = $value;
    }

    return $self;
}

sub headers {
    my ( $self, $h ) = @_;
}

sub buildOptions {
    my ( $self, $url, $params ) = @_;
    $params->{options}{url} = URI->new($url);
    $params->{options}{headers} ||= {};
}

sub BUILDARGS {
    my ( $self, $url, %params ) = @_;
    $self->buildOptions( $url, \%params );
    return \%params;
}

sub get    { shift->request( 'GET',    @_ ) }
sub post   { shift->request( 'POST',   @_ ) }
sub patch  { shift->request( 'PATCH',  @_ ) }
sub put    { shift->request( 'PUT',    @_ ) }
sub delete { shift->request( 'DELETE', @_ ) }
sub head   { shift->request( 'HEAD',   @_ ) }

__PACKAGE__->meta->make_immutable;

1;

__END__

=pod

=encoding utf-8

=head1 NAME

AnyEvent::HTTP::ScopedClient - L<AnyEvent> based L<https://github.com/technoweenie/node-scoped-http-client>

=head1 VERSION

version 0.0.5

=head1 SYNOPSIS

    my $client = AnyEvent::HTTP::ScopedClient->new('http://example.com');
    $client->request('GET', sub {
        my ($body, $hdr) = @_;    # $body is undef if error occured
        return if ( !$body || $hdr->{Status} !~ /^2/ );
        # do something;
    });

    # shorcut for GET
    $client->get(sub {
        my ($body, $hdr) = @_;
        # ...
    });

    # Content-Type: application/x-www-form-urlencoded
    $client->post(
        { foo => 1, bar => 2 },    # note this.
        sub {
            my ($body, $hdr) = @_;
            # ...
        }
    );

    # application/x-www-form-urlencoded post request
    $client->post(
        "foo=1&bar=2"    # and note this.
        sub {
            my ($body, $hdr) = @_;
            # ...
        }
    );

    # Content-Type: application/json
    use JSON::XS;
    $client->header('Content-Type', 'application/json')
        ->post(
            encode_json({ foo => 1 }),
            sub {
                my ($body, $hdr) = @_;
                # ...
            }
        );

    $client->header('Accept', 'application/json')
        ->query({ key => 'value' })
        ->query('key', 'value')
        ->get(
            sub {
                my ($body, $hdr) = @_;
                # ...
            }
        );

    # headers at once
    $client->header({
        Accept        => '*/*',
        Authorization => 'Basic abcd'
    })->get(
        sub {
            my ($body, $hdr) = @_;
            # ...
        }
    );

=head1 DESCRIPTION

L<AnyEvent::HTTP> wrapper

=head1 SEE ALSO

L<https://github.com/technoweenie/node-scoped-http-client>

=head1 AUTHOR

Hyungsuk Hong <hshong@perl.kr>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Hyungsuk Hong.

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

=cut