File Coverage

blib/lib/SimpleMock/Mocks/LWP/UserAgent.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 18 18 100.0


line stmt bran cond sub pod time code
1             package SimpleMock::Mocks::LWP::UserAgent;
2 5     5   29 use strict;
  5         18  
  5         206  
3 5     5   29 use warnings;
  5         5  
  5         301  
4              
5             our $VERSION = '0.01';
6              
7             # adds a handler to LWP::UserAgent to mock HTTP requests
8              
9             require LWP::UserAgent;
10            
11 5     5   18 no warnings 'redefine';
  5         7  
  5         649  
12             my $orig = \&LWP::UserAgent::new;
13              
14             *LWP::UserAgent::new = sub {
15 4     4   2700 my ($class, @args) = @_;
16 4         14 my $ua = $orig->($class, @args);
17              
18             # This remains in the model to avoid circular deps
19 4         226 require SimpleMock::Model::LWP_UA;
20 4         32 $ua->add_handler(request_send => \&SimpleMock::Model::LWP_UA::mock_send_request);
21              
22 4         76 return $ua;
23             };
24              
25             1;
26              
27             =head1 NAME
28              
29             SimpleMock::Mocks::LWP::UserAgent - Mock LWP::UserAgent for testing
30              
31             =head1 DESCRIPTION
32              
33             This module overrides the constructor of LWP::UserAgent to add a custom request handler that allows for mocking HTTP requests in tests.
34              
35             =cut