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   37 use strict;
  5         23  
  5         159  
3 5     5   23 use warnings;
  5         5  
  5         331  
4              
5             our $VERSION = '0.03';
6              
7             # adds a handler to LWP::UserAgent to mock HTTP requests
8              
9             require LWP::UserAgent;
10            
11 5     5   32 no warnings 'redefine';
  5         5  
  5         626  
12             my $orig = \&LWP::UserAgent::new;
13              
14             *LWP::UserAgent::new = sub {
15 4     4   3144 my ($class, @args) = @_;
16 4         17 my $ua = $orig->($class, @args);
17              
18             # This remains in the model to avoid circular deps
19 4         213 require SimpleMock::Model::LWP_UA;
20 4         17 $ua->add_handler(request_send => \&SimpleMock::Model::LWP_UA::mock_send_request);
21              
22 4         94 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