NAME
SimpleMock::Model::LWP_UA - Mock model for LWP::UserAgent HTTP requests
DESCRIPTION
This module allows you to register HTTP mocks for LWP requests, enabling you to simulate various responses for testing purposes without making actual HTTP calls.
USAGE
You probably won't use this module directly. Instead, you will use the `SimpleMock` module to register your mocks. Here's an example of how to do that:
use SimpleMock qw(register_mocks);
register_mocks(
LWP_UA => {
# URL
'http://example.com/api' => {
# HTTP method
GET => [
# Each mock is a hashref with args and response
# args can be undef for default mock
# response can be a content string, or a hashref with code, message, content, and headers
{ args => { foo => 'bar' },
response => { code => 200, content => 'Success' }
},
{ args => { foo => 'bar2' },
response => 'Success'
},
# Default mock for GET method (no args) or for any other args not explicitly defined
{ response => { code => 404, content => 'Not Found' } },
],
POST => [
{ args => { data => 'test' },
response => { code => 201, content => 'Created' }
},
],
},
},
);
If args are not specified, the mock will be registered as a default mock for that URL and method. If args are specified, they will be used to differentiate between different mocks for the same URL and method that have different arguments.
The response can be a simple content string, or a hashref with the following keys:
code - HTTP status code (default: 200)
message - HTTP status message (default: derived from code)
content - The body of the response (default: empty string)
headers - A hashref of HTTP headers to include in the response (default: empty)
See the tests for more examples.