blib/lib/Mock/LWP/Request.pm

filter: Statementstmt 90.7% 59 / 65 Branchbran 55.5% 10 / 18 Conditioncond 41.6% 5 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 91.3% 21 / 23 Podpod 75.0% 3 / 4 totaltotal 75.3% 98 / 130 CC 14 SCAR 8.8
CC
14
Cov
78%
__ANON__
4.1
__ANON__
4.1
__ANON__
4.0
CRAP 2.4
↑ Summary
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
BranchTrueFalseTotal
unless ref $_[0] and ref $_[0] eq "HTTP::Response" 0 1 1
Condition33%1/3
ref $_[0] and ref $_[0] eq "HTTP::Response"
!ll&&!rl&&r
001
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $_[0] eq "die" or $_[0] eq "default" 0 3 3
Condition66%2/3
$_[0] eq "die" or $_[0] eq "default"
l!l&&r!l&&!r
210
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"
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless ref $_[0] and ref $_[0] eq "ARRAY" 0 1 1
Condition33%1/3
ref $_[0] and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
001
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $self->enabled 0 1 1
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
BranchTrueFalseTotal
if $self->debug 0 6 6
72
73 6 my $response = shift @{ $self->response_list };
74 6 ▶ return $response if defined $response;
Branch: 1 branch
BranchTrueFalseTotal
if defined $response 4 2 6
75 2 ▶ die "No response" if $self->missing_response_action eq 'die';
Branch: 1 branch
BranchTrueFalseTotal
if $self->missing_response_action eq "die" 1 1 2
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
BranchTrueFalseTotal
unless $self->enabled 0 0 0
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
BranchTrueFalseTotal
unless ref $response and ref $response eq "HTTP::Response" 0 4 4
Condition33%1/3
ref $response and ref $response eq "HTTP::Response"
!ll&&!rl&&r
004
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"
ABresult
0X0
100
111
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__
↑ Summary