| 1 | package Perl500503Syntax::OrDie; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Perl500503Syntax::OrDie - Validate Perl 5.005_03 source compatibility | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # https://metacpan.org/dist/Perl500503Syntax-OrDie | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Copyright (c) 2026 INABA Hitoshi <ina.cpan@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 28 | ▶ | use 5.00503; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 28 | ▶ | BEGIN { if ($] < 5.006 && !defined(&warnings::import)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.4
Branch: 1 branch
Condition33%1/3
$] < "5.006" and not defined &warnings::import
MC/DC0%0/2
$] < "5.006" and not defined &warnings::import
$] < "5.006"
not defined &warnings::import
Truth table33%1/3
A and not(B)
A= $] < "5.006"B= not defined &warnings::import
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | $INC{'warnings.pm'} = 'stub'; eval 'package warnings; sub import {}' } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 28 | ▶ | use warnings; local $^W = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 28 | ▶ | use vars qw($VERSION @BLACKLIST @REGEX_BLACKLIST @RAW_BLACKLIST @STRING_BLACKLIST $_OPEN_GUARDED $_MKDIR_GUARDED); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # BLACKLIST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Each entry: [ qr/pattern/, 'human-readable description' ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Matched against source after masking comments and string literals. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | @BLACKLIST = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Perl 5.6 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # our VARIABLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | [ qr/\bour\s*[\$\@\%\*]/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | "'our' declaration (introduced in Perl 5.6; use 'use vars' instead)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # 3-argument open() is detected in a dedicated paren-aware stage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # (see "Stage 1c" in _check_source); a flat comma-counting regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # cannot tell a top-level argument comma from one nested inside an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # expression such as open(FH, '>' . File::Spec->catfile($d, $f)). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # use utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | [ qr/\buse\s+utf8\b/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | "'use utf8' (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # use VERSION >= 5.6 (numeric forms: 5.6, 5.06, 5.006, 5.010, 5.100 ...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Pattern: 5. followed by (0*[6-9]) OR (0[1-9]\d+) OR ([1-9]\d+) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # This catches 5.6, 5.06, 5.006, 5.010, 5.012, 5.100 etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # but not 5.5, 5.005, 5.004 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | [ qr/\buse\s+5\s*\.\s*(?:0*[6-9]|0[1-9]\d+|[1-9]\d+)\b/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | "use VERSION >= 5.6 (target is Perl 5.005_03)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # use v5.6, use v5.10, ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | [ qr/\buse\s+v5\s*\.\s*[6-9]/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | "use vVERSION >= v5.6 (target is Perl 5.005_03)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | [ qr/\buse\s+v5\s*\.1/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | "use vVERSION >= v5.10 (target is Perl 5.005_03)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # \x{HHHH} Unicode escape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | [ qr/\\x\{[0-9A-Fa-f]+\}/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | "\\x{} Unicode escape (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # \N{name} named character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | [ qr/\\N\{[^}]+\}/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | "\\N{} named character escape (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # @+ / @- match-position arrays: $+[N] $-[N] @+ @- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | [ qr/(?:\$[+\-]\[|\@[+\-](?!\w))/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 'match-position arrays @+/@- or $+[N]/$-[N] (introduced in Perl 5.6)' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # CHECK { } / INIT { } named phase blocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | [ qr/\b(?:CHECK|INIT)\s*\{/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | "CHECK/INIT phase blocks (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # v-strings: v1.2.3 or v5.6.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | [ qr/(?<!\w)v\d+\.\d+/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | "v-string notation (introduced in Perl 5.6; use a plain number instead)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # $^V (version object; use $] instead) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | [ qr/\$\^V\b/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | '$^V version object (introduced in Perl 5.6; use $] instead)' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # :lvalue subroutine attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | [ qr/\bsub\s+\w[\w:]*\s*(?:\([^)]*\)\s*)?:[^{]*\blvalue\b/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | "':lvalue' subroutine attribute (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # typeglob component slice *FH{IO} *foo{SCALAR} *foo{CODE} etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Perl 5.005_03 does not support typeglob-element access via *name{SLOT}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Guard: require leading sigil or word boundary to avoid false positives. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | [ qr/\*\w[\w:]*\s*\{\s*(?:IO|SCALAR|ARRAY|HASH|CODE|GLOB|FORMAT|NAME|PACKAGE)\s*\}/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | "typeglob component access *name{SLOT} (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # Perl 5.8 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Lexical filehandle / directory handle. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # open(my $fh, ...), opendir(my $dh, ...) and their relatives rely on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # a handle being autovivified into an undefined lexical, which arrived | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # in Perl 5.6. Perl 5.005_03 has nothing to autovivify into: it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # reports "Can't use an undefined value as a symbol reference" at run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # time, so the defect survives compilation and shows up only when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # code actually opens something. Write local *FH; and pass the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # bareword, or pass a glob reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # Only the my spelling is listed. open($fh, ...) against a lexical | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # filled in earlier cannot be told apart from open($fh, ...) against a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # lexical holding a glob, which is valid in 5.005_03, so flagging it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # would report working code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | [ qr/\b(?:open|opendir|sysopen|pipe|socket|socketpair|accept)\s*(?:\(\s*)?my\s*[\$\(]/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | "lexical filehandle or directory handle (introduced in Perl 5.6; use 'local *FH' and a bareword)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # use encoding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | [ qr/\buse\s+encoding\b/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | "'use encoding' (introduced in Perl 5.8)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # use constant with a hashref (hash of constants) -- Perl 5.8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # Single-value form use constant NAME => VALUE is 5.004+, always OK. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Hash-ref form use constant { A => 1, B => 2 } was added in Perl 5.8. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | [ qr/\buse\s+constant\s*\{/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | "'use constant { HASH }' multi-constant form (introduced in Perl 5.8; use separate 'use constant' statements)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # Perl 5.10 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # defined-or-assignment operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 12 | [ do { my $p = '/' . '/='; qr/$p/ }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | "defined-or assignment '" . '/' . "/=' (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # say HANDLE or say LIST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # Exclude ->say(...) method calls and say => hash-key usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 12 | [ do { my $kw = 'sa' . 'y'; qr/(?<!->)\b$kw\b(?!\s*=>)/ }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | "'say' (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # sta-te $var | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 12 | [ do { my $kw = 'sta' . 'te'; qr/\b$kw\s+[\$\@\%]/ }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | "'sta" . "te' variable (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # given(...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | [ qr/\bgiven\s*\(/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | "'given' (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # when(...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | [ qr/\bwhen\s*\(/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | "'when' (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # smart-match ~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | [ qr/~~/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | "smart-match operator '~~' (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # use feature | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # The empty-import form use feature () imports nothing and, when paired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # with a BEGIN { $INC{'feature.pm'} = '' if $] < 5.010 } stub, loads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # nothing on Perl 5.005_03. It is a no-op on every Perl version and is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # standard cross-version guard idiom (parallel to the tolerated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # use warnings stub), so it is NOT a violation. A non-empty import list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # such as use feature 'say' or use feature qw(...) still is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | [ qr/\buse\s+feature\b(?!\s*\(\s*\))/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | "'use feature' (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # defined-or operator (two slashes, not part of s///, m//, =~, !~) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # and not the defined-or-assign variant | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | [ qr/(?<![=~!])\s\/\/(?!=)/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | "defined-or operator (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # UNITCHECK phase block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | [ qr/\bUNITCHECK\s*\{/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | "UNITCHECK phase block (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # ${^MATCH} ${^PREMATCH} ${^POSTMATCH} (used with /p flag -- 5.10) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | [ qr/\$\{\^(?:MATCH|PREMATCH|POSTMATCH)\}/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | "\${^MATCH}/\${^PREMATCH}/\${^POSTMATCH} (introduced in Perl 5.10; require /p flag)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # Perl 5.12 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # package NAME VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | [ qr/\bpackage\s+\w[\w:]*\s+v?\d/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | "'package NAME VERSION' (introduced in Perl 5.12)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # yada-yada operator ... (not to be confused with .. range) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 12 | [ do { my $p = '\\.' x 3; qr/(?<!\\.)$p(?!\\.)/ }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | "yada-yada operator '...' (introduced in Perl 5.12)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # Perl 5.14 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # /r (non-destructive) flag on s/// or tr/// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # _mask_source emits __SR__ or __TRR__ marker when r flag is present. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | [ qr/__SR__|__TRR__/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | "s///r or tr///r non-destructive flag (introduced in Perl 5.14)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # Perl 5.16 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # __SUB__ token (reference to the current subroutine) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | [ qr/__SUB__/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | "__SUB__ (introduced in Perl 5.16; use explicit sub name or \$_[0] recursion)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # Perl 5.18 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # my sub NAME / state sub NAME -- lexical subroutines (Perl 5.18) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 12 | [ do { my $kw = 'su' . 'b'; qr/\b(?:my|state)\s+$kw\s+\w/ }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | "'my sub'/'state sub' lexical subroutine (introduced in Perl 5.18)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # Perl 5.20 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # subroutine signatures: sub foo ($x, $y) { (Perl 5.20) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | [ qr/\bsub\s+\w+\s*\([^\)]*(?<!\\)[\$\@\%][a-zA-Z_][^\)]*\)\s*\{/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | "subroutine signature (introduced in Perl 5.20)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # postfix dereference $ref->@* $ref->%* $ref->&* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | [ qr/->\s*[\@\%\&\$]\s*\*/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | "postfix dereference (introduced in Perl 5.20)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # %hash{LIST} and %array[LIST] key/value (index/value) slices (Perl 5.20) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # Exclude plain %hash alone (no subscript) and %hash = (...) assignment. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # Require preceding context that cannot be an assignment target start. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | [ qr/(?:[\(=,;!&|?:]|\breturn\b)\s*\%\w[\w:]*\s*[\{\[]/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | "key/value hash/array slice %hash{} or %array[] (introduced in Perl 5.20)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # Perl 5.22 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # &. |. ^. ~. string bitwise operators (use feature 'bitwise') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | [ qr/(?:[&|^]\.=?|~\.)/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | "string bitwise operator '&.' '|.' '^.' '~.' (introduced in Perl 5.22)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # \$scalar in foreach -- reference aliasing (use feature 'refaliasing') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | [ qr/\bforeach\s+\\(?:my\s+)?[\$\@\%\*]/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | "reference aliasing in foreach (introduced in Perl 5.22; use index-based loop instead)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # <<>> double-diamond operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | [ qr/<</, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | "<<>> double-diamond operator (introduced in Perl 5.22)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # /n flag (non-capturing groups make all captures non-capturing) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | [ qr{(?:=~|!~|(?<!\w)[msqy])\s*X+[gimsxodualp]*n[gimsxodualp]*\s*[;,)\s\{]}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | "/n non-capturing regex flag (introduced in Perl 5.22)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # Perl 5.26 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # <<~ indented heredoc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | [ qr/<<~/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | "<<~ indented heredoc (introduced in Perl 5.26)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # Perl 5.32 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # isa infix operator: $obj isa ClassName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # Exclude ->isa() method calls (> before) and UNIVERSAL::isa() (:: before) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # Exclude isa( call form (followed by open paren = sub call, not infix) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | [ qr/(?<![>:])(?<![>])\bisa\b(?!::)(?!\s*\()/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | "'isa' infix operator (introduced in Perl 5.32; use UNIVERSAL::isa() instead)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # Perl 5.34+ features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # try { } catch ($e) { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | [ qr/\btry\s*\{/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | "'try' block (introduced in Perl 5.34)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # Perl 5.36 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # use builtin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | [ qr/\buse\s+builtin\b/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | "'use builtin' (introduced in Perl 5.36)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # for my ($a, $b) (@list) -- iterable-value variables in for loop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | [ qr/\bfor\s+my\s*\(/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | "'for my (\$a,\$b)' paired iteration (introduced in Perl 5.36)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # Perl 5.38+ features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # class Foo { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | [ qr/\bclass\s+\w/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | "'class' keyword (introduced in Perl 5.38)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # Perl 5.40 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # ^^ high-precedence logical XOR operator ($x ^^ $y) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | [ qr/\^\^[^>]/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | "'^^ / ^^=' high-precedence logical XOR (introduced in Perl 5.40)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # __CLASS__ keyword | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | [ qr/__CLASS__/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | "'__CLASS__' keyword (introduced in Perl 5.40; use __PACKAGE__ or \$class instead)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # Perl 5.42 features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # any { } LIST and all { } LIST -- experimental keyword operators | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # Exclude files that have "use List::Util" with any/all in the import list, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # since those are sub calls, not keywords. Detection deferred to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # _check_source() which performs the import pre-scan. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # (Pattern is applied conditionally; see _check_source().) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # my method NAME -- lexical method declaration inside class block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 12 | [ do { my $kw = 'meth' . 'od'; qr/\bmy\s+$kw\b/ }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | "'my method' lexical method declaration (introduced in Perl 5.42)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # ->& invocation of lexical method (Perl 5.42) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | [ qr/->&\s*\w/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | "'->&name' lexical method call operator (introduced in Perl 5.42)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # BLACKLIST_CONDITIONAL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # Entries that are only applied when certain file-level conditions hold. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # Each entry: [ $condition_key, qr/pattern/, 'description' ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # $condition_key is checked against %cond hash in _check_source(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # (Currently used for any/all keyword detection.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # REGEX_BLACKLIST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # Patterns checked against the CONTENT of regex literals only. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # Each entry: [ qr/pattern/, 'human-readable description' ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 12 | @REGEX_BLACKLIST = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # \x{HHHH} Unicode escape in regex -- Perl 5.6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | [ qr/\\x\{[0-9A-Fa-f]+\}/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | "\\x{} Unicode escape (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # \N{name} named character in regex -- Perl 5.6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | [ qr/\\N\{[^}]+\}/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | "\\N{} named character escape (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # \p{} \P{} Unicode property escapes -- Perl 5.6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | [ qr/\\[pP]\{/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | "\\p{}\\P{} Unicode property in regex (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # \K (keep) -- Perl 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | [ qr/\\K/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | "\\K (keep) in regex (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # Named capture (?<name>...) or \k<name> backreference -- Perl 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | [ qr/(?:\(\?<[A-Za-z_]|\\k<)/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | "named capture (?<name>...) or \\k<name> (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # Branch reset group (?|...) -- Perl 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | [ qr/\(\?[|]/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | "branch reset (?|...) in regex (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | # Backtrack control verbs (*FAIL) (*ACCEPT) (*PRUNE) (*SKIP) etc -- Perl 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | [ qr/\(\*[A-Z]/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | "backtrack control verb (*VERB) in regex (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # \h \H \v \V \R -- horizontal/vertical whitespace -- Perl 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | [ qr/\\[hHvVR](?!\w)/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | "\\h/\\H/\\v/\\V/\\R regex escape (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # Variable-length lookbehind -- experimental Perl 5.30, stable Perl 5.38 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | [ qr/\(\?<[=!][^)]*(?:\{|\*|\+)[^)]*\)/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | "variable-length lookbehind in regex (experimental from Perl 5.30, stable in Perl 5.38; use fixed-length)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # Possessive quantifiers in regex: a++ a*+ a?+ a{n,m}+ -- Perl 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | [ qr/(?:[A-Za-z0-9_)\].])(?:[+*?]|\{\d+(?:,\d*)?\})\+/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | "possessive quantifier (++/*+/?+/{n,m}+) in regex (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # Recursive patterns (?PARNO) (?&name) (?R) -- Perl 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | [ qr/\(\?(?:[0-9]+|[+-][0-9]+|R|&\w+)\)/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | "recursive pattern (?PARNO) / (?&name) / (?R) (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # \g{N} relative or absolute backreference -- Perl 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | [ qr/\\g\{/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | "\\g{N} relative/absolute backreference (introduced in Perl 5.10)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # RAW_BLACKLIST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # Abolished: string and regex contents must be freely writable in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # Perl 5.005_03 code. Checking runtime string values (PerlIO layer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # names, sprintf format flags, etc.) is not the role of a static | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # syntax checker. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | # Former entries and why they were removed: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # PerlIO layer (:utf8 etc) in open()/binmode() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # -> open() with a PerlIO layer requires 3-argument form, already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | # caught by the 3-argument open() entry in @BLACKLIST. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # binmode() layer string is a runtime value, not syntax. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # sprintf/printf "%v" format flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # -> The format string is a runtime value, not a syntax construct. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # A string literal containing "%v" is valid Perl 5.005_03 syntax. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # Note that this reasoning covers the *value* a string denotes, not the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # escape sequences its source spelling is made of. Those are syntax and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # are checked; see @STRING_BLACKLIST below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 12 | @RAW_BLACKLIST = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # STRING_BLACKLIST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # Matched against the body of every INTERPOLATING string literal: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # "...", qq//, qx//, `...`, an unquoted or double-quoted heredoc, and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # replacement half of s/// unless it is single-quote delimited. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # The bodies of string literals are masked out before @BLACKLIST runs, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # an escape written inside one used to be invisible to every stage: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # \x{} and \N{} entries in @BLACKLIST could fire only on the rare source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # that puts them outside a string, and @REGEX_BLACKLIST covered them only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # inside a regex. The ordinary spelling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # my $smiley = "\x{263A}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # therefore passed unreported, which is precisely the construct this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # distribution exists to catch: Perl 5.005_03 does not know \x{...} and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # quietly reads it as \x with no hex digits followed by the literal text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # "{263A}", so the program keeps running and produces the wrong string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # Only escapes are listed here. What a string *says* is still none of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # this module's business; an interpolating string may contain any text. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # A single-quoted string performs no escape processing at all and is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # scanned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 12 | @STRING_BLACKLIST = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # \x{HHHH} Unicode escape in a string -- Perl 5.6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | [ qr/\\x\{[0-9A-Fa-f]+\}/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | "\\x{} Unicode escape in a string (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # \N{name} named character in a string -- Perl 5.6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | [ qr/\\N\{[^}]+\}/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | "\\N{} named character escape in a string (introduced in Perl 5.6)" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # import() -- called when the caller writes: use Perl500503Syntax::OrDie; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | my ($pkg, $file, $line) = caller(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if (defined $file && $file ne '' && $file ne '-e' && $file ne '-') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
defined $file and $file ne "" and $file ne "-e" and $file ne "-"
defined $file and $file ne "" and $file ne "-e"
defined $file and $file ne ""
MC/DC0%0/4
defined $file and $file ne "" and $file ne "-e" and $file ne "-"
defined $file
$file ne ""
$file ne "-e"
$file ne "-"
Truth table0%0/5
A and B and C and D
A= defined $fileB= $file ne ""C= $file ne "-e"D= $file ne "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | if (-f $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | my @violations = _check_file($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | if (@violations) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | die join('', @violations); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | _install_runtime_guards(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # _check_file($path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # Returns a list of violation strings (empty list = no violations). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 11 | ▶ | sub _check_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_file: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 11 | my ($file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 11 | local *_ORDIE_FH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 11 | eval 'CORE::' . 'open(_ORDIE_FH, $file) or die $!'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 11 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | warn "Perl500503Syntax::OrDie: cannot open '$file': $!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 11 | my $source = do { local $/; <_ORDIE_FH> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 11 | close _ORDIE_FH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 11 | return _check_source($source, $file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # _check_source($source, $filename) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # Returns a list of violation strings (empty list = no violations). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 428 | ▶ | sub _check_source { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_source: called CC=63 SCAR=42.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 428 | my ($source, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 428 | ▶ | $file = '(unknown)' unless defined $file && $file ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $file and $file ne ""
MC/DC0%0/2
defined $file and $file ne ""
defined $file
$file ne ""
Truth table33%1/3
A and B
A= defined $fileB= $file ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 428 | my @violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 428 | my ($masked, $regex_bodies_ref, $string_bodies_ref) = _mask_source($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 428 | my @lines = split(/\n/, $masked, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 428 | my @rawlines = split(/\n/, $source, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # A line carries live code when its masked form still holds something | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # other than the mask character, whitespace and the comment marker. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # Comments, POD, heredoc bodies and everything after __END__ are dead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # by that test, which is what the stages below need when they have to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # consult the RAW text of a line: it keeps a construct quoted in prose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # from being read as the construct itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 428 | ▶ | my @live = map { ($lines[$_] =~ /[^X\s#]/) ? 1 : 0 } 0 .. $#lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # Pre-scan: detect use List::Util qw(... any ... all ...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # If found, the any/all BLOCK keyword check is suppressed because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # those names are imported subs, not the new keyword form. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 428 | my $listutil_any_imported = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 428 | my $listutil_all_imported = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 428 | my $cm = _mask_comments($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 428 | ▶ | if ($cm =~ /\buse\s+List::Util\b([^;]+);/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 6 | my $args = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 6 | ▶ | $listutil_any_imported = 1 if $args =~ /\bany\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 6 | ▶ | $listutil_all_imported = 1 if $args =~ /\ball\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # Stage 1: BLACKLIST -- scan masked source (comments + strings masked) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 428 | for my $entry (@BLACKLIST) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 20544 | my ($pattern, $desc) = @{$entry}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 20544 | my $lineno = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 20544 | for my $mline (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 2123568 | $lineno++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 2123568 | ▶ | if ($mline =~ $pattern) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 116 | push @violations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | "Perl500503Syntax::OrDie: VIOLATION at $file line $lineno:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | . " $desc\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # Stage 1b: any/all BLOCK keyword -- conditional on import pre-scan. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # The List::Util keyword form is an expression any { ... } LIST . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # A subroutine *definition* sub any { ... } (or a method call such | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | # as $obj->all { ... } ) must NOT be flagged. We therefore inspect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # the text immediately preceding each any{ / all{ match and skip it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | # when it is preceded by sub or by an arrow operator. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 428 | ▶ | my $check_any = $listutil_any_imported ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 428 | ▶ | my $check_all = $listutil_all_imported ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 428 | my $desc_any = "'any BLOCK LIST' keyword operator (introduced in Perl 5.42; use List::Util instead)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 428 | my $desc_all = "'all BLOCK LIST' keyword operator (introduced in Perl 5.42; use List::Util instead)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 428 | my $lineno = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 428 | for my $mline (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 44241 | $lineno++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 44241 | ▶ | while ($mline =~ /\b(any|all)(\s*)\{/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 13 | my $word = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 13 | my $matchlen = length($1) + length($2) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 13 | my $start = pos($mline) - $matchlen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 13 | my $pre = substr($mline, 0, $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 13 | ▶ | next if $pre =~ /\bsub\s+$/; # sub any { ... } definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 9 | ▶ | next if $pre =~ /->\s*$/; # $obj->any { ... } method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 8 | ▶ | if ($word eq 'any' && $check_any) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$word eq "any" and $check_any
MC/DC100%2/2
$word eq "any" and $check_any
$word eq "any"
$check_any
Truth table100%3/3
A and B
A= $word eq "any"B= $check_any
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 4 | push @violations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | "Perl500503Syntax::OrDie: VIOLATION at $file line $lineno:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | . " $desc_any\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | ▶ | elsif ($word eq 'all' && $check_all) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$word eq "all" and $check_all
MC/DC100%2/2
$word eq "all" and $check_all
$word eq "all"
$check_all
Truth table100%3/3
A and B
A= $word eq "all"B= $check_all
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 2 | push @violations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | "Perl500503Syntax::OrDie: VIOLATION at $file line $lineno:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | . " $desc_all\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # Stage 1c: 3-argument open() -- paren-aware top-level comma count. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | # open(FH, MODE, EXPR) has two commas at the top level of the call; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | # open(FH, EXPR) has one. Commas nested inside parentheses -- e.g. a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | # function call used as the second argument, as in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # open(FH, '>' . File::Spec->catfile($dir, $file)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | # -- sit at depth >= 2 and are not counted, so the 2-argument form is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # no longer mistaken for the 3-argument form. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 428 | my $kw = 'op' . 'en'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 428 | my $open_re = qr/\b$kw\s*\(/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 428 | my $lineno = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 428 | for my $mline (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 44241 | $lineno++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 44241 | ▶ | while ($mline =~ /$open_re/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 134 | my $i = pos($mline); # index just after the '(' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 134 | my $len = length($mline); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 134 | my $depth = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 134 | my $commas = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 134 | ▶ | while ($i < $len && $depth > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i < $len and $depth > 0
MC/DC100%2/2
$i < $len and $depth > 0
$i < $len
$depth > 0
Truth table100%3/3
A and B
A= $i < $lenB= $depth > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 2911 | my $c = substr($mline, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 2911 | ▶ | if ($c eq '(') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 3 | $depth++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | elsif ($c eq ')') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 137 | $depth--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | ▶ | elsif ($c eq ',' && $depth == 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$c eq "," and $depth == 1
MC/DC100%2/2
$c eq "," and $depth == 1
$c eq ","
$depth == 1
Truth table100%3/3
A and B
A= $c eq ","B= $depth == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 138 | $commas++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 2911 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 134 | ▶ | if ($commas >= 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 6 | push @violations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | "Perl500503Syntax::OrDie: VIOLATION at $file line $lineno:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | . " 3-argument $kw() (introduced in Perl 5.6; use 2-argument form)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | # Stage 1d: binmode() with more than one argument. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | # Perl 5.005_03's binmode takes exactly one argument. The LAYER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | # argument -- binmode($fh, ':raw') -- arrived with PerlIO in Perl 5.6, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | # and a 5.005_03 perl rejects it outright with "Too many arguments for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | # binmode". What the layer string says does not enter into it: this is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | # a question of arity, the same question the 3-argument open() stage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | # above asks, so it is answered the same way, by counting the commas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # that sit at the top level of the call. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 428 | my $kw = 'binm' . 'ode'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 428 | my $lineno = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 428 | for my $mline (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 44241 | $lineno++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 44241 | my $hit = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # binmode(...) -- count top-level commas inside the parens. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 44241 | ▶ | while ($mline =~ /\b$kw\s*\(/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 18 | my $i = pos($mline); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 18 | my $len = length($mline); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 18 | my $depth = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 18 | my $commas = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 18 | ▶ | while ($i < $len && $depth > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i < $len and $depth > 0
MC/DC50%1/2
$i < $len and $depth > 0
$i < $len
$depth > 0
Truth table66%2/3
A and B
A= $i < $lenB= $depth > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 152 | my $c = substr($mline, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | ▶ | if ($c eq '(') { $depth++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 18 | elsif ($c eq ')') { $depth-- } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 4 | ▶ | elsif ($c eq ',' && $depth == 1) { $commas++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$c eq "," and $depth == 1
MC/DC50%1/2
$c eq "," and $depth == 1
$c eq ","
$depth == 1
Truth table66%2/3
A and B
A= $c eq ","B= $depth == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 152 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 18 | ▶ | $hit = 1 if $commas >= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | # binmode FH, LAYER -- the same call without parentheses. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | # argument text is taken up to the end of the statement, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | # comma belonging to a later statement on the same line is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | # counted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 44241 | ▶ | $hit = 1 if $mline =~ /\b$kw\s+[^;(]*,/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 44241 | ▶ | if ($hit) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 5 | push @violations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | "Perl500503Syntax::OrDie: VIOLATION at $file line $lineno:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | . " $kw() with a LAYER argument (introduced in Perl 5.6; " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | . "5.005_03 takes the filehandle alone)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | # Stage 1e: use warnings / no warnings without the compatibility stub. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | # The warnings pragma is Perl 5.6. On 5.005_03 the bare statement dies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # at compile time with "Can't locate warnings.pm", which makes it the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # 5.6-ism a port trips over first. It is nevertheless written in every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # cross-version file, guarded: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | # BEGIN { $INC{'warnings.pm'} = '' if $] < 5.006 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | # use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | # With the entry in %INC the require is skipped, and Perl ignores a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # missing import/unimport, so both use warnings and no warnings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | # become no-ops on 5.005_03 and keep their meaning everywhere else. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | # That idiom is the tolerated form, exactly as the empty-import form of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # use feature is tolerated above; the unguarded statement is not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | # The guard is looked for in the raw text of lines that carry live | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | # code, so that the idiom quoted in a comment or in POD -- this file's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | # own documentation quotes it -- is not mistaken for the guard itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 428 | my $guard_line = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 428 | for my $i (0 .. $#rawlines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 1522 | ▶ | next unless $live[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 530 | ▶ | if ($rawlines[$i] =~ /\$INC\s*\{\s*['"]warnings\.pm['"]\s*\}/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 34 | $guard_line = $i + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 34 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 428 | my $lineno = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 428 | for my $mline (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 44241 | $lineno++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 44241 | ▶ | next unless $mline =~ /\b(use|no)\s+warnings\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 38 | my $word = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 38 | ▶ | next if $guard_line && $guard_line <= $lineno; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$guard_line and $guard_line <= $lineno
MC/DC100%2/2
$guard_line and $guard_line <= $lineno
$guard_line
$guard_line <= $lineno
Truth table100%3/3
A and B
A= $guard_lineB= $guard_line <= $lineno
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 4 | push @violations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | "Perl500503Syntax::OrDie: VIOLATION at $file line $lineno:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | . " '$word warnings' without the \$INC{'warnings.pm'} stub " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | . "(the warnings pragma was introduced in Perl 5.6)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # Possessive quantifiers in code: a++ a*+ a?+ a{n,m}+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 428 | my $lineno2 = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 428 | for my $mline (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 44241 | $lineno2++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 44241 | ▶ | while ($mline =~ /(?<=[a-zA-Z0-9_.)\]])((?:[+*?]|\{\d+(?:,\d*)?\})\+)/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 440 | my $quant = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # In masked code a "++" is always the postfix-increment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | # operator (e.g. $pkg::var++, $a[0]++); a genuine possessive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | # quantifier can only occur inside a regex, which is masked, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | # and is caught by REGEX_BLACKLIST instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 440 | ▶ | next if $quant eq '++'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | my $qpos = pos($mline) - length($quant) - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | my $before = substr($mline, 0, $qpos + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | next if $before =~ /\$\w+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | ▶ | next if $before =~ /\@\w+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | push @violations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | "Perl500503Syntax::OrDie: VIOLATION at $file line $lineno2:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | . " possessive quantifier (++/*+/?+/{n,m}+) (introduced in Perl 5.10)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | # Stage 2: RAW_BLACKLIST -- comment-stripped raw source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 428 | my $comment_masked = _mask_comments($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 428 | my @cmlines = split(/\n/, $comment_masked, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 428 | for my $entry (@RAW_BLACKLIST) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | my ($pattern, $desc) = @{$entry}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | my $lineno = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | for my $cmline (@cmlines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | $lineno++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | ▶ | if ($cmline =~ $pattern) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | push @violations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | "Perl500503Syntax::OrDie: VIOLATION at $file line $lineno:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | . " $desc\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | # Stage 3: REGEX_BLACKLIST -- content of regex literals only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # Each element of @$regex_bodies_ref is [$body_text, $line_number]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | # Escaped backslashes are first neutralised so that, for example, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | # two-character literal sequence "\\h" (an escaped backslash followed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | # by the letter h, valid in every Perl) is not mistaken for the \h | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | # horizontal-whitespace escape introduced in Perl 5.10. Backslash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | # pairs are consumed left to right, leaving a genuine escape introducer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | # intact (so "\\\h" still exposes a real \h). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 428 | my @scan_bodies; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 428 | for my $rbody (@{$regex_bodies_ref}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 2397 | my ($body_text, $body_line) = @{$rbody}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 2397 | (my $scan = $body_text) =~ s/\\\\/\0\0/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 2397 | push @scan_bodies, [$scan, $body_line]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 428 | for my $entry (@REGEX_BLACKLIST) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 5136 | my ($pattern, $desc) = @{$entry}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 5136 | for my $rbody (@scan_bodies) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 28764 | my ($body_text, $body_line) = @{$rbody}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 28764 | ▶ | if ($body_text =~ $pattern) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 39 | push @violations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | "Perl500503Syntax::OrDie: VIOLATION at $file line $body_line:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | . " $desc\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | # Stage 4: STRING_BLACKLIST -- body of interpolating string literals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | # only. Escaped backslashes are neutralised first, exactly as in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | # stage 3, so that the two-character literal sequence "\\x" (a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | # backslash written as \\ followed by the letter x, valid in every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | # Perl) is not mistaken for the \x escape introducer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 428 | my @scan_strings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 428 | for my $sbody (@{$string_bodies_ref}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 2360 | my ($body_text, $body_line) = @{$sbody}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 2360 | (my $scan = $body_text) =~ s/\\\\/\0\0/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 2360 | push @scan_strings, [$scan, $body_line]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 428 | for my $entry (@STRING_BLACKLIST) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 856 | my ($pattern, $desc) = @{$entry}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 856 | for my $sbody (@scan_strings) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 4720 | my ($body_text, $body_line) = @{$sbody}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 4720 | ▶ | if ($body_text =~ $pattern) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 4 | push @violations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | "Perl500503Syntax::OrDie: VIOLATION at $file line $body_line:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | . " $desc\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 428 | return @violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | # _mask_comments($source) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 856 | ▶ | sub _mask_comments { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mask_comments: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 856 | my ($src) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 856 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 856 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 856 | my $len = length($src); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 856 | ▶ | while ($pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 1339742 | my $ch = substr($src, $pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 1339742 | ▶ | if ($ch eq '#') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 8706 | my $end = index($src, "\n", $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 8706 | ▶ | $end = $len if $end == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 8706 | $out .= '#' . ('X' x ($end - $pos - 1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 8706 | $pos = $end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 8706 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 1331036 | ▶ | if ($ch eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 3246 | my ($rep, $len2) = _mask_dquote($src, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 3246 | $out .= substr($src, $pos, $len2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 3246 | $pos += $len2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 3246 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 1327790 | ▶ | if ($ch eq "'") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 8846 | my ($rep, $len2) = _mask_squote($src, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 8846 | $out .= substr($src, $pos, $len2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 8846 | $pos += $len2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 8846 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 1318944 | $out .= $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 1318944 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 856 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | # _mask_source($source) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | # Returns ($masked_source, \@regex_bodies). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | # Each element of @regex_bodies is [$body_text, $start_line_number]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 476 | ▶ | sub _mask_source { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mask_source: called CC=66 SCAR=42.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 476 | my ($src) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 476 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 476 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 476 | my $len = length($src); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 476 | my @regex_bodies; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | my @string_bodies; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 476 | my $in_pod = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 476 | my @pending_heredocs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 476 | ▶ | while ($pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 781499 | my $ch = substr($src, $pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | # -- flush pending heredoc bodies at the end of their line ------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | # Heredoc bodies follow, in order, the line on which their << | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | # operators appear. When that line's newline is reached, consume | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | # every queued body so that two or more heredocs sharing one line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | # (e.g. $_ = <<'A'; $x eq <<'B';) are all masked correctly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 781499 | ▶ | if ($ch eq "\n" && @pending_heredocs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ch eq "\n" and @pending_heredocs
MC/DC100%2/2
$ch eq "\n" and @pending_heredocs
$ch eq "\n"
@pending_heredocs
Truth table100%3/3
A and B
A= $ch eq "\n"B= @pending_heredocs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 45 | $out .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 45 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 45 | ▶ | while (@pending_heredocs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 50 | my $pending = shift @pending_heredocs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 50 | my $sentinel = $pending->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 50 | my $interp = $pending->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 50 | my $bodyline = 1 + _count_newlines($src, 0, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 50 | my $remain = substr($src, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 50 | my $bodylen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 50 | ▶ | if ($remain =~ /^\Q$sentinel\E[\t ]*\r?\n/m) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 50 | $bodylen = length($`) + length($&); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | elsif ($remain =~ /^\Q$sentinel\E[\t ]*\r?\z/m) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | $bodylen = length($`) + length($&); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | $bodylen = length($remain); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 50 | my $raw = substr($src, $pos, $bodylen); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 50 | ▶ | push @string_bodies, [$raw, $bodyline] if $interp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 50 | (my $masked_body = $raw) =~ s/[^\n]/X/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 50 | $out .= $masked_body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 50 | $pos += $bodylen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 45 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | # -- __END__ / __DATA__ : mask everything after this line ------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 781454 | ▶ | if ($ch eq '_' && ($pos == 0 || substr($src, $pos - 1, 1) eq "\n")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$ch eq "_" and $pos == 0 || substr($src, $pos - 1, 1) eq "\n"
$pos == 0 or substr($src, $pos - 1, 1) eq "\n"
MC/DC100%3/3
$ch eq "_" and $pos == 0 || substr($src, $pos - 1, 1) eq "\n"
$ch eq "_"
$pos == 0
substr($src, $pos - 1, 1) eq "\n"
Truth table100%4/4
A and B or C
A= $ch eq "_"B= $pos == 0C= substr($src, $pos - 1, 1) eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 29 | ▶ | if (substr($src, $pos, 7) eq '__END__' || substr($src, $pos, 8) eq '__DATA__') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
substr($src, $pos, 7) eq "__END__" or substr($src, $pos, 8) eq "__DATA__"
MC/DC100%2/2
substr($src, $pos, 7) eq "__END__" or substr($src, $pos, 8) eq "__DATA__"
substr($src, $pos, 7) eq "__END__"
substr($src, $pos, 8) eq "__DATA__"
Truth table100%3/3
A or B
A= substr($src, $pos, 7) eq "__END__"B= substr($src, $pos, 8) eq "__DATA__"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 23 | my $rest = substr($src, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 23 | $rest =~ s/[^\n]/X/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 23 | $out .= $rest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 23 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | # -- POD block ------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 781431 | ▶ | if (!$in_pod && $ch eq '=' && ($pos == 0 || substr($src, $pos - 1, 1) eq "\n")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
not $in_pod and $ch eq "=" and $pos == 0 || substr($src, $pos - 1, 1) eq "\n"
not $in_pod and $ch eq "="
$pos == 0 or substr($src, $pos - 1, 1) eq "\n"
MC/DC75%3/4
not $in_pod and $ch eq "=" and $pos == 0 || substr($src, $pos - 1, 1) eq "\n"
not $in_pod
$ch eq "="
$pos == 0
substr($src, $pos - 1, 1) eq "\n"
Truth table80%4/5
not(A) and B and C or D
A= not $in_podB= $ch eq "="C= $pos == 0D= substr($src, $pos - 1, 1) eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 9 | my $nxt = substr($src, $pos, 12); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 9 | ▶ | if ($nxt =~ /^=(head|over|item|back|pod|begin|end|for|encoding)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 5 | $in_pod = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 781431 | ▶ | if ($in_pod) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 146823 | ▶ | if ($ch eq '=' && ($pos == 0 || substr($src, $pos - 1, 1) eq "\n")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$ch eq "=" and $pos == 0 || substr($src, $pos - 1, 1) eq "\n"
$pos == 0 or substr($src, $pos - 1, 1) eq "\n"
MC/DC66%2/3
$ch eq "=" and $pos == 0 || substr($src, $pos - 1, 1) eq "\n"
$ch eq "="
$pos == 0
substr($src, $pos - 1, 1) eq "\n"
Truth table75%3/4
A and B or C
A= $ch eq "="B= $pos == 0C= substr($src, $pos - 1, 1) eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 1079 | ▶ | if (substr($src, $pos, 4) eq '=cut') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 5 | my $end2 = index($src, "\n", $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 5 | ▶ | $end2 = $len if $end2 == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 5 | $out .= 'X' x ($end2 - $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 5 | $pos = $end2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 5 | $in_pod = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 146818 | ▶ | $out .= ($ch eq "\n") ? "\n" : 'X'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 146818 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 146818 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | # -- single-line comment # ... -------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 634608 | ▶ | if ($ch eq '#') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 5395 | my $end = index($src, "\n", $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 5395 | ▶ | $end = $len if $end == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 5395 | $out .= '#' . ('X' x ($end - $pos - 1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 5395 | $pos = $end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 5395 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | # -- double-quoted string "..." -------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 629213 | ▶ | if ($ch eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 1456 | my ($rep, $len2) = _mask_dquote($src, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 1456 | push @string_bodies, [substr($src, $pos, $len2), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 1 + _count_newlines($src, 0, $pos)]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 1456 | $out .= $rep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 1456 | $pos += $len2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 1456 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | # -- single-quoted string '...' -------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 627757 | ▶ | if ($ch eq "'") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | # Old-style package separator: &jcode'tr is &jcode::tr . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | # When a sigil-led identifier ($pkg'var, &pkg'sub, *pkg'glob, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | # ...) abuts the apostrophe and a word character follows, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | # apostrophe separates package components and is NOT a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | # delimiter. Emit it verbatim so the following name is not read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | # as the start of a new string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 4036 | ▶ | my $nextc = ($pos + 1 < $len) ? substr($src, $pos + 1, 1) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 4036 | ▶ | if ($out =~ /[\$\@\%\&\*]\w*\z/ && $nextc =~ /[A-Za-z_]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$out =~ /[\$\@\%\&\*]\w*\z/ and $nextc =~ /[A-Za-z_]/
MC/DC50%1/2
$out =~ /[\$\@\%\&\*]\w*\z/ and $nextc =~ /[A-Za-z_]/
$out =~ /[\$\@\%\&\*]\w*\z/
$nextc =~ /[A-Za-z_]/
Truth table66%2/3
A and B
A= $out =~ /[\$\@\%\&\*]\w*\z/B= $nextc =~ /[A-Za-z_]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | # Emit the apostrophe together with the whole following | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | # identifier, so that a quote-like name such as the tr in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | # &jcode'tr is not subsequently read as the tr/// operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | # (the operator detector keys off the preceding character). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 5 | my $rest = substr($src, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 5 | $rest =~ /\A('(\w+))/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 5 | $out .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 5 | $pos += length($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 4031 | my ($rep, $len2) = _mask_squote($src, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 4031 | $out .= $rep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 4031 | $pos += $len2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 4031 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | # -- backtick string `...` ------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 623721 | ▶ | if ($ch eq '`') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 9 | my ($rep, $len2) = _mask_delimited($src, $pos, '`', '`'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 9 | push @string_bodies, [substr($src, $pos, $len2), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 1 + _count_newlines($src, 0, $pos)]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 9 | $out .= $rep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 9 | $pos += $len2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 9 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | # -- q{} qq{} qw{} qx{} (but NOT qr) --------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 623712 | ▶ | if ($ch eq 'q' && $pos + 1 < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ch eq "q" and $pos + 1 < $len
MC/DC50%1/2
$ch eq "q" and $pos + 1 < $len
$ch eq "q"
$pos + 1 < $len
Truth table66%2/3
A and B
A= $ch eq "q"B= $pos + 1 < $len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 2554 | my $nxt = substr($src, $pos + 1, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 2554 | ▶ | if ($nxt =~ /^[qwx]$/ && $pos + 2 < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$nxt =~ /^[qwx]$/ and $pos + 2 < $len
MC/DC50%1/2
$nxt =~ /^[qwx]$/ and $pos + 2 < $len
$nxt =~ /^[qwx]$/
$pos + 2 < $len
Truth table66%2/3
A and B
A= $nxt =~ /^[qwx]$/B= $pos + 2 < $len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 423 | my $d = substr($src, $pos + 2, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 423 | ▶ | if ($d =~ /\S/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 376 | my $cl = _matching_delim($d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 376 | my ($rep, $len2) = _mask_delimited($src, $pos + 2, $d, $cl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | # qq// and qx// interpolate; qw// does not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 376 | ▶ | push @string_bodies, [substr($src, $pos + 2, $len2), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$nxt eq "q" or $nxt eq "x"
MC/DC100%2/2
$nxt eq "q" or $nxt eq "x"
$nxt eq "q"
$nxt eq "x"
Truth table100%3/3
A or B
A= $nxt eq "q"B= $nxt eq "x"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 1 + _count_newlines($src, 0, $pos)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | if $nxt eq 'q' || $nxt eq 'x'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 376 | $out .= substr($src, $pos, 2) . $rep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 376 | $pos += 2 + $len2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 376 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | elsif ($nxt =~ /^[\{\(\[\/\|!<]$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 42 | my $cl = _matching_delim($nxt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 42 | my ($rep, $len2) = _mask_delimited($src, $pos + 1, $nxt, $cl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 42 | $out .= 'q' . $rep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 42 | $pos += 1 + $len2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 42 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | # -- heredoc start <<WORD <<"WORD" <<'WORD' ------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | # Only the operator token (<< plus the sentinel) is masked here; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | # the body is consumed when the current line's newline is reached | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | # (see the flush handler at the top of the loop). This lets two or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | # more heredocs that share a single line all be masked in order. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 623294 | ▶ | if ($ch eq '<' && $pos + 1 < $len && substr($src, $pos + 1, 1) eq '<') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$ch eq "<" and $pos + 1 < $len and substr($src, $pos + 1, 1) eq "<"
$ch eq "<" and $pos + 1 < $len
MC/DC66%2/3
$ch eq "<" and $pos + 1 < $len and substr($src, $pos + 1, 1) eq "<"
$ch eq "<"
$pos + 1 < $len
substr($src, $pos + 1, 1) eq "<"
Truth table75%3/4
A and B and C
A= $ch eq "<"B= $pos + 1 < $lenC= substr($src, $pos + 1, 1) eq "<"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 52 | my $rest = substr($src, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 52 | ▶ | if ($rest =~ /\A(<<\s*([\"']?)(\w+)\2)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 50 | my $token = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 50 | my $quote = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 50 | my $sentinel = $3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | # <<'WORD' performs no escape processing; <<WORD and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | # <<"WORD" do, so only those bodies are scanned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 50 | ▶ | push @pending_heredocs, [$sentinel, ($quote eq "'" ? 0 : 1)]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 50 | $out .= 'X' x length($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 50 | $pos += length($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 50 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | # -- Regex/subst/transliteration operators ---------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | # A quote-like operator (q/qq/qw/qx/qr/m/s/tr/y) is not recognised | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | # when the immediately preceding character is a typeglob sigil '*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | # a subroutine sigil '&', or a package-separator colon ':'; there | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | # the following word is a symbol name, not an operator -- e.g. the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | # typeglob *s in local(*s, $n) = @_; or the function name tr in a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | # package-qualified call such as mb::tr($_, 'A', '1'). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 623244 | ▶ | if ($out !~ /[\w\$\@\%*&:]\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 348977 | my $rest = substr($src, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 348977 | ▶ | if ($rest =~ /\A(qr|m(?!y(?:\b|\s*=>))|s(?!ub(?:\b|\s*\{))|tr|y)\s*([^\w\s#])/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 1089 | my $op = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 1089 | my $delim = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 1089 | my $close = _matching_delim($delim); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 1089 | my $ws = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 1089 | ▶ | if (substr($rest, length($op)) =~ /\A(\s*)([^\w\s#])/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 1089 | $ws = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 1089 | $delim = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 1089 | $close = _matching_delim($delim); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 1089 | my $op_len = length($op) + length($ws) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | # Compute line number of the start of this regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 1089 | my $cur_line = 1 + _count_newlines($src, 0, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 1089 | $pos += $op_len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 1089 | my ($body1, $blen1) = _mask_delimited_raw($src, $pos, $delim, $close); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 1089 | $pos += $blen1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 1089 | my $pat1 = substr($body1, 0, length($body1) - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 1089 | ▶ | push @regex_bodies, [$pat1, $cur_line] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$op eq "tr" or $op eq "y"
MC/DC50%1/2
$op eq "tr" or $op eq "y"
$op eq "tr"
$op eq "y"
Truth table66%2/3
A or B
A= $op eq "tr"B= $op eq "y"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | unless $op eq 'tr' || $op eq 'y'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 1089 | my $repl_len = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 1089 | ▶ | if ($op eq 's' || $op eq 'tr' || $op eq 'y') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$op eq "s" or $op eq "tr" or $op eq "y"
$op eq "s" or $op eq "tr"
MC/DC66%2/3
$op eq "s" or $op eq "tr" or $op eq "y"
$op eq "s"
$op eq "tr"
$op eq "y"
Truth table75%3/4
A or B or C
A= $op eq "s"B= $op eq "tr"C= $op eq "y"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 778 | my $delim2 = $delim; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 778 | my $close2 = $close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 778 | ▶ | if ($delim ne $close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 30 | my $gap = substr($src, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 30 | ▶ | if ($gap =~ /\A(\s*)([^\w\s])/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 30 | $pos += length($1) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 30 | $repl_len += length($1) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 30 | $delim2 = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 30 | $close2 = _matching_delim($delim2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 778 | my $repl_line = 1 + _count_newlines($src, 0, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 778 | my ($body2, $blen2) = _mask_delimited_raw($src, $pos, $delim2, $close2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | # The replacement half of s/// interpolates unless it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | # is single-quote delimited; tr/// and y/// never do. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 778 | ▶ | push @string_bodies, [$body2, $repl_line] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$op eq "s" and $delim2 ne "'"
MC/DC50%1/2
$op eq "s" and $delim2 ne "'"
$op eq "s"
$delim2 ne "'"
Truth table66%2/3
A and B
A= $op eq "s"B= $delim2 ne "'"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | if $op eq 's' && $delim2 ne "'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 778 | $pos += $blen2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 778 | $repl_len += $blen2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 1089 | my $flags = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 1089 | ▶ | if (substr($src, $pos) =~ /\A([msixpgeodualncrs]*)/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 1089 | $flags = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 1089 | $pos += length($flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 1089 | my $marker = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 1089 | ▶ | if ($flags =~ /r/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 4 | ▶ | if ($op eq 's') { $marker = '__SR__'; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 1 | ▶ | elsif ($op eq 'tr' || $op eq 'y') { $marker = '__TRR__'; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$op eq "tr" or $op eq "y"
MC/DC0%0/2
$op eq "tr" or $op eq "y"
$op eq "tr"
$op eq "y"
Truth table33%1/3
A or B
A= $op eq "tr"B= $op eq "y"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 1089 | my $raw_body = substr($src, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | $pos - length($flags) - $repl_len - $blen1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | $blen1 + $repl_len); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 1089 | (my $mbody = $ws . $raw_body) =~ s/[^\n]/X/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 1089 | $out .= $op . $mbody . $flags . $marker; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 1089 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | # -- bare /regex/ -- only in regex context ---------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | # The keyword alternation also lists the regex-first-argument list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | # operators split/grep/map: a '/' immediately following one of these | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | # barewords can only begin a pattern (e.g. split //, $str), never a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | # division, so it is treated as a regex. This keeps the empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | # pattern // in split //, ... from being misread as the Perl 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | # defined-or operator. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 622155 | ▶ | if ($ch eq '/' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ch eq "/" and $out =~ /(?:=~|!~|[=(,\{\[!&|;]|\b(?:if|while|unless|until|not|and|or|return|split|grep|map))\s*\z/s
MC/DC100%2/2
$ch eq "/" and $out =~ /(?:=~|!~|[=(,\{\[!&|;]|\b(?:if|while|unless|until|not|and|or|return|split|grep|map))\s*\z/s
$ch eq "/"
$out =~ /(?:=~|!~|[=(,\{\[!&|;]|\b(?:if|while|unless|until|not|and|or|return|split|grep|map))\s*\z/s
Truth table100%3/3
A and B
A= $ch eq "/"B= $out =~ /(?:=~|!~|[=(,\{\[!&|;]|\b(?:if|while|unless|until|not|and|or|return|split|grep|map))\s*\z/s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | $out =~ /(?:=~|!~|[=(,\{\[!&|;]|\b(?:if|while|unless|until|not|and|or|return|split|grep|map))\s*\z/s) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 1321 | my $cur_line = 1 + _count_newlines($src, 0, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 1321 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 1321 | my ($body, $blen) = _mask_delimited_raw($src, $pos, '/', '/'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 1321 | $pos += $blen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 1321 | my $pat = substr($body, 0, length($body) - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 1321 | push @regex_bodies, [$pat, $cur_line]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 1321 | my $flags = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 1321 | ▶ | if (substr($src, $pos) =~ /\A([msixpgeodualn]*)/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 1321 | $flags = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 1321 | $pos += length($flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 1321 | (my $mtext = '/' . $body) =~ s/[^\n]/X/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 1321 | $out .= $mtext . $flags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 1321 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 620834 | $out .= $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 620834 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 476 | return ($out, \@regex_bodies, \@string_bodies); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | # _count_newlines($str, $from, $to) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | # Count newline characters in $str between positions $from and $to-1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | # Used to compute line numbers from byte offsets. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | 4830 | ▶ | sub _count_newlines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_count_newlines: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 4830 | my ($str, $from, $to) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 4830 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 4830 | my $p = $from; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 4830 | ▶ | while ($p < $to) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | 226537638 | ▶ | $count++ if substr($str, $p, 1) eq "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 226537638 | $p++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 4830 | return $count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | # _mask_delimited_raw($src, $start, $open, $close) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 3188 | ▶ | sub _mask_delimited_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mask_delimited_raw: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 3188 | my ($src, $start, $open, $close) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 3188 | my $pos = $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 3188 | my $slen = length($src); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 3188 | my $depth = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 3188 | my $paired = ($open ne $close); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 3188 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 3188 | ▶ | while ($pos < $slen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 63695 | my $c = substr($src, $pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 63695 | $out .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 63695 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 63695 | ▶ | if ($c eq '\\' && $pos < $slen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c eq "\\" and $pos < $slen
MC/DC50%1/2
$c eq "\\" and $pos < $slen
$c eq "\\"
$pos < $slen
Truth table66%2/3
A and B
A= $c eq "\\"B= $pos < $slen
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 7333 | $out .= substr($src, $pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 7333 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | 7333 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 56362 | ▶ | if ($paired) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 7637 | ▶ | $depth++ if $c eq $open; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 7637 | ▶ | $depth-- if $c eq $close; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 7637 | ▶ | last if $depth == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 48725 | ▶ | last if $c eq $close; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 3188 | return ($out, $pos - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 4702 | ▶ | sub _mask_dquote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mask_dquote: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 4702 | my ($src, $start) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 4702 | my $pos = $start + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 4702 | my $len = length($src); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 4702 | my $out = '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | 4702 | ▶ | while ($pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 404329 | my $ch = substr($src, $pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 404329 | ▶ | if ($ch eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 5412 | ▶ | my $nx = ($pos + 1 < $len) ? substr($src, $pos + 1, 1) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 5412 | ▶ | $out .= ($nx eq "\n") ? "\\\n" : 'XX'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 5412 | $pos += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | elsif ($ch eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 4694 | $out .= '"'; $pos++; last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | elsif ($ch eq "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 8969 | $out .= "\n"; $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | 385254 | $out .= 'X'; $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 4702 | return ($out, $pos - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 12877 | ▶ | sub _mask_squote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mask_squote: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 12877 | my ($src, $start) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 12877 | my $pos = $start + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 12877 | my $len = length($src); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 12877 | my $out = "'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 12877 | ▶ | while ($pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 811498 | my $ch = substr($src, $pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 811498 | ▶ | if ($ch eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 5917 | ▶ | my $nx = ($pos + 1 < $len) ? substr($src, $pos + 1, 1) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 5917 | ▶ | $out .= ($nx eq "'" || $nx eq '\\') ? 'XX' : ('\\' . $nx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$nx eq "'" or $nx eq "\\"
MC/DC100%2/2
$nx eq "'" or $nx eq "\\"
$nx eq "'"
$nx eq "\\"
Truth table100%3/3
A or B
A= $nx eq "'"B= $nx eq "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 5917 | $pos += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | elsif ($ch eq "'") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | 12855 | $out .= "'"; $pos++; last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | elsif ($ch eq "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 23715 | $out .= "\n"; $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 769011 | $out .= 'X'; $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 12877 | return ($out, $pos - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | 427 | ▶ | sub _mask_delimited { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mask_delimited: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 427 | my ($src, $start, $open, $close) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 427 | my $pos = $start + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 427 | my $len = length($src); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 427 | my $depth = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 427 | my $out = $open; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | 427 | ▶ | while ($pos < $len && $depth > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pos < $len and $depth > 0
MC/DC100%2/2
$pos < $len and $depth > 0
$pos < $len
$depth > 0
Truth table100%3/3
A and B
A= $pos < $lenB= $depth > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | 18439 | my $ch = substr($src, $pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | 18439 | ▶ | if ($ch eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | 827 | $out .= 'XX'; $pos += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | ▶ | elsif ($open ne $close && $ch eq $open) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$open ne $close and $ch eq $open
MC/DC100%2/2
$open ne $close and $ch eq $open
$open ne $close
$ch eq $open
Truth table100%3/3
A and B
A= $open ne $closeB= $ch eq $open
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | 48 | $depth++; $out .= $open; $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | elsif ($ch eq $close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | 475 | $depth--; $out .= $close; $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | elsif ($ch eq "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 191 | $out .= "\n"; $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | 16898 | $out .= 'X'; $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | 427 | return ($out, $pos - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 2626 | ▶ | sub _matching_delim { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_matching_delim: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 2626 | my ($o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 2626 | ▶ | return '{' eq $o ? '}' : '(' eq $o ? ')' : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | '[' eq $o ? ']' : '<' eq $o ? '>' : $o; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | # _install_runtime_guards() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 9 | ▶ | sub _install_runtime_guards { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install_runtime_guards: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 9 | ▶ | unless ($_OPEN_GUARDED) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 7 | $_OPEN_GUARDED = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 28 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | 7 | *{'CORE::GLOBAL::open'} = \&_guarded_open; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 9 | ▶ | unless ($_MKDIR_GUARDED) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | 7 | $_MKDIR_GUARDED = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 28 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 7 | *{'CORE::GLOBAL::mkdir'} = \&_guarded_mkdir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 12 | ▶ | sub _guarded_open { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_guarded_open: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 12 | ▶ | if (@_ >= 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | 6 | my ($p, $f, $l) = caller(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 6 | die "Perl500503Syntax::OrDie: RUNTIME VIOLATION at $f line $l:\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | . " 3-argument open() is not supported in Perl 5.005_03\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 6 | ▶ | if (@_ >= 2 && ref $_[1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ >= 2 and ref $_[1]
MC/DC50%1/2
@_ >= 2 and ref $_[1]
@_ >= 2
ref $_[1]
Truth table66%2/3
A and B
A= @_ >= 2B= ref $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 2 | my ($p, $f, $l) = caller(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 2 | die "Perl500503Syntax::OrDie: RUNTIME VIOLATION at $f line $l:\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | . " open() with a reference as mode is not supported" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | . " in Perl 5.005_03\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 20 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 4 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 0 | my $ofn = 'CORE::' . 'open'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 0 | return &{$ofn}($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 4 | return CORE::open($_[0], $_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | 6 | ▶ | sub _guarded_mkdir { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_guarded_mkdir: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | 6 | ▶ | if (@_ < 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 3 | my ($p, $f, $l) = caller(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 3 | die "Perl500503Syntax::OrDie: RUNTIME VIOLATION at $f line $l:\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | . " mkdir() requires an explicit mode argument in Perl 5.005_03\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 3 | return CORE::mkdir($_[0], $_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | # Public API | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | 3 | ▶ | sub check_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_file: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 3 | my $first = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | 3 | ▶ | my $path = ($first eq 'Perl500503Syntax::OrDie' || ref $first) ? shift : $first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$first eq "Perl500503Syntax::OrDie" or ref $first
MC/DC50%1/2
$first eq "Perl500503Syntax::OrDie" or ref $first
$first eq "Perl500503Syntax::OrDie"
ref $first
Truth table66%2/3
A or B
A= $first eq "Perl500503Syntax::OrDie"B= ref $first
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 3 | my @v = _check_file($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | 3 | ▶ | if (@v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 1 | die join('', @v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | 37 | ▶ | sub check_source { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_source: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 37 | my $first = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | 37 | my ($src, $label); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | 37 | ▶ | if ($first eq 'Perl500503Syntax::OrDie' || ref $first) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$first eq "Perl500503Syntax::OrDie" or ref $first
MC/DC50%1/2
$first eq "Perl500503Syntax::OrDie" or ref $first
$first eq "Perl500503Syntax::OrDie"
ref $first
Truth table66%2/3
A or B
A= $first eq "Perl500503Syntax::OrDie"B= ref $first
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 2 | ($src, $label) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | 35 | ($src, $label) = ($first, shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 37 | my @violations = _check_source($src, $label); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 37 | return @violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | # Command-line interface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | # ====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 8 | ▶ | sub _run_as_command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_as_command: called CC=10 SCAR=23.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | 8 | ▶ | if (!@ARGV || ($ARGV[0] eq '--help') || ($ARGV[0] eq '-h')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not @ARGV or $ARGV[0] eq "--help" or $ARGV[0] eq "-h"
not @ARGV or $ARGV[0] eq "--help"
MC/DC33%1/3
not @ARGV or $ARGV[0] eq "--help" or $ARGV[0] eq "-h"
not @ARGV
$ARGV[0] eq "--help"
$ARGV[0] eq "-h"
Truth table50%2/4
not(A) or B or C
A= not @ARGVB= $ARGV[0] eq "--help"C= $ARGV[0] eq "-h"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 1 | print "Usage: perl Perl500503Syntax/OrDie.pm <file> [<file> ...]\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 1 | print " perl Perl500503Syntax/OrDie.pm -\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | 1 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 1 | print " Check each <file> for constructs not available in Perl 5.005_03.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 1 | print " Use '-' to read from standard input.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 1 | print " Violations are reported with file name and line number.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | 1 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 1 | print "Example:\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 1 | print " perl lib/Perl500503Syntax/OrDie.pm myscript.pl\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | 1 | exit 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | 7 | my $ok = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | 7 | my $fail = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | 7 | my $sep = '-' x 60; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | 7 | for my $path (@ARGV) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 8 | print "$sep\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | 8 | my @violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 8 | ▶ | if ($path eq '-') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | 0 | print "Checking: (standard input)\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | 0 | my $source = do { local $/; <STDIN> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | 0 | @violations = _check_source($source, '(stdin)'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | elsif (!-f $path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | 0 | print "ERROR: file not found: $path\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | 0 | $fail++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | 8 | print "Checking: $path\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 8 | @violations = _check_file($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | 8 | ▶ | if (@violations) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 2 | print join('', @violations); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 2 | $fail++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 6 | print " -> No violations found.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | 6 | $ok++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | 7 | print "$sep\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | 7 | my $total = $ok + $fail; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | 7 | print "Results: $ok/$total passed"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | 7 | ▶ | if ($fail) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | 2 | print ", $fail failed"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | 7 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | 7 | ▶ | exit($fail ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 12 | ▶ | _run_as_command() if $0 eq __FILE__; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||