NAME

Test::HTTP::Scenario::Adapter::LWP - LWP adapter for Test::HTTP::Scenario

SYNOPSIS

use Test::HTTP::Scenario::Adapter::LWP;

my $adapter = Test::HTTP::Scenario::Adapter::LWP->new;
$adapter->set_scenario($scenario);
$adapter->install;

DESCRIPTION

This adapter integrates Test::HTTP::Scenario with LWP::UserAgent. It temporarily overrides request() to route HTTP traffic through the scenario engine for record and replay.

METHODS

new

Construct a new LWP adapter.

Purpose

Initializes adapter state and prepares for scenario attachment.

Arguments (Params::Validate::Strict)

None.

Returns (Returns::Set)

  • adapter object

Side Effects

None.

Notes

Scenario must be attached via set_scenario() before use.

Example

my $adapter = Test::HTTP::Scenario::Adapter::LWP->new;

set_scenario

Attach a scenario to the adapter.

Purpose

Associates the adapter with a Test::HTTP::Scenario instance.

Arguments

  • scenario (Object)

    Scenario object.

Returns

True value.

Side Effects

Stores the scenario reference.

Notes

Must be called before install().

Example

$adapter->set_scenario($scenario);

install

Install the LWP request override.

Purpose

Monkey-patch LWP::UserAgent::request so that all HTTP requests pass through the scenario engine.

Arguments

None.

Returns

True value.

Side Effects

  • Overrides LWP::UserAgent::request globally.

  • Captures original request method on first install.

Notes

Idempotent per adapter instance.

Example

$adapter->install;

uninstall

Restore the original LWP request method.

Purpose

Undo the override installed by install().

Arguments

None.

Returns

True value.

Side Effects

Restores original request() method.

Notes

Idempotent per adapter instance.

Example

$adapter->uninstall;

normalize_request

Normalize an HTTP::Request.

Purpose

Convert an LWP request into a stable, serializable hash.

Arguments

  • req (HTTP::Request)

Returns

Hashref with method, uri, headers, body.

Side Effects

None.

Example

my $norm = $adapter->normalize_request($req);

normalize_response

Normalize an HTTP::Response.

Purpose

Convert an LWP response into a stable, serializable hash.

Arguments

  • res (HTTP::Response)

Returns

Hashref with status, reason, headers, body.

Side Effects

None.

Example

my $norm = $adapter->normalize_response($res);

build_response

Reconstruct an HTTP::Response from stored data.

Purpose

Convert a normalized response hash back into a real LWP response.

Arguments

  • hash (HashRef)

Returns

HTTP::Response object.

Side Effects

None.

Example

my $res = $adapter->build_response($hash);