fix transform in void context, Middleware::Runtime
[chaz/p5-HTTP-AnyUA] / t / lib / MockBackend.pm
1 package MockBackend;
2 # ABSTRACT: A backend for testing HTTP::AnyUA
3
4 use warnings;
5 use strict;
6
7 use Scalar::Util qw(blessed);
8 use namespace::clean;
9
10 use parent 'HTTP::AnyUA::Backend';
11
12
13 =method response
14
15 $response = $backend->response;
16 $response = $backend->response($response);
17
18 Get and set the response hashref or L<Future> that this backend will always respond with.
19
20 =cut
21
22 sub response { @_ == 2 ? $_[0]->{response} = pop : $_[0]->{response} }
23
24 =method requests
25
26 @requests = $backend->requests;
27
28 Get the requests the backend has handled so far.
29
30 =cut
31
32 sub requests { @{$_[0]->{requests} || []} }
33
34 sub response_is_future { blessed($_[0]->{response}) && $_[0]->{response}->isa('Future') }
35
36 sub request {
37 my $self = shift;
38
39 push @{$self->{requests} ||= []}, [@_];
40
41 return $self->response || {
42 success => '',
43 status => 599,
44 reason => 'Internal Exception',
45 content => "No response mocked.\n",
46 };
47 }
48
49
50 1;
This page took 0.035025 seconds and 4 git commands to generate.