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   45 use strict;
  5         20  
  5         156  
3 5     5   21 use warnings;
  5         6  
  5         317  
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         6  
  5         596  
12             my $orig = \&LWP::UserAgent::new;
13              
14             *LWP::UserAgent::new = sub {
15 4     4   2862 my ($class, @args) = @_;
16 4         19 my $ua = $orig->($class, @args);
17              
18             # This remains in the model to avoid circular deps
19 4         231 require SimpleMock::Model::LWP_UA;
20 4         19 $ua->add_handler(request_send => \&SimpleMock::Model::LWP_UA::mock_send_request);
21              
22 4         79 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