blib/lib/App/FileSync/Platform.pm

filter: Statementstmt 100% 18 / 18 Branchbran 100% 6 / 6 Conditioncond 100% 18 / 18 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 100% 58 / 58 CC 10 SCAR 15.3
CC
10
Cov
100%
wants_plain_end_of_scope_hook
7.0
use_plain_end_of_scope_hook
4.0
BEGIN
1.0
CRAP 4.6
« blib/lib/App/FileSync/Delta.pm ↑ Summary blib/lib/App/FileSync/Protocol.pm »
1 package App::FileSync::Platform;
2  
3 # Deliberately dependency-free, and loaded first by every module that uses
4 # Sub::Private: the end-of-scope hook implementation has to be chosen before
5 # anything loads B::Hooks::EndOfScope, and Sub::Private loads it at compile time.
6  
7 342 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 342 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 342 ▶use version; our $VERSION = version->declare('0.002.1');
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =encoding utf8
13  
14 =head1 NAME
15  
16 App::FileSync::Platform - choose platform workarounds before other modules load
17  
18 =head1 SYNOPSIS
19  
20 use App::FileSync::Platform; # first, before Sub::Private or Log::Abstraction
21  
22 =head1 DESCRIPTION
23  
24 B::Hooks::EndOfScope 0.28 releases its XS scope hook with an access violation
25 (0xC0000005) on Perl 5.42 for Windows, after a command has done its work but
26 before the interpreter exits, so a run that synced everything would still exit
27 nonzero. Its plain-Perl hook does not fault. The implementation is fixed when
28 B::Hooks::EndOfScope first loads, so this module makes the choice in a BEGIN
29 block and is the first thing every App::FileSync module loads.
30  
31 =head1 FUNCTIONS
32  
33 =head2 wants_plain_end_of_scope_hook
34  
35 Purpose: decide whether an interpreter needs the plain-Perl end-of-scope hook.
36  
37 Args: C<$os> (as C<$^O>), C<$version> (as C<$]>).
38  
39 Returns: 1 for MSWin32 with a 5.42.x interpreter, otherwise 0.
40  
41 Side Effects: none.
42  
43 Usage:
44  
45 App::FileSync::Platform::wants_plain_end_of_scope_hook('MSWin32', 5.042003); # 1
46  
47 =head3 EXAMPLE
48  
49 print App::FileSync::Platform::wants_plain_end_of_scope_hook($^O, $]) ? "PP\n" : "XS\n";
50  
51 =head3 API SPECIFICATION
52  
53 =head4 INPUT
54  
55 [
56 { name => 'os', type => 'string', optional => 1 },
57 { name => 'version', type => 'string', optional => 1 },
58 ]
59  
60 =head4 OUTPUT
61  
62 { type => 'integer', min => 0, max => 1 }
63  
64 =head3 MESSAGES
65  
66 None.
67  
68 =head3 FORMAL SPECIFICATION
69  
70 wants : OS Γ— VERSION β†’ 𝔹
71 wants(os, v) ⇔ os = MSWin32 ∧ v ∈ β„š ∧ 5.042 ≀ v < 5.043
72  
73 =cut
74  
75 352 ▶sub wants_plain_end_of_scope_hook {
Subroutine wants_plain_end_of_scope_hook: called CC=7 SCAR=19.5
Pod documented
76 352 my ($os, $version) = @_;
77  
78 # 5.42.x only: later releases may not share the fault, and forcing an
79 # implementation a later B::Hooks::EndOfScope no longer ships would refuse
80 # to load.
81 352 ▶ return (defined $os && $os eq 'MSWin32'
Branch: 1 branch
BranchTrueFalseTotal
defined $os && $os eq 'MSWin32' && defined $version && $version =~ /\A[0-9.]+\z/ && $version >= 5.042 && $version < 5.043 ? : 3 349 352
Condition100%15/15
defined $os and $os eq "MSWin32" and defined $version and $version =~ /\A[0-9.]+\z/ and $version >= "5.042" and $version < "5.043"
!ll&&!rl&&r
34813
defined $os and $os eq "MSWin32" and defined $version and $version =~ /\A[0-9.]+\z/ and $version >= "5.042"
!ll&&!rl&&r
34624
defined $os and $os eq "MSWin32" and defined $version and $version =~ /\A[0-9.]+\z/
!ll&&!rl&&r
34516
defined $os and $os eq "MSWin32" and defined $version
!ll&&!rl&&r
34417
defined $os and $os eq "MSWin32"
!ll&&!rl&&r
13438
MC/DC100%6/6
defined $os and $os eq "MSWin32" and defined $version and $version =~ /\A[0-9.]+\z/ and $version >= "5.042" and $version < "5.043"
defined $os $os eq "MSWin32" defined $version $version =~ /\A[0-9.]+\z/ $version >= "5.042" $version < "5.043"
Truth table100%7/7
A and B and C and D and E and F
A= defined $osB= $os eq "MSWin32"C= defined $versionD= $version =~ /\A[0-9.]+\z/E= $version >= "5.042"F= $version < "5.043"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
82 && defined $version && $version =~ /\A[0-9.]+\z/
83 && $version >= 5.042 && $version < 5.043) ? 1 : 0;
84 }
85  
86 =head2 use_plain_end_of_scope_hook
87  
88 Purpose: select the plain-Perl hook for an interpreter that needs it.
89  
90 Args: C<$os>, C<$version>, as for L</wants_plain_end_of_scope_hook>.
91  
92 Returns: 1 when the environment variable was set, 0 when it was left alone.
93  
94 Side Effects: may set C<$ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION}> to C<PP>. An
95 implementation already named in the environment always wins.
96  
97 Usage:
98  
99 App::FileSync::Platform::use_plain_end_of_scope_hook($^O, $]);
100  
101 =head3 EXAMPLE
102  
103 local $ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION};
104 App::FileSync::Platform::use_plain_end_of_scope_hook('MSWin32', 5.042003);
105 print "$ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION}\n"; # PP
106  
107 =head3 API SPECIFICATION
108  
109 =head4 INPUT
110  
111 [
112 { name => 'os', type => 'string', optional => 1 },
113 { name => 'version', type => 'string', optional => 1 },
114 ]
115  
116 =head4 OUTPUT
117  
118 { type => 'integer', min => 0, max => 1 }
119  
120 =head3 MESSAGES
121  
122 None.
123  
124 =head3 FORMAL SPECIFICATION
125  
126 Ξ”ENV
127 os? : OS ; v? : VERSION ; r! : 𝔹
128 r! ⇔ B_HOOKS βˆ‰ dom ENV ∧ wants(os?, v?)
129 r! β‡’ ENV' = ENV βŠ• {B_HOOKS ↦ PP}
130 Β¬r! β‡’ ENV' = ENV
131  
132 =cut
133  
134 344 ▶sub use_plain_end_of_scope_hook {
Subroutine use_plain_end_of_scope_hook: called CC=4 SCAR=13.9
Pod documented
135 344 my ($os, $version) = @_;
136  
137 my $set = (!defined $ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION}
138 344 ▶ && wants_plain_end_of_scope_hook($os, $version)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!defined($ENV{'B_HOOKS_ENDOFSCOPE_IMPLEMENTATION'}) && wants_plain_end_of_scope_hook($os, $version) ? : 1 343 344
Condition100%3/3
not defined $ENV{"B_HOOKS_ENDOFSCOPE_IMPLEMENTATION"} and wants_plain_end_of_scope_hook($os, $version)
!ll&&!rl&&r
13421
MC/DC100%2/2
not defined $ENV{"B_HOOKS_ENDOFSCOPE_IMPLEMENTATION"} and wants_plain_end_of_scope_hook($os, $version)
not defined $ENV{"B_HOOKS_ENDOFSCOPE_IMPLEMENTATION"} wants_plain_end_of_scope_hook($os, $version)
Truth table100%3/3
not(A) and B
A= not defined $ENV{"B_HOOKS_ENDOFSCOPE_IMPLEMENTATION"}B= wants_plain_end_of_scope_hook($os, $version)
ABresult
0X0
100
111
139 344 ▶ $ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION} = 'PP' if $set;
Branch: 1 branch
BranchTrueFalseTotal
if $set 1 343 344
140  
141 344 return $set;
142 }
143  
144 342 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
145 342 use_plain_end_of_scope_hook($^O, $]);
146 }
147  
148 342 1;
149  
150 __END__
« blib/lib/App/FileSync/Delta.pm ↑ Summary blib/lib/App/FileSync/Protocol.pm »