sanity.pm

filter: Statementstmt 79.1% 190 / 240 Branchbran 61.9% 78 / 126 Conditioncond 28.0% 7 / 25 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 86.2% 25 / 29 Podpod 0.0% 0 / 9 totaltotal 67.7% 300 / 443 CC 74 SCAR 30.4
CC
74
Cov
70%
unimport
42.0
load_pragma
31.8
encode_pragmahash
30.0
CRAP 20.9
« sanity/BaseCalc.pm ↑ Summary
1 package sanity;
2  
3 2 our $AUTHORITY = 'cpan:BBYRD'; # AUTHORITY
4 2 our $VERSION = '1.03'; # VERSION
5 # ABSTRACT: The ONLY meta pragma you'll ever need!
6  
7 # use feature has to be difficult...
8 2 our $VER_PACK;
9 2 ▶BEGIN { $VER_PACK = sprintf(":%vd", $^V); }
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Eat our own dog food
12 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use strict qw(subs vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 #use feature ($VER_PACK);
16 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶no if $] >= 5.017011, warnings => 'experimental::smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # Need this for some of the bit math
21 2 ▶use bigint; ### LAZY: I should probably be using Math::BigInt... ###
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use sanity::BaseCalc; ### FIXME: Temporary until Math::BaseCalc fix (RT #77198) ###
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 2 ▶use List::MoreUtils qw(any all none uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # Useful for importing modules, including stuff like Carp and its exports
27 2 ▶use Import::Into v1.1.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 2 my $base90 = [0..9, 'A'..'Z', 'a'..'z', split(//, '#$%&()*+.,-/:;<=>?@[]^_`{|}~')]; # no !, ', ", or \
30 my $base48900 = [
31 @$base90,
32 # see printuni.pl for details
33 2 map { chr } (
34 0xa2..0xac, 0xae..0x2e9, 0x2ec..0x2ff, 0x370..0x377, 0x37a..0x37e, 0x384..0x38a, 0x38c, 0x38e..0x3a1, 0x3a3..0x3e1,
35 0x3f0..0x482, 0x48a..0x513, 0x531..0x556, 0x559..0x55f, 0x561..0x587, 0x589, 0x58a, 0x5be, 0x5c0,
36 0x5c3, 0x5c6, 0x5d0..0x5ea, 0x5f0..0x5f4, 0x606..0x60f, 0x61b, 0x61e..0x64a, 0x660..0x66f,
37 0x671..0x6d5, 0x6de, 0x6e5, 0x6e6, 0x6e9, 0x6ee..0x70d, 0x710, 0x712..0x72f, 0x74d..0x7b1,
38 0x7c0..0x7ea, 0x7f4..0x7fa, 0x900..0x902, 0x904..0x93a, 0x93d, 0x941..0x948, 0x950, 0x955..0x977,
39 0x979..0x97f, 0x981, 0x985..0x98c, 0x98f, 0x990, 0x993..0x9a8, 0x9aa..0x9b0, 0x9b2, 0x9b6..0x9b9,
40 0x9bd, 0x9c1..0x9c4, 0x9ce, 0x9dc, 0x9dd, 0x9df..0x9e3, 0x9e6..0x9fb, 0xa01, 0xa02, 0xa05..0xa0a,
41 0xa0f, 0xa10, 0xa13..0xa28, 0xa2a..0xa30, 0xa32, 0xa33, 0xa35, 0xa36, 0xa38, 0xa39, 0xa41, 0xa42, 0xa47, 0xa48,
42 0xa4b, 0xa4c, 0xa51, 0xa59..0xa5c, 0xa5e, 0xa66..0xa75, 0xa81, 0xa82, 0xa85..0xa8d, 0xa8f..0xa91,
43 0xa93..0xaa8, 0xaaa..0xab0, 0xab2, 0xab3, 0xab5..0xab9, 0xabd, 0xac1..0xac5, 0xac7, 0xac8, 0xad0,
44 0xae0..0xae3, 0xae6..0xaef, 0xaf1, 0xb01, 0xb05..0xb0c, 0xb0f, 0xb10, 0xb13..0xb28, 0xb2a..0xb30,
45 0xb32, 0xb33, 0xb35..0xb39, 0xb3d, 0xb3f, 0xb41..0xb44, 0xb56, 0xb5c, 0xb5d, 0xb5f..0xb63,
46 0xb66..0xb77, 0xb82, 0xb83, 0xb85..0xb8a, 0xb8e..0xb90, 0xb92..0xb95, 0xb99, 0xb9a, 0xb9c, 0xb9e, 0xb9f,
47 0xba3, 0xba4, 0xba8..0xbaa, 0xbae..0xbb9, 0xbc0, 0xbd0, 0xbe6..0xbfa, 0xc05..0xc0c, 0xc0e..0xc10,
48 0xc12..0xc28, 0xc2a..0xc33, 0xc35..0xc39, 0xc3d..0xc40, 0xc46..0xc48, 0xc4a..0xc4c, 0xc58, 0xc59, 0xc60..0xc63,
49 0xc66..0xc6f, 0xc78..0xc7f, 0xc85..0xc8c, 0xc8e..0xc90, 0xc92..0xca8, 0xcaa..0xcb3, 0xcb5..0xcb9, 0xcbd,
50 0xcbf, 0xcc6, 0xccc, 0xcde, 0xce0..0xce3, 0xce6..0xcef, 0xcf1, 0xcf2, 0xd05..0xd0c,
51 0xd0e..0xd10, 0xd12..0xd3a, 0xd3d, 0xd41..0xd44, 0xd4e, 0xd60..0xd63, 0xd66..0xd75, 0xd79..0xd7f,
52 0xd85..0xd96, 0xd9a..0xdb1, 0xdb3..0xdbb, 0xdbd, 0xdc0..0xdc6, 0xdd2..0xdd4, 0xdd6, 0xdf4,
53 0xe01..0xe37, 0xe3f..0xe47, 0xe4c..0xe5b, 0xe81, 0xe82, 0xe84, 0xe87, 0xe88, 0xe8a, 0xe8d,
54 0xe94..0xe97, 0xe99..0xe9f, 0xea1..0xea3, 0xea5, 0xea7, 0xeaa, 0xeab, 0xead..0xeb7, 0xebb..0xebd,
55 0xec0..0xec4, 0xec6, 0xecc, 0xecd, 0xed0..0xed9, 0xedc, 0xedd, 0xf00..0xf17, 0xf1a..0xf34, 0xf36,
56 0xf38, 0xf3a..0xf3d, 0xf40..0xf47, 0xf49..0xf6c, 0xf73, 0xf75..0xf79, 0xf7e, 0xf81,
57 0xf85, 0xf88..0xf97, 0xf99..0xfbc, 0xfbe..0xfc5, 0xfc7..0xfcc, 0xfce..0xfda, 0x10fb, 0x1100..0x115e,
58 0x1161..0x1248, 0x124a..0x124d, 0x1250..0x1256, 0x1258, 0x125a..0x125d, 0x1260..0x1288, 0x128a..0x128d, 0x1290..0x12b0,
59 0x12b2..0x12b5, 0x12b8..0x12be, 0x12c0, 0x12c2..0x12c5, 0x12c8..0x12d6, 0x12d8..0x1310, 0x1312..0x1315, 0x1318..0x135a,
60 0x1360..0x137c, 0x1380..0x1399, 0x13a0..0x13f4, 0x1400..0x167f, 0x1681..0x169c, 0x16a0..0x16f0, 0x1735, 0x1736, 0x1780..0x17b3,
61 0x17b7..0x17bd, 0x17c6, 0x17c9..0x17d1, 0x17d3..0x17dc, 0x17e0..0x17e9, 0x17f0..0x17f9, 0x1800..0x180d, 0x1810..0x1819,
62 0x1820..0x1877, 0x1880..0x18a8, 0x18aa, 0x1950..0x196d, 0x1970..0x1974, 0x1980..0x19ab, 0x19c1..0x19c7, 0x19d0..0x19da,
63 0x19de..0x19ff, 0x1d00..0x1dbf, 0x1e00..0x1f15, 0x1f18..0x1f1d, 0x1f20..0x1f45, 0x1f48..0x1f4d, 0x1f50..0x1f57, 0x1f59,
64 0x1f5b, 0x1f5d, 0x1f5f..0x1f7d, 0x1f80..0x1fb4, 0x1fb6..0x1fc4, 0x1fc6..0x1fd3, 0x1fd6..0x1fdb, 0x1fdd..0x1fef,
65 0x1ff2..0x1ff4, 0x1ff6..0x1ffe, 0x2010..0x2027, 0x2030..0x205e, 0x2070, 0x2071, 0x2074..0x208e, 0x2090..0x209c, 0x20a0..0x20b9,
66 0x2100..0x2189, 0x2190..0x22bf, 0x2500..0x257f, 0x25a0..0x266f, 0x2701..0x27bf, 0x2800..0x28ff, 0x2c60..0x2c7f, 0x2d30..0x2d65,
67 0x2d6f, 0x2d70, 0x2d80..0x2d96, 0x2da0..0x2da6, 0x2da8..0x2dae, 0x2db0..0x2db6, 0x2db8..0x2dbe, 0x2dc0..0x2dc6, 0x2dc8..0x2dce,
68 0x2dd0..0x2dd6, 0x2dd8..0x2dde, 0x2e80..0x2e99, 0x2e9b..0x2ef3, 0x2ff0..0x2ffb, 0x3001..0x3029, 0x3030..0x303f, 0x3041..0x3096,
69 0x309b..0x30ff, 0x3131..0x3163, 0x3165..0x318e, 0x3190..0x319f, 0x31c0..0x31e3, 0x31f0..0x321e, 0x3220..0x32fe, 0x3300..0x4db5,
70 0x4e00..0x9fcb, 0xa000..0xa48c, 0xa490..0xa4c6, 0xa500..0xa62b, 0xa840..0xa877, 0xac00..0xd7a3, 0xf900..0xfa2d, 0xfa30..0xfa6d,
71 0xfa70..0xfad9, 0xfb00..0xfb06, 0xfb13..0xfb17, 0xfb1d, 0xfb1f..0xfb36, 0xfb38..0xfb3c, 0xfb3e, 0xfb40, 0xfb41,
72 0xfb43, 0xfb44, 0xfb46..0xfb4f, 0xfe10..0xfe19, 0xfe30..0xfe52, 0xfe54..0xfe66, 0xfe68..0xfe6b, 0xff01..0xff9f, 0xffa1..0xffbe,
73 0xffc2..0xffc7, 0xffca..0xffcf, 0xffd2..0xffd7, 0xffda..0xffdc, 0xffe0..0xffe6, 0xffe8..0xffee,
74 )
75 ];
76 2 my $calc90 = sanity::BaseCalc->new(digits => $base90);
77 2 my $calc48900 = sanity::BaseCalc->new(digits => $base48900);
78  
79 2 my @FLAGS = (
80 # Perl.h HINTS (Bits 0-31)
81 # (matches ordering of $^H)
82 qw(
83 integer
84 strict/refs
85 locale
86 bytes
87 XXX:ARRAY_BASE
88 XXX:V_VMSISH1
89 XXX:V_VMSISH2
90 XXX:V_VMSISH3
91 XXX:BLOCK_SCOPE
92 strict/subs
93 strict/vars
94 feature/HINT/unicode
95 XXX:overload/integer
96 XXX:overload/float
97 XXX:overload/binary
98 XXX:overload/q
99 XXX:overload/qr
100 XXX:LOCALIZE_HH
101 XXX:LEXICAL_IO_IN
102 XXX:LEXICAL_IO_OUT
103 re/taint
104 re/eval
105 filetest
106 utf8
107 NO:overloading
108 XXX:RE_FLAGS
109 XXX:FEATURE_BIT1
110 XXX:FEATURE_BIT2
111 XXX:FEATURE_BIT3
112 XXX:HINT_0x20000000
113 XXX:HINT_0x40000000
114 XXX:HINT_0x80000000
115 ),
116  
117 # warnings.pm (Bits 32-160)
118 # (matches REVERSE ordering of $^{WARNING_BITS} << 32)
119 qw(
120 MULTI:warnings/all MULTI:warnings/all/FATAL
121 warnings/closure MULTI:warnings/closure/FATAL
122 warnings/deprecated MULTI:warnings/deprecated/FATAL
123 warnings/exiting MULTI:warnings/exiting/FATAL
124 warnings/glob MULTI:warnings/glob/FATAL
125 MULTI:warnings/io MULTI:warnings/io/FATAL
126 warnings/closed MULTI:warnings/closed/FATAL
127 warnings/exec MULTI:warnings/exec/FATAL
128 warnings/layer MULTI:warnings/layer/FATAL
129 warnings/newline MULTI:warnings/newline/FATAL
130 warnings/pipe MULTI:warnings/pipe/FATAL
131 warnings/unopened MULTI:warnings/unopened/FATAL
132 warnings/misc MULTI:warnings/misc/FATAL
133 warnings/numeric MULTI:warnings/numeric/FATAL
134 warnings/once MULTI:warnings/once/FATAL
135 warnings/overflow MULTI:warnings/overflow/FATAL
136 warnings/pack MULTI:warnings/pack/FATAL
137 warnings/portable MULTI:warnings/portable/FATAL
138 warnings/recursion MULTI:warnings/recursion/FATAL
139 warnings/redefine MULTI:warnings/redefine/FATAL
140 warnings/regexp MULTI:warnings/regexp/FATAL
141 MULTI:warnings/severe MULTI:warnings/severe/FATAL
142 warnings/debugging MULTI:warnings/debugging/FATAL
143 warnings/inplace MULTI:warnings/inplace/FATAL
144 warnings/internal MULTI:warnings/internal/FATAL
145 warnings/malloc MULTI:warnings/malloc/FATAL
146 warnings/signal MULTI:warnings/signal/FATAL
147 warnings/substr MULTI:warnings/substr/FATAL
148 MULTI:warnings/syntax MULTI:warnings/syntax/FATAL
149 warnings/ambiguous MULTI:warnings/ambiguous/FATAL
150 warnings/bareword MULTI:warnings/bareword/FATAL
151 warnings/digit MULTI:warnings/digit/FATAL
152 warnings/parenthesis MULTI:warnings/parenthesis/FATAL
153 warnings/precedence MULTI:warnings/precedence/FATAL
154 warnings/printf MULTI:warnings/printf/FATAL
155 warnings/prototype MULTI:warnings/prototype/FATAL
156 warnings/qw MULTI:warnings/qw/FATAL
157 warnings/reserved MULTI:warnings/reserved/FATAL
158 warnings/semicolon MULTI:warnings/semicolon/FATAL
159 warnings/taint MULTI:warnings/taint/FATAL
160 warnings/threads MULTI:warnings/threads/FATAL
161 warnings/uninitialized MULTI:warnings/uninitialized/FATAL
162 warnings/unpack MULTI:warnings/unpack/FATAL
163 warnings/untie MULTI:warnings/untie/FATAL
164 MULTI:warnings/utf8 MULTI:warnings/utf8/FATAL
165 warnings/void MULTI:warnings/void/FATAL
166 warnings/imprecision MULTI:warnings/imprecision/FATAL
167 warnings/illegalproto MULTI:warnings/illegalproto/FATAL
168 warnings/non_unicode MULTI:warnings/non_unicode/FATAL
169 warnings/nonchar MULTI:warnings/nonchar/FATAL
170 warnings/surrogate MULTI:warnings/surrogate/FATAL
171 MULTI:warnings/experimental MULTI:warnings/experimental/FATAL
172 warnings/experimental::lexical_subs MULTI:warnings/experimental::lexical_subs/FATAL
173 warnings/experimental::lexical_topic MULTI:warnings/experimental::lexical_topic/FATAL
174 warnings/experimental::regex_sets MULTI:warnings/experimental::regex_sets/FATAL
175 warnings/experimental::smartmatch MULTI:warnings/experimental::smartmatch/FATAL
176 warnings/experimental::autoderef MULTI:warnings/experimental::autoderef/FATAL
177 warnings/experimental::postderef MULTI:warnings/experimental::postderef/FATAL
178 warnings/experimental::signatures MULTI:warnings/experimental::signatures/FATAL
179 warnings/syscalls MULTI:warnings/syscalls/FATAL
180 XXX:warnings/60 XXX:warnings/60/FATAL
181 XXX:warnings/61 XXX:warnings/61/FATAL
182 XXX:warnings/62 XXX:warnings/62/FATAL
183 XXX:warnings/63 XXX:warnings/63/FATAL
184 ),
185  
186 # feature (Bits 161-176)
187 qw(
188 feature/^V
189 feature/switch
190 feature/say
191 feature/state
192 MULTI:feature/unicode
193 feature/fc
194 feature/evalbytes
195 feature/array_base
196 feature/current_sub
197 feature/lexical_subs
198 feature/unicode_eval
199 feature/signatures
200 feature/postderef
201 feature/postderef_qq
202 feature/current_sub
203 XXX:feature/15
204 ),
205  
206 ### TODO: Might need move this set to the bottom and add some extra bitmap bits after Perl 5.23
207  
208 # Perl versions (Bits 177-184)
209 # (MAJOR-8)*16 + MINOR + 1 = 8-bit bitmap
210 qw(
211 BITMAP:perl/0
212 BITMAP:perl/1
213 BITMAP:perl/2
214 BITMAP:perl/3
215 BITMAP:perl/4
216 BITMAP:perl/5
217 BITMAP:perl/6
218 BITMAP:perl/7
219 ),
220  
221 # Autodie (Bits 185-200)
222 # Will expand if requested, but I don't want to waste
223 # all of that bit space right now.
224 qw(
225 MULTI:autodie/io
226 autodie/dbm
227 autodie/file
228 autodie/filesys
229 MULTI:autodie/ipc
230 autodie/msg
231 autodie/semaphore
232 autodie/shm
233 autodie/socket
234 autodie/threads
235 autodie/system
236 XXX:autodie/11
237 XXX:autodie/12
238 XXX:autodie/13
239 XXX:autodie/14
240 XXX:autodie/15
241 ),
242  
243 # Other CORE pragmas (Bits 201-216)
244 qw(
245 bigint
246 bignum
247 bigrat
248 charnames
249 charnames/short
250 charnames/full
251 encoding::warnings
252 encoding::warnings/FATAL
253 mro/dfs
254 mro/c3
255 open/crlf
256 open/bytes
257 open/utf8
258 open/locale
259 open/std
260 XXX:CORE/15
261 ),
262  
263 # Other pragmas (Bits 217-247 and beyond)
264 qw(
265 NO:autovivification/fetch
266 NO:autovivification/exists
267 NO:autovivification/delete
268 NO:autovivification/store
269 NO:autovivification/warn
270 NO:autovivification/strict
271 NO:indirect
272 NO:indirect/global
273 NO:indirect/fatal
274 NO:multidimensional
275 NO:bareword::filehandles
276 namespace::clean
277 namespace::autoclean
278 namespace::sweep
279 namespace::functions
280 subs::auto
281 utf8::all
282 IO::File
283 IO::Handle
284 IO::All
285 Carp
286 BITMAP:criticism/0
287 BITMAP:criticism/1
288 BITMAP:criticism/2
289 vendorlib
290 true
291 autolocale
292 perl5i::0
293 perl5i::1
294 perl5i::2
295 perl5i::3
296 perl5i::latest
297 Toolkit
298 ),
299 # new adds
300 qw(
301 Function::Parameters
302 Function::Parameters/strict
303 Switch::Plain
304 Quote::Code
305 ),
306 );
307 2 my %FLAGS; # namespace abuse I know...
308 2 $FLAGS{$FLAGS[$_]} = $_ for (0 .. $#FLAGS);
309  
310 my %ALIAS = (
311 strict => [qw(strict/refs strict/subs strict/vars)],
312  
313 # See corpus/warnbits.pl for the bitwise math
314 'warnings/all' => '1902996923607946508077714625932660180412006400', # 0x55555555555555555555555555555500
315 'warnings/all/FATAL' => '5708990770823839524233143877797980541236019200', # 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
316 'warnings/io' => '1427247692705959881058285969473512868379885568', # 0x00545500000000000000000000004000
317 'warnings/io/FATAL' => '4281743078117879643174857908420538605139656704', # 0x00FCFF0000000000000000000000C000
318 'warnings/severe' => '6441307882634196071481344', # 0x00000000005405000000000000000000
319 'warnings/severe/FATAL' => '19323923647902588214444032', # 0x0000000000FC0F000000000000000000
320 'warnings/syntax' => '85071024421536332098205581043061227520', # 0x00000000000000555515004000000000
321 'warnings/syntax/FATAL' => '170142481534374380428773091271241629696', # 0x00000000000000FFFF3F008000000000
322 'warnings/utf8' => '7147258933335492648603770563127412785152', # 0x00000000000000000000000115000000
323 'warnings/utf8/FATAL' => '21441776800006477945811311689382238355456', # 0x0000000000000000000000033F000000
324 'warnings/experimental' => '475741971544825646998874771158206501072404480', # 0x00000000000000000000000040551500
325 'warnings/experimental/FATAL' => '1427225914634476940996624313474619503217213440', # 0x000000000000000000000000C0FF3F00
326 'warnings' => 'warnings/all',
327 'warnings/FATAL' => 'warnings/all/FATAL',
328  
329 # XXX: 5.18 has array_base and they "backported" it to older versions.
330 # We don't use it, but that's not totally accurate of the feature_bundles.
331 # It's a barely used $[ variable, anyway...
332  
333 'feature/unicode' => [qw(MULTI:feature/unicode feature/HINT/unicode)],
334 'feature/unicode_strings' => 'feature/unicode',
335 'feature/5.9.5' => 'feature/5.10',
336 6 'feature/5.10' => [map { "feature/$_" } qw(say state switch)], # 5.18 has array_base, but not in 5.10's version
337 4 'feature/5.11' => [map { "feature/$_" } qw(5.10 unicode)],
338 'feature/5.12' => 'feature/5.11',
339 'feature/5.13' => 'feature/5.11',
340 'feature/5.14' => 'feature/5.11',
341 16 'feature/5.15' => [map { "feature/$_" } qw(current_sub evalbytes fc say state switch unicode_eval unicode_strings)],
342 'feature/5.16' => 'feature/5.15',
343 'feature/5.17' => 'feature/5.15',
344 'feature/5.18' => 'feature/5.15',
345 'feature/5.19' => 'feature/5.15',
346 'feature/5.20' => 'feature/5.15',
347 'feature/5.21' => 'feature/5.15',
348 feature => 'feature/^V',
349  
350 'autodie/ipc' => [qw(MULTI:autodie/ipc autodie/msg autodie/semaphore autodie/shm)],
351 'autodie/io' => [qw(MULTI:autodie/io autodie/dbm autodie/file autodie/filesys autodie/ipc autodie/socket)],
352 'autodie/default' => [qw(autodie/io autodie/threads)],
353 'autodie/all' => [qw(autodie/default autodie/system)],
354 autodie => 'autodie/default',
355  
356 mro => 'mro/dfs',
357 6 'NO:autovivification' => [map { 'NO:autovivification/'.$_ } qw(fetch exists delete)],
358  
359 4 'criticism/gentle' => [map { 'BITMAP:criticism/'.$_ } qw(0 2)],
360 'criticism/stern' => 'BITMAP:criticism/2',
361 4 'criticism/harsh' => [map { 'BITMAP:criticism/'.$_ } qw(0 1)],
362 'criticism/cruel' => 'BITMAP:criticism/1',
363 'criticism/brutal' => 'BITMAP:criticism/0',
364 criticism => 'criticism/gentle',
365  
366 # mimicry of other "meta pragma" modules
367 'ex::caution' => [qw(strict warnings)],
368 'NO:crap' => [qw(strict warnings)],
369 'shit' => [qw(strict warnings)],
370 'latest' => [qw(strict warnings feature)],
371 'sane' => [qw(strict warnings feature utf8)],
372 'NO:nonsense' => [qw(strict warnings true namespace::autoclean)],
373 'Modern::Perl' => [qw(strict warnings mro/dfs feature IO::File IO::Handle)],
374 'strictures' => [qw(v5.8.4 strict warnings/all/FATAL NO:indirect/fatal NO:multidimensional NO:bareword::filehandles)],
375 'uni::perl' => [qw(
376 v5.10 strict feature/5.10
377 ), (
378 54 map { "warnings/$_/FATAL" } qw(closed threads internal debugging pack substr malloc
379 unopened portable prototype inplace io pipe unpack regexp deprecated exiting glob
380 digit printf utf8 layer reserved parenthesis taint closure semicolon)
381 ), qw(
382 -warnings/exec/FATAL
383 -warnings/newline/FATAL
384 utf8
385 open/utf8
386 open/std
387 mro/c3
388 Carp
389 )],
390 'common::sense' => [qw(
391 strict feature/5.10
392 ), (
393 2 map { "warnings/$_/FATAL" } qw(closed threads internal debugging pack malloc
394 portable prototype inplace io pipe unpack deprecated glob digit printf
395 layer reserved taint closure semicolon)
396 ),
397 qw(
398 -warnings/exec/FATAL
399 -warnings/newline/FATAL
400 -warnings/unopened/FATAL
401 utf8
402 )],
403 'sanity' => [qw(
404 v5.10.1 utf8 open/utf8 open/std mro/c3 strict/subs strict/vars feature/5.10
405 warnings/all/FATAL -warnings/uninitialized/FATAL -warnings/experimental::smartmatch/FATAL
406 NO:autovivification NO:autovivification/store NO:autovivification/strict
407 NO:indirect/fatal NO:multidimensional
408 )],
409 'Acme::Very::Modern::Perl' => [qw(Modern::Perl -mro/dfs mro/c3 utf8 open/utf8 open/std common::sense perl5i::latest Toolkit Carp)],
410 );
411  
412 # Implement experimental ALIASes in a similar manner as Leon's code itself
413 2 foreach my $main_pragma (qw[ array_base autoderef lexical_topic postderef regex_sets signatures smartmatch switch ]) {
414 # additional pragmas to enable
415 16 my @pragmas = ($main_pragma);
416 16 ▶ push @pragmas, 'postderef_qq' if $main_pragma eq 'postderef';
Branch: 1 branch
BranchTrueFalseTotal
if $main_pragma eq "postderef" 2 14 16
417 16 ▶ push @pragmas, 'smartmatch' if $main_pragma eq 'switch';
Branch: 1 branch
BranchTrueFalseTotal
if $main_pragma eq "switch" 2 14 16
418  
419 16 my @flags;
420 16 foreach my $pragma (@pragmas) {
421 20 ▶ push @flags, "-warnings/experimental::$pragma" if "warnings/experimental::$pragma" ~~ @FLAGS;
Branch: 1 branch
BranchTrueFalseTotal
if "warnings/experimental::$pragma" ~~ \@FLAGS 14 6 20
422 20 ▶ push @flags, "feature/$pragma" if "feature/$pragma" ~~ @FLAGS;
Branch: 1 branch
BranchTrueFalseTotal
if "feature/$pragma" ~~ \@FLAGS 10 10 20
423 }
424  
425 16 $ALIAS{"experimental/$main_pragma"} = \@flags;
426 }
427  
428 # All FATAL warnings have both bits marked (at least in $^{WARNING_BITS}),
429 # so we'll mimic the same
430 2 foreach my $flag ( grep { qr(^warnings/) } @FLAGS ) {
431 506 $ALIAS{"$flag/FATAL"} = [$flag, "MULTI:$flag/FATAL"];
432 }
433  
434 # These modules are optional. Everything else changes the nature
435 # of how Perl works, or would let you do something that would
436 # normally fatally error.
437 2 my @NON_INSTADIE = (qw(
438 overloading
439 autovivification
440 indirect
441 multidimensional
442 bareword::filehandles
443 criticism
444 ));
445 # (autovivification probably shouldn't be here, since it actually
446 # prevents autoviv, but it's generally used as an author tool.)
447  
448 2 my $author_load_warned;
449 12 ▶sub import {
Subroutine import: called CC=16 SCAR=33.3
450 12 my ($class, @args) = @_;
451  
452 # See if we need to encode a pragma hash
453 12 my $print_hash = find_and_remove(qr/^PRINT_PRAGMA_HASH$/, \@args);
454 # ... or print flags
455 12 my $print_flags = find_and_remove(qr/^PRINT_FLAGS$/, \@args);
456  
457 12 ▶ @args = ($class) unless (@args);
Branch: 1 branch
BranchTrueFalseTotal
unless @args 1 11 12
458 12 ▶ unshift @args, $class if (all { /^-/ } @args); # don't be all negative and such
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &all(sub { /^-/; } , @args) 1 11 12
459 12 @args = filter_args(@args);
460  
461 12 ▶ if ($print_hash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($print_hash) 0 12 12
462 0 binmode STDOUT, ':utf8';
463 0 print "use $class '".encode_pragmahash(\@args, '0')."'; # Overly long decimal version\n";
464 0 print "use $class '".encode_pragmahash(\@args, '!')."'; # Safer ASCII version\n";
465 0 print "use $class '".encode_pragmahash(\@args, '¡')."'; # Shorter UTF8 version\n";
466 ### TODO: should try to resolve back to the closest alias ###
467 0 exit;
468 }
469 12 ▶ if ($print_flags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($print_flags) 0 12 12
470 0 print join("\n", @args)."\n";
471 0 exit;
472 }
473  
474 # Look for every indicator that proves that the user is in the distro directory
475 # and appears to be one of the coders
476 12 ▶ my $author_mode = !!((caller)[1] =~ /^(?:x?t|b?lib)[\/\\]/ && (-d '.git' or -d '.svn'));
Condition33%2/6
(caller)[{sign => '+', value => ['1']}] =~ m(^(?:x?t|b?lib)[/\\]) && (-d '.git' || -d '.svn')
!ll&&!rl&&r
0120
-d ".git" or -d ".svn"
l!l&&r!l&&!r
0012
MC/DC0%0/3
(caller)[{sign => '+', value => ['1']}] =~ m(^(?:x?t|b?lib)[/\\]) && (-d '.git' || -d '.svn')
(caller)[{sign => '+', value => ['1']}] =~ m(^(?:x?t|b?lib)[/\\]) -d ".git" -d ".svn"
Truth table25%1/4
A && B or C
A= (caller)[{sign => '+', value => ['1']}] =~ m(^(?:x?t|b?lib)[/\\])B= -d ".git"C= -d ".svn"
ABCresult
0XX0
1000
11X1
1011
477 $author_mode = 0 if (grep {
478 12 ▶ $ENV{"PERL5_${_}_IS_RUNNING"} || $ENV{"PERL5_${_}_IS_RUNNING_IN_RECURSION"}
Branch: 1 branch
BranchTrueFalseTotal
if grep {$ENV{"PERL5_${_}_IS_RUNNING"} or $ENV{"PERL5_${_}_IS_RUNNING_IN_RECURSION"};} "CPANM", "CPANP", "CPANPLUS", "CPAN" 0 12 12
Condition33%1/3
$ENV{"PERL5_${_}_IS_RUNNING"} || $ENV{"PERL5_${_}_IS_RUNNING_IN_RECURSION"}
l!l&&r!l&&!r
0048
MC/DC0%0/2
$ENV{"PERL5_${_}_IS_RUNNING"} || $ENV{"PERL5_${_}_IS_RUNNING_IN_RECURSION"}
$ENV{"PERL5_${_}_IS_RUNNING"} $ENV{"PERL5_${_}_IS_RUNNING_IN_RECURSION"}
Truth table33%1/3
A || B
A= $ENV{"PERL5_${_}_IS_RUNNING"}B= $ENV{"PERL5_${_}_IS_RUNNING_IN_RECURSION"}
ABresult
1X1
011
000
479 } (qw/CPANM CPANP CPANPLUS CPAN/) );
480  
481 # Process order:
482 # v5.##.##
483 # utf8
484 # mro
485 # strict
486 # warnings
487 # feature
488 # ...anything else...
489 # namespace::clean
490 # namespace::functions (always last)
491 # (If this needs to be changed, let me know and I can reorder it)
492  
493 # Perl version
494 12 ▶ if ( my @perl_version = find_and_remove(qr/^BITMAP:perl\b/, \@args) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@perl_version) = find_and_remove(qr/^BITMAP:perl\b/, \@args)) 3 9 12
495 3 my $bitmap = args2bitmask(@perl_version) >> $FLAGS{'BITMAP:perl/0'};
496 3 my $mj = ($bitmap >> 4) + 8;
497 3 my $mn = $bitmap % 16 - 1;
498  
499 3 ▶ eval "use v5.$mj.$mn";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
500 }
501  
502 12 my @init = find_and_remove(qr/^(?:utf8|mro|strict|warnings|feature)\b/, \@args);
503 12 my @end = find_and_remove(qr/^namespace::(clean|functions)\b/, \@args);
504 12 my @mod_list = uniq map { (/^(?:[A-Z]+\:(?!\:))?([\w\:]+)/)[0] } (@init, sort(@args), @end);
505 12 unshift @args, @init;
506 12 push @args, @end;
507  
508 12 my @failed;
509 12 foreach my $module (@mod_list) {
510 50 my $success = load_pragma('import', find_and_remove(qr/^(?:[A-Z]+\:(?!\:))?$module\b/, \@args) );
511 50 ▶ unless (defined $success) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $success) 0 50 50
512 0 ▶ require $module unless ($module ~~ @NON_INSTADIE); # death by suicide (which prints the proper error msg)
Branch: 1 branch
BranchTrueFalseTotal
unless $module ~~ \@NON_INSTADIE 0 0 0
513 0 push @failed, $module;
514 }
515 }
516  
517 12 ▶ if (@failed and $author_mode and not $author_load_warned++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@failed and $author_mode and not $author_load_warned++) 0 12 12
Condition33%2/6
@failed and $author_mode and not $author_load_warned++
!ll&&!rl&&r
1200
@failed and $author_mode
!ll&&!rl&&r
1200
MC/DC0%0/3
@failed and $author_mode and not $author_load_warned++
@failed $author_mode not $author_load_warned++
Truth table25%1/4
A and B and not(C)
A= @failedB= $author_modeC= not $author_load_warned++
ABCresult
0XX0
10X0
1100
1111
518 0 my $failed = join ' ', @failed;
519 0 warn <<EOE;
520 Detected current environment to be in "author mode" but couldn't load all
521 modules. Missing (author) modules were:
522  
523 $failed
524  
525 You should install these modules via CPAN, but these modules are not
526 required by your users (unless you add them to your META file).
527 EOE
528 }
529 }
530  
531 # This is import with some subtractions and slight changes
532 0 ▶sub unimport {
Subroutine unimport: not called CC=6 SCAR=37.4
533 0 my ($class, @args) = @_;
534  
535 0 ▶ @args = ($class) unless (@args);
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 0 0
536 0 ▶ unshift @args, $class if (all { /^-/ } @args); # don't be all negative and such
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &all(sub { /^-/; } , @args) 0 0 0
537 0 @args = filter_args(@args);
538  
539 # Process order: IN REVERSE!
540 0 my @end = find_and_remove(qr/^(?:utf8|mro|strict|warnings|feature)\b/, \@args);
541 0 my @init = find_and_remove(qr/^namespace::(clean|functions)\b/, \@args);
542 0 my @mod_list = uniq map { (/^(?:[A-Z]+\:(?!\:))?([\w\:]+)/)[0] } (@init, sort(@args), @end);
543 0 unshift @args, @init;
544 0 push @args, @end;
545  
546 0 foreach my $module (@mod_list) {
547 0 my $success = load_pragma('unimport', find_and_remove(qr/^(?:[A-Z]+\:(?!\:))?$module\b/, \@args) );
548 0 ▶ require $module unless (defined $success || $module !~~ @NON_INSTADIE); # death by suicide (which prints the proper error msg)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $success or not $module =~ ~@NON_INSTADIE 0 0 0
Condition0%0/3
defined $success or not $module =~ ~@NON_INSTADIE
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $success or not $module =~ ~@NON_INSTADIE
defined $success not $module =~ ~@NON_INSTADIE
Truth table0%0/3
A or not(B)
A= defined $successB= not $module =~ ~@NON_INSTADIE
ABresult
1X1
011
000
549 }
550 }
551  
552 50 ▶sub load_pragma {
Subroutine load_pragma: called CC=23 SCAR=34.6
Pod undocumented
553 50 my $method = shift;
554 50 ▶ $method = 'import' unless ($method =~ /^(?:un)?import$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $method =~ /^(?:un)?import$/ 0 50 50
555 50 ▶ return 0 unless (@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 50 50
556  
557 # import/unimport called us, so one step back
558 50 my $target = scalar caller(1);
559  
560 50 my ($module, @options);
561 50 foreach my $flag (@_) {
562 832 ($module, my $param) = ($flag =~ qr!^([\w\:]+)(?:/(.+))?!);
563 832 ▶ push @options, $param if ($param);
Branch: 1 branch
BranchTrueFalseTotal
if $param 823 9 832
564 }
565  
566 # handle NO:
567 50 my ($modifier) = ($module =~ s/^([A-Z]+)\:(?!\:)//);
568 50 ▶ $method = 'un'.$method if ($modifier eq 'NO');
Branch: 1 branch
BranchTrueFalseTotal
if $modifier eq "NO" 0 50 50
569 50 $method =~ s/^unun//;
570  
571 # Use import::into / unimport:out_of
572 50 ▶ $method .= '::'.($method =~ /^un/ ? 'out_of' : 'into');
Branch: 1 branch
BranchTrueFalseTotal
$method =~ /^un/ ? : 0 50 50
573  
574 50 ▶ die "Cannot use XXX flag: XXX:$module" if ($modifier eq 'XXX');
Branch: 1 branch
BranchTrueFalseTotal
if $modifier eq "XXX" 0 50 50
575  
576 # Specific exceptions
577  
578 # (:param format for certain modules)
579 50 ▶ @options = map { ":$_" } @options if ($module =~ /^(?:open|indirect|charnames|autodie|Function::Parameters)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $module =~ /^(?:open|indirect|charnames|autodie|Function::Parameters)$/ 6 44 50
580 # ^V = $^V (like feature)
581 50 ▶ @options = map { $_ = ($_ eq '^V') ? $VER_PACK : $_ } @options;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '^V' ? : 4 819 823
582 # remove feature/HINT/unicode
583 50 ▶ @options = grep { !/^HINT\/unicode$/ } @options if ($module eq 'feature');
Branch: 1 branch
BranchTrueFalseTotal
if $module eq "feature" 8 42 50
584 # (adding cleanee to namespace::* modules)
585 50 ▶ if ($module =~ /^namespace::/ and not $module eq 'namespace::functions') {
Branch: 1 branch
BranchTrueFalseTotal
if ($module =~ /^namespace::/ and not $module eq "namespace::functions") 0 50 50
Condition33%1/3
$module =~ /^namespace::/ and not $module eq "namespace::functions"
!ll&&!rl&&r
5000
MC/DC0%0/2
$module =~ /^namespace::/ and not $module eq "namespace::functions"
$module =~ /^namespace::/ not $module eq "namespace::functions"
Truth table33%1/3
A and not(B)
A= $module =~ /^namespace::/B= not $module eq "namespace::functions"
ABresult
0X0
100
111
586 0 @options = (-cleanee => $target);
587 # (add 'meta' to namespace::clean's exceptions)
588 0 ▶ push @options, (-except => 'meta') if ($module eq 'namespace::clean');
Branch: 1 branch
BranchTrueFalseTotal
if $module eq "namespace::clean" 0 0 0
589 }
590 # (handling of FATAL in warnings)
591 50 ▶ if ($module eq 'warnings') {
Branch: 1 branch
BranchTrueFalseTotal
if ($module eq "warnings") 10 40 50
592 # separate out FATAL and non-FATAL options
593 10 my $options = [@options];
594 10 my @fatal = map { s|/FATAL$||; $_ } find_and_remove(qr|/FATAL$|, $options);
595 10 my @nonfatal = notin(\@fatal, $options);
596  
597 # To prevent "Unknown warnings category" errors for various versions of Perl,
598 # we'll need to remove the ones that don't exist in the current version.
599  
600 # (also remove the combo flags while we're at it...)
601 10 my @combos = grep { /^MULTI:warnings\/\w+$/ } @FLAGS;
602 10 @combos = map { s|MULTI:warnings/||; $_ } @combos;
603  
604 10 my @warn_categories = keys %warnings::Offsets;
605 10 @fatal = notin(\@combos, [ foundin(\@warn_categories, \@fatal) ]);
606 10 @nonfatal = notin(\@combos, [ foundin(\@warn_categories, \@nonfatal) ]);
607  
608 # if this is an import, first clean all warnings
609 10 warnings->unimport::out_of($target);
610  
611 # warnings can handle both in one import, so let's do it that way
612 10 @options = ();
613 10 ▶ push(@options, FATAL => @fatal) if (@fatal);
Branch: 1 branch
BranchTrueFalseTotal
if @fatal 4 6 10
614 10 ▶ push(@options, NONFATAL => @nonfatal) if (@nonfatal);
Branch: 1 branch
BranchTrueFalseTotal
if @nonfatal 6 4 10
615 }
616 50 ▶ if ($module eq 'strict') {
Branch: 1 branch
BranchTrueFalseTotal
if ($module eq "strict") 10 40 50
617 # if this is an import, first clean all stricts
618 10 strict->unimport::out_of($target);
619 }
620 # (BITMAPs)
621 50 ▶ if ($modifier eq 'BITMAP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($modifier eq "BITMAP") 0 50 50
622 0 my $bitmap = args2bitmask(map { s|^|BITMAP:$module/| } @options) >> $FLAGS{"BITMAP:$module/0"};
623 0 ▶ if ($module eq 'criticism') { @options = ( -severity => $bitmap ); }
Branch: 2 branches
BranchTrueFalseTotal
if ($module eq 'criticism') { } 0 0 0
elsif ($module eq 'perl') { } 0 0 0
624 0 elsif ($module eq 'perl') { die "Internal error (report as a bug): Perl versions should have already been extracted at this point!"; }
625 0 else { die "Unsupported set of BITMAP flags: BITMAP:$module/*"; }
626 }
627  
628 # open gets kinda strange with the eval/require
629 50 my $evalmodule = $module;
630 50 ▶ $evalmodule = "'open.pm'" if ($module eq 'open');
Branch: 1 branch
BranchTrueFalseTotal
if $module eq "open" 3 47 50
631  
632 # DO IT!
633 50 ▶ if (eval "require $evalmodule; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require $evalmodule; 1") 50 0 50
634 50 $module->$method($target, @options);
635 50 return 1;
636 }
637 0 return undef;
638 }
639  
640 120 ▶sub find_and_remove {
Subroutine find_and_remove: called CC=6 SCAR=17.9
Pod undocumented
641 120 my ($re, $arr) = @_;
642 120 ▶ return (wantarray ? () : undef) unless @$arr;
Branch: 2 branches
BranchTrueFalseTotal
unless @$arr 4 116 120
wantarray ? : 2 2 4
643 116 ▶ $re = qr/$re/ unless (ref $re eq 'Regexp');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $re eq "Regexp" 0 116 116
644  
645 116 my @flags;
646 116 ▶ for (my $i = 0; $i < @$arr; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$arr) 4930 116 5046
647 4930 ▶ push @flags, splice(@$arr, $i--, 1) if ($arr->[$i] =~ $re);
Branch: 1 branch
BranchTrueFalseTotal
if $arr->[$i] =~ /$re/ 1587 3343 4930
648 }
649  
650 116 return @flags;
651 }
652  
653 # Find items in @B that are in @A
654 20 ▶sub foundin (\@\@) {
Subroutine foundin: called CC=1 SCAR=0.0
Pod undocumented
655 20 my ($A, $B) = @_;
656 20 ▶ return grep { my $i = $_; any { $i eq $_ } @$A; } @$B;
Subroutine __ANON__: called CC=1 SCAR=0.0
657 }
658  
659 # Find items in @B that are not in @A
660 30 ▶sub notin (\@\@) {
Subroutine notin: called CC=1 SCAR=0.0
Pod undocumented
661 30 my ($A, $B) = @_;
662 30 ▶ return grep { my $i = $_; none { $i eq $_ } @$A; } @$B;
Subroutine __ANON__: called CC=1 SCAR=0.0
663 }
664  
665 12 ▶sub filter_args {
Subroutine filter_args: called CC=1 SCAR=0.0
Pod undocumented
666 12 return bitmask2flags( args2bitmask(@_) );
667 }
668  
669 15 ▶sub args2bitmask {
Subroutine args2bitmask: called CC=18 SCAR=31.3
Pod undocumented
670 15 my @args = @_;
671  
672 15 my $bitmask = 0;
673 15 ▶ while (my $flag = shift @args) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $flag = shift @args) 238 15 253
674 238 my $negate_bit = ($flag =~ s/^-//);
675 238 my $bit = $FLAGS{$flag};
676 238 my $def = $ALIAS{$flag};
677  
678 # Direct find on FLAGS
679 238 ▶ if (defined $bit) {
Branch: 6 branches
BranchTrueFalseTotal
if (defined $bit) { } 153 85 238
elsif ($flag =~ /^(?| # branch reset (look it up) v? 5\. (?<major>\d+) (?:\.(?<minor>\d+))? | \x05(?<major>.)(?<minor>.)? )$/x) { } 3 82 85
elsif ($flag =~ /^[!\241]/) { } 0 82 82
elsif ($flag =~ /^\xC2\xA1/) { } 0 82 82
elsif ($flag =~ /^\d+$/) { } 10 72 82
elsif (defined $def) { } 72 0 72
680 153 ▶ $bitmask = $negate_bit ?
Branch: 1 branch
BranchTrueFalseTotal
$negate_bit ? : 20 133 153
681 $bitmask & ~(1 << $bit) :
682 $bitmask | 1 << $bit;
683 }
684 # Perl version
685 elsif ($flag =~ /^(?| # branch reset (look it up)
686 v? 5\. (?<major>\d+) (?:\.(?<minor>\d+))? |
687 \x05(?<major>.)(?<minor>.)?
688 )$/x) {
689 3 my ($mj, $mn) = ($+{major}, $+{minor});
690 3 ▶ ($mj, $mn) = (ord($mj), ord($mn)) if $flag =~ /^\x05/;
Branch: 1 branch
BranchTrueFalseTotal
if $flag =~ /^\x05/ 0 3 3
691 3 ▶ $mn ||= 0; # bigint/BigInt has weird problems with undef
Condition50%1/2
$mn ||= bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
l!l
30
MC/DC0%0/1
$mn ||= bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$mn
Truth table50%1/2
A
A= $mn
Aresult
11
00
692  
693 3 my $bitmask8 = ($mj-8) * 16 + $mn + 1;
694 3 ▶ die "Perl version flags for sanity must be at least 5.8.0" if ($bitmask8 <= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $bitmask8 <= bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) 0 3 3
695  
696 3 foreach my $bit8 (0..7) {
697 24 ▶ push @args, 'BITMAP:perl/'.$bit8 if ($bitmask8 & 1 << $bit8);
Branch: 1 branch
BranchTrueFalseTotal
if $bitmask8 & bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) << $bit8 6 18 24
698 }
699 }
700 # Pragma hash
701 elsif ($flag =~ /^[!¡]/) {
702 0 ▶ die "Only one argument can be provided if you are using a pragma hash!" unless (@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) 0 0 0
703 0 return decode_pragmahash($flag);
704 }
705 # A UTF-8 pragma hash
706 elsif ($flag =~ /^\xC2\xA1/) {
707 # This could happen if the user sent in a UTF-8 string without saying 'use utf8;' or
708 # any identifying BOFs, etc., saying that the program is in UTF-8. Of course, the
709 # catch-22 is that they are expecting _sanity_ to enable utf8 for them, so we need to
710 # convert the string manually.
711 0 require Encode;
712 0 push @args, Encode::decode('utf8', $flag);
713 }
714 # A real bitmask
715 elsif ($flag =~ /^\d+$/) {
716 10 $flag += 0;
717 10 ▶ $bitmask = $negate_bit ?
Branch: 1 branch
BranchTrueFalseTotal
$negate_bit ? : 0 10 10
718 $bitmask & ~$flag :
719 $bitmask | $flag;
720 }
721 # An alias
722 elsif (defined $def) {
723 72 ▶ unshift @args, map { $negate_bit ? "-$_" : $_ } (ref $def ? @$def : $def);
Branch: 2 branches
BranchTrueFalseTotal
$negate_bit ? : 18 194 212
ref $def ? : 52 20 72
724 }
725 else {
726 0 die "Unsupported flag: $flag";
727 }
728 }
729  
730 15 return $bitmask;
731 }
732  
733 12 ▶sub bitmask2flags {
Subroutine bitmask2flags: called CC=3 SCAR=11.0
Pod undocumented
734 12 my ($bitmask) = @_;
735  
736 12 my @flags;
737 12 foreach my $bit (0..@FLAGS-1) {
738 3036 ▶ push @flags, $FLAGS[$bit] if ($bitmask & 1 << $bit);
Branch: 1 branch
BranchTrueFalseTotal
if $bitmask & bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) << $bit 838 2198 3036
739 }
740  
741 12 return @flags;
742 }
743  
744 2 my $CURRENT_HASH_VERSION = 0;
745  
746 0 ▶sub encode_pragmahash {
Subroutine encode_pragmahash: not called CC=5 SCAR=34.0
Pod undocumented
747 0 my ($flags, $type) = @_;
748 0 ▶ $type //= '¡';
Condition0%0/2
$type //= "\x{a1}"
l!l
00
MC/DC0%0/1
$type //= "\x{a1}"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
749  
750 0 ▶ $flags = args2bitmask(@$flags) if (ref $flags eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $flags eq "ARRAY" 0 0 0
751 0 ▶ return $flags if ($type eq '0');
Branch: 1 branch
BranchTrueFalseTotal
if $type eq 0 0 0 0
752 0 ▶ my $hash = ($type eq '!' ? $calc90 : $calc48900)->to_base($flags);
Branch: 1 branch
BranchTrueFalseTotal
$type eq '!' ? : 0 0 0
753 0 return $type.$CURRENT_HASH_VERSION.$hash
754 }
755  
756 ### FIXME: Wait for Math::BaseCalc fix (RT #77198) ###
757 0 ▶sub decode_pragmahash {
Subroutine decode_pragmahash: not called CC=4 SCAR=30.0
Pod undocumented
758 0 my ($hash) = @_;
759 0 ($hash, my $type) = (substr($hash, 1), substr($hash, 0, 1));
760 0 ▶ die "Invalid hash type ($type) for pragma hash: $hash" unless ($type =~ /^[!¡]$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /^[!\241]$/ 0 0 0
761 0 ▶ die "Unsupported pragma hash version!" unless ($hash =~ s/^$CURRENT_HASH_VERSION//);
Branch: 1 branch
BranchTrueFalseTotal
unless $hash =~ s/^$CURRENT_HASH_VERSION// 0 0 0
762  
763 0 ▶ return ($type eq '!' ? $calc90 : $calc48900)->from_base($hash);
Branch: 1 branch
BranchTrueFalseTotal
$type eq '!' ? : 0 0 0
764 }
765  
766 # warnings void + bigint + 1; + perl sanity.pm = "Useless use of a constant (1) in void context"
767 2 42;
768  
769 __END__
« sanity/BaseCalc.pm ↑ Summary