NAME

Perl::Critic::PJCJ::Fixer - automatically fix RequireConsistentQuoting violations

VERSION

version v0.3.0

SYNOPSIS

use Perl::Critic::PJCJ::Fixer;

my $fixer = Perl::Critic::PJCJ::Fixer->new;
my $fixed = $fixer->fix($source);

DESCRIPTION

This module rewrites Perl source so that it satisfies Perl::Critic::Policy::ValuesAndExpressions::RequireConsistentQuoting. It never decides for itself what to change: it runs the policy over the parsed document and rewrites only the tokens the policy flags, computing each replacement so that the runtime value of every string is preserved.

Source that the policy accepts, including all surrounding whitespace and comments, is passed through byte for byte.

METHODS

new

Create a new fixer.

fix ($source, %opts)

Take Perl source as a string and return the fixed source. Source that cannot be parsed is returned unchanged. Fixing repeats until no further changes are needed, since one fix can enable the next suggestion.

Source receiving no applied fix is returned byte for byte, and a file using CRLF line endings throughout keeps them. A file with mixed line endings is normalised to LF when a fix applies.

Each violation from the policy carries its own structured fix, which the fixer uses directly; for other violation sources it falls back to the policy's fix_data lookup keyed on the description. A violation with no fix by either route is reported once on standard error and left unchanged.

A repeating or non-converging sequence of fixes is reported on standard error and the current state returned.

The lines option restricts fixes to elements starting within an inclusive line range, while still parsing the whole document:

my $fixed = $fixer->fix($source, lines => [ 10, 20 ]);

AUTHOR

Paul Johnson <paul@pjcj.net>

LICENCE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.