NAME
App::FileSync::Platform - choose platform workarounds before other modules load
SYNOPSIS
use App::FileSync::Platform; # first, before Sub::Private or Log::Abstraction
DESCRIPTION
B::Hooks::EndOfScope 0.28 releases its XS scope hook with an access violation (0xC0000005) on Perl 5.42 for Windows, after a command has done its work but before the interpreter exits, so a run that synced everything would still exit nonzero. Its plain-Perl hook does not fault. The implementation is fixed when B::Hooks::EndOfScope first loads, so this module makes the choice in a BEGIN block and is the first thing every App::FileSync module loads.
FUNCTIONS
wants_plain_end_of_scope_hook
Purpose: decide whether an interpreter needs the plain-Perl end-of-scope hook.
Args: $os (as $^O), $version (as $]).
Returns: 1 for MSWin32 with a 5.42.x interpreter, otherwise 0.
Side Effects: none.
Usage:
App::FileSync::Platform::wants_plain_end_of_scope_hook('MSWin32', 5.042003); # 1
EXAMPLE
print App::FileSync::Platform::wants_plain_end_of_scope_hook($^O, $]) ? "PP\n" : "XS\n";
API SPECIFICATION
INPUT
[
{ name => 'os', type => 'string', optional => 1 },
{ name => 'version', type => 'string', optional => 1 },
]
OUTPUT
{ type => 'integer', min => 0, max => 1 }
MESSAGES
None.
FORMAL SPECIFICATION
wants : OS × VERSION → 𝔹
wants(os, v) ⇔ os = MSWin32 ∧ v ∈ ℚ ∧ 5.042 ≤ v < 5.043
use_plain_end_of_scope_hook
Purpose: select the plain-Perl hook for an interpreter that needs it.
Args: $os, $version, as for "wants_plain_end_of_scope_hook".
Returns: 1 when the environment variable was set, 0 when it was left alone.
Side Effects: may set $ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION} to PP. An implementation already named in the environment always wins.
Usage:
App::FileSync::Platform::use_plain_end_of_scope_hook($^O, $]);
EXAMPLE
local $ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION};
App::FileSync::Platform::use_plain_end_of_scope_hook('MSWin32', 5.042003);
print "$ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION}\n"; # PP
API SPECIFICATION
INPUT
[
{ name => 'os', type => 'string', optional => 1 },
{ name => 'version', type => 'string', optional => 1 },
]
OUTPUT
{ type => 'integer', min => 0, max => 1 }
MESSAGES
None.
FORMAL SPECIFICATION
ΔENV
os? : OS ; v? : VERSION ; r! : 𝔹
r! ⇔ B_HOOKS ¬in; dom ENV ∧ wants(os?, v?)
r! ⇒ ENV' = ENV ⊕ {B_HOOKS ↦ PP}
¬r! ⇒ ENV' = ENV
LIMITATIONS
The choice only helps when this module is loaded before B::Hooks::EndOfScope. Code outside this distribution that loads namespace::clean, Sub::Private or Log::Abstraction first gets whichever implementation was already chosen.
AUTHOR
Nigel Horne, <njh at nigelhorne.com>
LICENCE AND COPYRIGHT
Copyright 2026 Nigel Horne.
Usage is subject to the GPL2 licence terms. If you use it, please let me know.