| 1 | package Paws::Net::FileMockCaller; | ||||||||||
| 2 | 7 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 7 | with 'Paws::Net::RetryCallerRole', 'Paws::Net::CallerRole'; | |||||||||
| 5 | |||||||||||
| 6 | 7 | ▶ | use Paws::Net::APIResponse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 7 | ▶ | use File::Slurper qw(read_text write_text); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 7 | ▶ | use JSON::MaybeXS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 7 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 7 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 7 | has file => (is => 'rw', isa => 'Str', trigger => \&_set_file); | |||||||||
| 13 | |||||||||||
| 14 | has real_caller => ( | ||||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | does => 'Paws::Net::CallerRole', | ||||||||||
| 17 | 40 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 40 | require Paws::Net::Caller; | |||||||||
| 19 | 40 | Paws::Net::Caller->new; | |||||||||
| 20 | } | ||||||||||
| 21 | 7 | ); | |||||||||
| 22 | |||||||||||
| 23 | 113 | ▶ | sub _set_file { | ||||||||
|
Subroutine
_set_file: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 113 | my $self = shift; | |||||||||
| 25 | 113 | $self->_clear_file_contents; | |||||||||
| 26 | 113 | $self->_clear_method; | |||||||||
| 27 | 113 | $self->_clear_service; | |||||||||
| 28 | 113 | $self->_clear_params; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | has file_contents => ( | ||||||||||
| 32 | is => 'ro', | ||||||||||
| 33 | isa => 'HashRef', | ||||||||||
| 34 | lazy => 1, | ||||||||||
| 35 | clearer => '_clear_file_contents', | ||||||||||
| 36 | 113 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 113 | my $self = shift; | |||||||||
| 38 | 113 | my $content = read_text($self->file); | |||||||||
| 39 | 113 | my $hash = $self->_encoder->decode($content); | |||||||||
| 40 | 113 | return $hash; | |||||||||
| 41 | } | ||||||||||
| 42 | 7 | ); | |||||||||
| 43 | |||||||||||
| 44 | has service => ( | ||||||||||
| 45 | is => 'ro', | ||||||||||
| 46 | isa => 'Str', | ||||||||||
| 47 | clearer => '_clear_service', | ||||||||||
| 48 | lazy => 1, | ||||||||||
| 49 | 40 | ▶ | default => sub { shift->file_contents->{ request }->{ service } } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 7 | ); | |||||||||
| 51 | has method => ( | ||||||||||
| 52 | is => 'ro', | ||||||||||
| 53 | isa => 'Str', | ||||||||||
| 54 | clearer => '_clear_method', | ||||||||||
| 55 | lazy => 1, | ||||||||||
| 56 | 40 | ▶ | default => sub { shift->file_contents->{ request }->{ call } } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 57 | 7 | ); | |||||||||
| 58 | has params => ( | ||||||||||
| 59 | is => 'ro', | ||||||||||
| 60 | isa => 'HashRef', | ||||||||||
| 61 | clearer => '_clear_params', | ||||||||||
| 62 | lazy => 1, | ||||||||||
| 63 | 113 | ▶ | default => sub { shift->file_contents->{ request }->{ params } } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 7 | ); | |||||||||
| 65 | |||||||||||
| 66 | has actual_request => ( | ||||||||||
| 67 | is => 'rw', | ||||||||||
| 68 | isa => 'Object', | ||||||||||
| 69 | lazy => 1, | ||||||||||
| 70 | 0 | ▶ | default => sub { '' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 71 | 7 | ); | |||||||||
| 72 | |||||||||||
| 73 | 54 | ▶ | has _encoder => (is => 'ro', default => sub { JSON::MaybeXS->new(canonical => 1) }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 74 | |||||||||||
| 75 | 113 | ▶ | sub send_request { | ||||||||
|
Subroutine
send_request: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||
| 76 | 113 | my ($self, $service, $call_object) = @_; | |||||||||
| 77 | |||||||||||
| 78 | 113 | $self->actual_request($service->prepare_request_for_call($call_object)); | |||||||||
| 79 | 113 | my $actual_call = $self->_encoder->encode($service->to_hash($call_object)); | |||||||||
| 80 | 113 | my $recorded_call = $self->_encoder->encode($self->params); | |||||||||
| 81 | |||||||||||
| 82 | 113 | ▶ | if ($actual_call ne $recorded_call) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | warn "CALL: $actual_call"; | |||||||||
| 84 | 0 | warn "RECORDED: $recorded_call"; | |||||||||
| 85 | |||||||||||
| 86 | 0 | Paws::Exception->throw( | |||||||||
| 87 | request_id => '', | ||||||||||
| 88 | code => 'ReplayInvalid', | ||||||||||
| 89 | message => 'The calling parameters and the parameters used to generate the call are not equal' | ||||||||||
| 90 | ) | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 113 | my $response = $self->file_contents; | |||||||||
| 94 | return Paws::Net::APIResponse->new( | ||||||||||
| 95 | status => $response->{response}{status}, | ||||||||||
| 96 | content => $response->{response}{content}, | ||||||||||
| 97 | headers => $response->{response}{headers} | ||||||||||
| 98 | 113 | ); | |||||||||
| 99 | }; | ||||||||||
| 100 | |||||||||||
| 101 | 113 | ▶ | sub caller_to_response { | ||||||||
|
Subroutine
caller_to_response: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 102 | 113 | my ($self, $service, $call_object, $response) = @_; | |||||||||
| 103 | |||||||||||
| 104 | 113 | return $self->real_caller->caller_to_response($service, $call_object, $response); | |||||||||
| 105 | }; | ||||||||||
| 106 | |||||||||||
| 107 | 7 | 1; | |||||||||