This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
narrow the filename check in strict.pm/warnings.pm
authorAristotle Pagaltzis <pagaltzis@gmx.de>
Wed, 2 Mar 2016 02:30:30 +0000 (03:30 +0100)
committerAristotle Pagaltzis <pagaltzis@gmx.de>
Wed, 2 Mar 2016 02:30:30 +0000 (03:30 +0100)
commit67ba812d5fe08169b8a39cdc1f4945c5e08f32e1
tree3dde2d686828c844514ed565d2fd0ea32ab35a26
parentf24480bcc6bbe9061c0ff1595df8d3eadb2ab8db
narrow the filename check in strict.pm/warnings.pm

• The code previously assumed that any filename basename besides
  `strict.pm` meant that the user mistyped `use strict` (e.g. as
  `use Strict`). But that could just mean the file was not loaded
  from the filesystem, e.g. due to naïve fatpacking.

  This is fixed by adding a guard to check that an unexpected value
  really is a mis-capitalised variant of `strict.pm`.

• The code previously insisted on either slash or backslash as the
  directory separator, which is not strictly portable (though nobody
  noticed in years; apparently nobody has tried to run a recent-ish
  on a MacOS Classic or RiscOS system).

  This is fixed by switching to \b as a best effort, to avoid going
  down the rabbit hole of platform-specific separators.

• The code previously used an `unless` statement, declared lexical
  variables inside its block, and used ${\EXPR} to interpolate the
  __PACKAGE__ constant into the regexp. Each of these increases the
  size of the optree, which is only ever executed once, then sticks
  around wasting some hundred(s) bytes in almost every single Perl
  program in the world.

  This is fixed for warnings.pm by rewriting the code with no use of
  any temporary variables and single-quoted strings instead of regexp
  literals. In strict.pm, we can do even better by moving the code to
  the BEGIN block, since BEGIN CVs are freed after running. (We do not
  add one to warnings.pm since BEGIN blocks have a creation cost.)
lib/strict.pm
lib/warnings.pm
regen/warnings.pl