This software allows users to execute code after a subroutine call while maintaining the appropriate context, as if the subroutine was the final statement in the calling function.
To address this problem, Context::Preserve automates the process of calling the function in the correct context. With this module, you provide a coderef for the original function and another for the function to run after the original function. The module preserves the context the original function would have seen if it were the last statement in the caller.
The syntax becomes much simpler with Context::Preserve. Instead of having to type out the various code paths for each context, you can now use the preserve_context function like this:
use Context::Preserve;
return preserve_context { some::code() } after => sub { $_ += 42 for @_ };
Wantarray is correct inside both coderefs, with the return value ignored in the after coderef. The value returned for wantarray is related to the context in which the original function was called. This module makes it much easier to manage contexts when calling functions and modifying their results.
Version 0.01: N/A