File: UA.pm

package info (click to toggle)
libpithub-perl 0.01033-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 928 kB
  • ctags: 321
  • sloc: perl: 3,282; makefile: 7
file content (29 lines) | stat: -rw-r--r-- 645 bytes parent folder | download | duplicates (3)
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
package    # hide from PAUSE
  Pithub::Test::UA;

use Moo;
use Path::Tiny;
use HTTP::Response;
use Test::More;

my @responses;

sub add_response {
    my ( $self, $path ) = @_;
    my $full_path = sprintf '%s/http_response/api.github.com/%s', path(__FILE__)->dirname, $path;
    my $response_string = path($full_path)->slurp;
    my $response = HTTP::Response->parse($response_string);
    push @responses, $response;
}

sub request {
    my ( $self, $request ) = @_;
    my $result = HTTP::Response->new;
    if ( my $response = shift(@responses) ) {
        $result = $response;
    }
    $result->request($request);
    return $result;
}

1;