File: UA.pm

package info (click to toggle)
libpithub-perl 0.01025-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 880 kB
  • ctags: 300
  • sloc: perl: 3,204; makefile: 7
file content (26 lines) | stat: -rw-r--r-- 708 bytes parent folder | download
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
package    # hide from PAUSE
  Pithub::Test::UA;

use Moo;
use File::Basename qw(dirname);
use File::Slurp qw(read_file);
use HTTP::Response;
use Test::More;

sub request {
    my ( $self, $request ) = @_;
    my $path = sprintf '%s/http_response/%s/%s.%s', dirname(__FILE__), $request->uri->host, $request->uri->path, $request->method;
    my %query_form = $request->uri->query_form;
    foreach my $k ( sort keys %query_form ) {
        $path .= sprintf '.%s-%s', $k, $query_form{$k};
    }
    my $response = HTTP::Response->new;
    if ( -f $path ) {
        my $res = read_file($path);
        $response = HTTP::Response->parse($res);
    }
    $response->request($request);
    return $response;
}

1;