NAME

SimpleMock::ScopeGuard - Automatic cleanup of scoped mock layers

SYNOPSIS

use SimpleMock qw(register_mocks_scoped);

{
    my $guard = register_mocks_scoped(
        SUBS => {
            'My::Module' => {
                my_sub => [{ returns => 'scoped value' }],
            },
        },
    );
    # scoped mocks are active here
}
# $guard goes out of scope, DESTROY fires, scoped layer is removed

DESCRIPTION

Helper module to manage scoped mocks via an object that uses DESTROY to remove scoped mocks. The layer is identified by reference address (via Scalar::Util::refaddr), so nested scopes are safe regardless of exit order.

You should not need to use this module directly. Instead, use register_mocks_scoped from SimpleMock, which returns a ScopeGuard object.