| 1 | package Mock::LWP::Request; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use HTTP::Status qw( :constants ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use HTTP::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | has old_lwp_request => ( | ||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||
| 14 | init_arg => undef, | ||||||||||||||||||||||||||||
| 15 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | return \&LWP::UserAgent::request; | |||||||||||||||||||||||||||
| 17 | }, | ||||||||||||||||||||||||||||
| 18 | 1 | ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | has default_response => ( | ||||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||
| 22 | 1 | ▶ | isa => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | die "default_response must be a HTTP::Response object" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $_[0] and ref $_[0] eq "HTTP::Response"
MC/DC0%0/2
ref $_[0] and ref $_[0] eq "HTTP::Response"
ref $_[0]
ref $_[0] eq "HTTP::Response"
Truth table33%1/3
A and B
A= ref $_[0]B= ref $_[0] eq "HTTP::Response"
| |||||||||||||||||||||||||||||
| 24 | unless (ref $_[0] && ref $_[0] eq 'HTTP::Response'); | ||||||||||||||||||||||||||||
| 25 | }, | ||||||||||||||||||||||||||||
| 26 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | return HTTP::Response->new( HTTP_PRECONDITION_FAILED ); | |||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||
| 29 | 1 | ); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | has missing_response_action => ( | ||||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||
| 33 | 3 | ▶ | isa => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | die "missing_response_action must be either die or default" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_[0] eq "die" or $_[0] eq "default"
MC/DC0%0/2
$_[0] eq "die" or $_[0] eq "default"
$_[0] eq "die"
$_[0] eq "default"
Truth table66%2/3
A or B
A= $_[0] eq "die"B= $_[0] eq "default"
| |||||||||||||||||||||||||||||
| 35 | unless $_[0] eq 'die' || $_[0] eq 'default'; | ||||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||
| 37 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 1 | return 'die'; | |||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||
| 40 | 1 | ); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | has response_list => ( | ||||||||||||||||||||||||||||
| 43 | is => 'rw', | ||||||||||||||||||||||||||||
| 44 | 1 | ▶ | isa => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | die "$_[0] is not an ARRAY ref" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $_[0] and ref $_[0] eq "ARRAY"
MC/DC0%0/2
ref $_[0] and ref $_[0] eq "ARRAY"
ref $_[0]
ref $_[0] eq "ARRAY"
Truth table33%1/3
A and B
A= ref $_[0]B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||
| 46 | unless ( ref $_[0] && ref $_[0] eq 'ARRAY' ); | ||||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||
| 48 | 1 | ▶ | default => sub { return []; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 1 | ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | has enabled => ( | ||||||||||||||||||||||||||||
| 52 | is => 'rwp', | ||||||||||||||||||||||||||||
| 53 | init_arg => undef, | ||||||||||||||||||||||||||||
| 54 | 1 | ▶ | default => sub { return 0; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 1 | ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | has debug => ( | ||||||||||||||||||||||||||||
| 58 | is => 'rw', | ||||||||||||||||||||||||||||
| 59 | 1 | ▶ | default => sub { return 0; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 1 | ); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub enable { | ||||||||||||||||||||||||||
|
Subroutine
enable: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | ▶ | return if $self->enabled; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 1 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | 6 | ▶ | *LWP::UserAgent::request = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 69 | 6 | my $class = shift; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 6 | ▶ | warn "IN REDEFINED LWP::UserAgent::request" if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 6 | my $response = shift @{ $self->response_list }; | |||||||||||||||||||||||||||
| 74 | 6 | ▶ | return $response if defined $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 2 | ▶ | die "No response" if $self->missing_response_action eq 'die'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 1 | return $self->default_response; | |||||||||||||||||||||||||||
| 77 | 1 | }; | |||||||||||||||||||||||||||
| 78 | 1 | ▶ | use warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | 1 | $self->_set_enabled(1); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub disable { | ||||||||||||||||||||||||||
|
Subroutine
disable: not called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return unless $self->enabled; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | 0 | *LWP::UserAgent::request = $self->old_lwp_request; | |||||||||||||||||||||||||||
| 89 | 1 | ▶ | use warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | 0 | $self->_set_enabled(0); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 4 | ▶ | sub add_response { | ||||||||||||||||||||||||||
|
Subroutine
add_response: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 4 | my ($self, $response) = @_; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 4 | ▶ | die "Response must be a HTTP::Response object" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $response and ref $response eq "HTTP::Response"
MC/DC0%0/2
ref $response and ref $response eq "HTTP::Response"
ref $response
ref $response eq "HTTP::Response"
Truth table33%1/3
A and B
A= ref $responseB= ref $response eq "HTTP::Response"
| |||||||||||||||||||||||||||||
| 97 | unless ref $response && ref $response eq 'HTTP::Response'; | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 4 | push @{ $self->response_list }, $response; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub DEMOLISH { | ||||||||||||||||||||||||||
|
Subroutine
DEMOLISH: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | $self->disable(); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | 1; | |||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||||