File: UA.pm

package info (click to toggle)
libpithub-perl 0.01043-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,148 kB
  • sloc: perl: 9,098; makefile: 7
file content (30 lines) | stat: -rw-r--r-- 665 bytes parent folder | download | duplicates (2)
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
package    # hide from PAUSE
    Pithub::Test::UA;

use Moo;

use Path::Tiny     qw( path );
use HTTP::Response ();

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;