Perl500503Syntax-OrDie

 view release on metacpan or  search on metacpan

lib/Perl500503Syntax/OrDie.pm  view on Meta::CPAN

      "typeglob component access *name{SLOT} (introduced in Perl 5.6)" ],

    # ------------------------------------------------------------------
    # Perl 5.8 features
    # ------------------------------------------------------------------

    # use encoding
    [ qr/\buse\s+encoding\b/,
      "'use encoding' (introduced in Perl 5.8)" ],

    # use constant with a hashref (hash of constants)  -- Perl 5.8
    # Single-value form  use constant NAME => VALUE  is 5.004+, always OK.
    # Hash-ref form  use constant { A => 1, B => 2 }  was added in Perl 5.8.
    [ qr/\buse\s+constant\s*\{/,
      "'use constant { HASH }' multi-constant form (introduced in Perl 5.8; use separate 'use constant' statements)" ],

    # ------------------------------------------------------------------
    # Perl 5.10 features
    # ------------------------------------------------------------------

    # defined-or-assignment operator
    [ do { my $p = '/' . '/='; qr/$p/ },
      "defined-or assignment '" . '/' . "/=' (introduced in Perl 5.10)" ],

    # say HANDLE or say LIST
    # Exclude ->say(...) method calls and say => hash-key usage
    [ do { my $kw = 'sa' . 'y'; qr/(?<!->)\b$kw\b(?!\s*=>)/ },
      "'say' (introduced in Perl 5.10)" ],

    # sta-te $var
    [ do { my $kw = 'sta' . 'te'; qr/\b$kw\s+[\$\@\%]/ },
      "'sta" . "te' variable (introduced in Perl 5.10)" ],

    # given(...)
    [ qr/\bgiven\s*\(/,
      "'given' (introduced in Perl 5.10)" ],

    # when(...)
    [ qr/\bwhen\s*\(/,
      "'when' (introduced in Perl 5.10)" ],

    # smart-match ~~
    [ qr/~~/,
      "smart-match operator '~~' (introduced in Perl 5.10)" ],

    # use feature
    # The empty-import form  use feature ()  imports nothing and, when paired
    # with a  BEGIN { $INC{'feature.pm'} = '' if $] < 5.010 }  stub, loads
    # nothing on Perl 5.005_03.  It is a no-op on every Perl version and is the
    # standard cross-version guard idiom (parallel to the tolerated
    # use warnings stub), so it is NOT a violation.  A non-empty import list
    # such as  use feature 'say'  or  use feature qw(...)  still is.
    [ qr/\buse\s+feature\b(?!\s*\(\s*\))/,
      "'use feature' (introduced in Perl 5.10)" ],

    # defined-or operator (two slashes, not part of s///, m//, =~, !~)
    # and not the defined-or-assign variant
    [ qr/(?<![=~!])\s\/\/(?!=)/,
      "defined-or operator (introduced in Perl 5.10)" ],

    # UNITCHECK phase block
    [ qr/\bUNITCHECK\s*\{/,
      "UNITCHECK phase block (introduced in Perl 5.10)" ],

    # ${^MATCH} ${^PREMATCH} ${^POSTMATCH} (used with /p flag -- 5.10)
    [ qr/\$\{\^(?:MATCH|PREMATCH|POSTMATCH)\}/,
      "\${^MATCH}/\${^PREMATCH}/\${^POSTMATCH} (introduced in Perl 5.10; require /p flag)" ],

    # ------------------------------------------------------------------
    # Perl 5.12 features
    # ------------------------------------------------------------------

    # package NAME VERSION
    [ qr/\bpackage\s+\w[\w:]*\s+v?\d/,
      "'package NAME VERSION' (introduced in Perl 5.12)" ],

    # yada-yada operator ...  (not to be confused with .. range)
    [ do { my $p = '\\.' x 3; qr/(?<!\\.)$p(?!\\.)/ },
      "yada-yada operator '...' (introduced in Perl 5.12)" ],

    # ------------------------------------------------------------------
    # Perl 5.14 features
    # ------------------------------------------------------------------

    # /r (non-destructive) flag on s/// or tr///
    # _mask_source emits __SR__ or __TRR__ marker when r flag is present.
    [ qr/__SR__|__TRR__/,
      "s///r or tr///r non-destructive flag (introduced in Perl 5.14)" ],

    # ------------------------------------------------------------------
    # Perl 5.16 features
    # ------------------------------------------------------------------

    # __SUB__ token (reference to the current subroutine)
    [ qr/__SUB__/,
      "__SUB__ (introduced in Perl 5.16; use explicit sub name or \$_[0] recursion)" ],

    # ------------------------------------------------------------------
    # Perl 5.18 features
    # ------------------------------------------------------------------

    # my sub NAME / state sub NAME -- lexical subroutines (Perl 5.18)
    [ do { my $kw = 'su' . 'b'; qr/\b(?:my|state)\s+$kw\s+\w/ },
      "'my sub'/'state sub' lexical subroutine (introduced in Perl 5.18)" ],

    # ------------------------------------------------------------------
    # Perl 5.20 features
    # ------------------------------------------------------------------

    # subroutine signatures: sub foo ($x, $y) {  (Perl 5.20)
    [ qr/\bsub\s+\w+\s*\([^\)]*(?<!\\)[\$\@\%][a-zA-Z_][^\)]*\)\s*\{/,
      "subroutine signature (introduced in Perl 5.20)" ],

    # postfix dereference  $ref->@*  $ref->%*  $ref->&*
    [ qr/->\s*[\@\%\&\$]\s*\*/,
      "postfix dereference (introduced in Perl 5.20)" ],

    # %hash{LIST} and %array[LIST]  key/value (index/value) slices  (Perl 5.20)
    # Exclude plain %hash alone (no subscript) and %hash = (...) assignment.
    # Require preceding context that cannot be an assignment target start.
    [ qr/(?:[\(=,;!&|?:]|\breturn\b)\s*\%\w[\w:]*\s*[\{\[]/,
      "key/value hash/array slice %hash{} or %array[] (introduced in Perl 5.20)" ],

lib/Perl500503Syntax/OrDie.pm  view on Meta::CPAN


=item C<check_file($path)>

Reads C<$path> and calls C<check_source>.  Dies with the violation
list if any violations are found; returns normally otherwise.

=back

=head1 CHECKED CONSTRUCTS

=head2 Static checks (compile time, via source scan)

=over 4

=item * C<our> declaration -- Perl 5.6

=item * 3-argument C<open()> -- Perl 5.6

=item * C<use utf8> -- Perl 5.6

=item * C<use VERSION> where VERSION E<gt>= 5.6

=item * C<use vVERSION> where VERSION E<gt>= v5.6

=item * C<\x{HHHH}> Unicode escape -- Perl 5.6

=item * C<\N{name}> named character escape -- Perl 5.6

=item * Match-position arrays C<@+>/C<@-> and C<$+[N]>/C<$-[N]> -- Perl 5.6

=item * C<CHECK>/C<INIT> phase blocks -- Perl 5.6

=item * v-string notation (C<v1.2.3>) -- Perl 5.6

=item * C<$^V> version object -- Perl 5.6

=item * C<:lvalue> subroutine attribute -- Perl 5.6

=item * Typeglob component access C<*name{SLOT}> -- Perl 5.6

=item * C<use encoding> -- Perl 5.8

=item * C<use constant { HASH }> multi-constant form -- Perl 5.8

=item * defined-or assignment operator C<//=> -- Perl 5.10

=item * C<say> -- Perl 5.10 (C<-E<gt>say()> method calls and C<say =E<gt>> hash keys excluded)

=item * C<state variable> -- Perl 5.10

=item * C<given>/C<when> -- Perl 5.10

=item * Smart-match C<~~> -- Perl 5.10

=item * C<use feature> -- Perl 5.10
(the empty-import form C<use feature ()> is a no-op on every Perl version
and is treated as compatible)

=item * Defined-or operator C<//> (standalone) -- Perl 5.10

=item * C<UNITCHECK> phase block -- Perl 5.10

=item * C<${^MATCH}>/C<${^PREMATCH}>/C<${^POSTMATCH}> -- Perl 5.10

=item * C<package NAME VERSION> -- Perl 5.12

=item * Yada-yada C<...> -- Perl 5.12

=item * C<s///r> or C<tr///r> non-destructive flag -- Perl 5.14

=item * C<__SUB__> token -- Perl 5.16

=item * C<my sub>/C<state sub> lexical subroutine -- Perl 5.18

=item * Subroutine signatures -- Perl 5.20

=item * Postfix dereference C<$ref-E<gt>@*> -- Perl 5.20

=item * C<%hash{LIST}>/C<%array[LIST]> key/value slices -- Perl 5.20

=item * C<&.> C<|.> C<^.> C<~.> string bitwise operators -- Perl 5.22

=item * Reference aliasing in C<foreach> -- Perl 5.22

=item * C<E<lt>E<lt>E<gt>E<gt>> double-diamond operator -- Perl 5.22

=item * C</n> non-capturing regex flag -- Perl 5.22

=item * C<E<lt>E<lt>~> indented heredoc -- Perl 5.26

=item * C<isa> infix operator -- Perl 5.32 (C<-E<gt>isa()> method calls and C<isa()> function calls excluded)

=item * C<try> block -- Perl 5.34

=item * C<use builtin> -- Perl 5.36

=item * C<for my ($a,$b)> paired iteration -- Perl 5.36

=item * C<class> keyword -- Perl 5.38

=item * C<^^>/C<^^=> high-precedence logical XOR -- Perl 5.40

=item * C<__CLASS__> keyword -- Perl 5.40

=item * C<any BLOCK LIST>/C<all BLOCK LIST> keyword operators -- Perl 5.42
(suppressed when C<List::Util> imports C<any>/C<all>)

=item * C<my method> lexical method declaration -- Perl 5.42

=item * C<-E<gt>&name> lexical method call -- Perl 5.42

=item * Possessive quantifiers C<a++>/C<a*+>/C<a?+> in code -- Perl 5.10

=item * C<\p{}>C<\P{}> Unicode property escapes in regex -- Perl 5.6

=item * C<\K> (keep) in regex -- Perl 5.10

=item * Named capture C<(?E<lt>nameE<gt>...)> and C<\kE<lt>nameE<gt>> -- Perl 5.10

=item * Branch reset C<(?|...)> in regex -- Perl 5.10



( run in 2.011 seconds using v1.01-cache-2.11-cpan-9581c071862 )