# Perltidy Change Log
-## 2020 01 10.01
+## 2020 06 19
- Added support for Switch::Plain syntax, issue git #31.
- Added --character-encoding=guess or -guess to have perltidy guess
if a file (or other input stream) is encoded as -utf8 or some
- older single-byte encoding. This is useful when processing a mixture
- of file types, such as utf8 and latin-1.
+ other single-byte encoding. This is useful when processing a mixture
+ of file types, such as utf8 and latin-1.
Please Note: The default encoding has been set to be 'guess'
- instead of 'none'. I do not like to change defaults, but this seems like
- the best choice, since it should make perltidy work properly with both
+ instead of 'none'. This seems like the best default, since
+ it allows perltidy work properly with both
utf8 files and older latin-1 files. The guess mode uses Encode::Guess,
which is included in standard perl distributions, and only tries to
guess if a file is utf8 or not, never any other encoding. If the guess is
utf8, and if the file successfully decodes as utf8, then it the encoding
- is assumed to be utf8. Otherwise, no encoding is assumed. I have done
- extensive testing and have not detected any problems with this
- rather conservative guess method, so I think it is a good default.
+ is assumed to be utf8. Otherwise, no encoding is assumed.
If you do not want to use this new default guess mode, or have a
problem with it, you can set --character-encoding=none (the previous
default) or --character-encoding=utf8 (if you deal with utf8 files).
- Specific encodings of input files other than utf8 may now be given, for
- example --character-encoding=euc-jp.
+ example --character-encoding=euc-jp.
- Fix for git#22, Preserve function signature on a single line. An
unwanted line break was being introduced when a closing signature paren
examples/perlcomment.pl
examples/perllinetype.pl
examples/perlmask.pl
-examples/perltidy.DEBUG
examples/perltidy_okw.pl
examples/perltidyrc_dump.pl
examples/perlxmltok.pl
# any zip files
\.zip$
-# Perl::Tidy error, log and tidy files
-\bperltidy\.ERR
-\bperltidy\.LOG
+# any Perl::Tidy error, log and tidy files
+\.ERR$
+\.LOG$
+\.DEBUG$
# The temporary combined perltidy.pl made by pm2pl
\bperltidy-.*\.pl
=head1 VERSION
-This man page documents perltidy version 20200110.01
+This man page documents perltidy version 20200619
=head1 BUG REPORTS
<h1>Perltidy Change Log</h1>
-<h2>2020 01 10.01</h2>
+<h2>2020 06 19</h2>
-<pre><code>- Fixed minor problem where trailing 'unless' clauses were not
+<pre><code>- Added support for Switch::Plain syntax, issue git #31.
+
+- Fixed minor problem where trailing 'unless' clauses were not
getting vertically aligned.
- Added a parameter --logical-padding or -lop to allow logical padding
- Added --character-encoding=guess or -guess to have perltidy guess
if a file (or other input stream) is encoded as -utf8 or some
- older single-byte encoding. This is useful when processing a mixture
- of file types, such as utf8 and latin-1.
+ other single-byte encoding. This is useful when processing a mixture
+ of file types, such as utf8 and latin-1.
Please Note: The default encoding has been set to be 'guess'
- instead of 'none'. I do not like to change defaults, but this seems like
- the best choice, since it should make perltidy work properly with both
+ instead of 'none'. This seems like the best default, since
+ it allows perltidy work properly with both
utf8 files and older latin-1 files. The guess mode uses Encode::Guess,
which is included in standard perl distributions, and only tries to
guess if a file is utf8 or not, never any other encoding. If the guess is
utf8, and if the file successfully decodes as utf8, then it the encoding
- is assumed to be utf8. Otherwise, no encoding is assumed. I have done
- extensive testing and have not detected any problems with this
- rather conservative guess method, so I think it is a good default.
+ is assumed to be utf8. Otherwise, no encoding is assumed.
If you do not want to use this new default guess mode, or have a
problem with it, you can set --character-encoding=none (the previous
default) or --character-encoding=utf8 (if you deal with utf8 files).
- Specific encodings of input files other than utf8 may now be given, for
- example --character-encoding=euc-jp.
+ example --character-encoding=euc-jp.
- Fix for git#22, Preserve function signature on a single line. An
unwanted line break was being introduced when a closing signature paren
<h1 id="VERSION">VERSION</h1>
-<p>This man page documents Perl::Tidy version 20200110.01</p>
+<p>This man page documents Perl::Tidy version 20200619</p>
<h1 id="LICENSE">LICENSE</h1>
$self->balance( $self->balance + $amount );
}</code></pre>
+<p>For one of the extensions, module Switch::Plain, colons are marked as labels. If you use this module, you may want to also use the <b>--nooutdent-labels</b> flag to prevent lines such as 'default:' from being outdented.</p>
+
<p>This flag is enabled by default but it can be deactivated with <b>-nxs</b>. Probably the only reason to deactivate this flag is to generate more diagnostic messages when debugging a script.</p>
</dd>
<p>The value given to <b>-ci</b> is also used by some commands when a small space is required. Examples are commands for outdenting labels, <b>-ola</b>, and control keywords, <b>-okw</b>.</p>
-<p>When default values are not used, it is suggested that the value <b>n</b> given with <b>-ci=n</b> be no more than about one-half of the number of spaces assigned to a full indentation level on the <b>-i=n</b> command.</p>
+<p>When default values are not used, it is highly recommended that the value <b>n</b> given with <b>-ci=n</b> be no more than about one-half of the number of spaces assigned to a full indentation level on the <b>-i=n</b> command. The reason is that discontinuities in the definition and control of continuation indentation arise in complex code, and this rule helps to smooth out these discontinuities.</p>
</dd>
<dt id="sil-n---starting-indentation-level-n"><b>-sil=n</b> <b>--starting-indentation-level=n</b></dt>
<dt id="Note:-Perltidy-does-always-follow-whitespace-controls">Note: Perltidy does always follow whitespace controls</dt>
<dd>
-<p>The various parameters controlling whitespace within a program are requests which perltidy follows as well as possible, but there are a number of situations where changing whitespace could change program behavior and is not done. Examples are whitespace around bareword symbols and possible filehandles. For example, consider the problem of formatting the following subroutine:</p>
+<p>The various parameters controlling whitespace within a program are requests which perltidy follows as well as possible, but there are a number of situations where changing whitespace could change program behavior and is not done. Some of these are obvious; for example, we should not remove the space between the two plus symbols in '$x+ +$y' to avoid creating a '++' operator. Some are more subtle and involve the whitespace around bareword symbols and locations of possible filehandles. For example, consider the problem of formatting the following subroutine:</p>
<pre><code> sub print_div {
my ($x,$y)=@_;
print $x /$y;
}</code></pre>
-<p>If formatted in this way, the program will not run (at least with recent versions of perl) because the / is assumed to start a quote. In a complex program, there might happen to be a / which terminates the multiline quote without a syntax error, allowing the program to run, but incorrectly.</p>
+<p>If formatted in this way, the program will not run (at least with recent versions of perl) because the $x is taken to be a filehandle and / is assumed to start a quote. In a complex program, there might happen to be a / which terminates the multiline quote without a syntax error, allowing the program to run, but incorrectly.</p>
-<p>Related issues arise with other binary operator symbols, such as + and -, and in older versions of perl there could be problems with ternary operators. So to avoid changing program behavior, perltidy has the simple rule that whitespace around possible filehandles is left unchanged. Likewise, whitespace around barewords is left unchanged.</p>
+<p>Related issues arise with other binary operator symbols, such as + and -, and in older versions of perl there could be problems with ternary operators. So to avoid changing program behavior, perltidy has the simple rule that whitespace around possible filehandles is left unchanged. Likewise, whitespace around barewords is left unchanged. The reason is that if the barewords are defined in other modules, or in code that has not even been written yet, perltidy will not have seen their prototypes and must treat them cautiously.</p>
</dd>
<dt id="Space-between-specific-keywords-and-opening-paren">Space between specific keywords and opening paren</dt>
<p>When an opening paren follows a Perl keyword, no space is introduced after the keyword, unless it is (by default) one of these:</p>
-<pre><code> my local our and or eq ne if else elsif until unless
+<pre><code> my local our and or xor eq ne if else elsif until unless
while for foreach return switch case given when</code></pre>
<p>These defaults can be modified with two commands:</p>
<h2 id="Controlling-List-Formatting">Controlling List Formatting</h2>
-<p>Perltidy attempts to format lists of comma-separated values in tables which look good. Its default algorithms usually work well, but sometimes parameters available to control list formatting. In this case, there are several methods available to control list formatting.</p>
+<p>Perltidy attempts to format lists of comma-separated values in tables which look good. Its default algorithms usually work well, but sometimes they don't. In this case, there are several methods available to control list formatting.</p>
<p>A very simple way to prevent perltidy from changing the line breaks within a comma-separated list of values is to insert a blank line, comment, or side-comment anywhere between the opening and closing parens (or braces or brackets). This causes perltidy to skip over its list formatting logic. (The reason is that any of these items put a constraint on line breaks, and perltidy needs complete control over line breaks within a container to adjust a list layout). For example, let us consider</p>
<h1 id="VERSION">VERSION</h1>
-<p>This man page documents perltidy version 20200110.01</p>
+<p>This man page documents perltidy version 20200619</p>
<h1 id="BUG-REPORTS">BUG REPORTS</h1>
# Release version must be bumped, and it is probably past time for a
# release anyway.
- $VERSION = '20200110.01';
+ $VERSION = '20200619';
}
sub streamhandle {
=head1 VERSION
-This man page documents Perl::Tidy version 20200110.01
+This man page documents Perl::Tidy version 20200619
=head1 LICENSE
package Perl::Tidy::Debugger;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
sub new {
package Perl::Tidy::DevNull;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
sub new { my $self = shift; return bless {}, $self }
sub print { return }
sub close { return }
package Perl::Tidy::Diagnostics;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
sub new {
package Perl::Tidy::FileWriter;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
# Maximum number of little messages; probably need not be changed.
my $MAX_NAG_MESSAGES = 6;
use strict;
use warnings;
use Carp;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
# The Tokenizer will be loaded with the Formatter
##use Perl::Tidy::Tokenizer; # for is_keyword()
}
elsif ( $type eq 'k' ) {
- # Keywords 'for', 'foreach' are special cases for -kpit since the
- # opening paren does not always immediately follow the keyword. So
- # we have to search forward for the paren in this case. I have
+ # Keywords 'for', 'foreach' are special cases for -kpit since the
+ # opening paren does not always immediately follow the keyword. So
+ # we have to search forward for the paren in this case. I have
# limited the search to 10 tokens ahead, just in case somebody
# has a big file and no opening paren. This should be enough for
# all normal code.
# token
if ( $pad_spaces < 0 ) {
- # Deactivated for -kpit due to conflict. This block deletes
- # a space in an attempt to improve alignment in some cases,
- # but it may conflict with user spacing requests. For now
- # it is just deactivated if the -kpit option is used.
+ # Deactivated for -kpit due to conflict. This block deletes
+ # a space in an attempt to improve alignment in some cases,
+ # but it may conflict with user spacing requests. For now
+ # it is just deactivated if the -kpit option is used.
if ( $pad_spaces == -1 ) {
if ( $ipad > $ibeg
&& $types_to_go[ $ipad - 1 ] eq 'b'
package Perl::Tidy::HtmlWriter;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
use File::Basename;
use strict;
use warnings;
use Carp;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
sub new {
my ( $package, $rscalar, $mode ) = @_;
use strict;
use warnings;
use Carp;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
sub new {
my ( $package, $rarray, $mode ) = @_;
package Perl::Tidy::IndentationItem;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
sub new {
package Perl::Tidy::LineBuffer;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
sub new {
package Perl::Tidy::LineSink;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
sub new {
package Perl::Tidy::LineSource;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
sub new {
package Perl::Tidy::Logger;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
sub new {
package Perl::Tidy::Tokenizer;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
use Perl::Tidy::LineBuffer;
package Perl::Tidy::VerticalAligner;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
use Perl::Tidy::VerticalAligner::Alignment;
use Perl::Tidy::VerticalAligner::Line;
# look for excessively long lines
my $max_excess = 0;
foreach my $item (@group_lines) {
- my ($str, $str_len) = @{$item};
+ my ( $str, $str_len ) = @{$item};
my $excess =
$str_len +
$leading_space_count -
my $k = 0;
my $jdel_next = $ridel->[$k];
- if ( $jdel_next < 0 ) { return } # shouldnt happen
+ if ( $jdel_next < 0 ) { return } # shouldnt happen
my $pattern = $rpatterns_old->[0];
my $field = $rfields_old->[0];
my $field_length = $rfield_lengths_old->[0];
my ( $raw_tok, $lev, $tag, $tok_count ) =
decode_alignment_token($new_list_type);
- # But for lines with leading commas, we will require that they be
- # tagged before converting a line from non-list to a list.
+ # But for lines with leading commas, we will require that they be
+ # tagged before converting a line from non-list to a list.
if ($tag) {
for ( my $i = 1 ; $i < @{$rtokens_new} - 1 ; $i++ ) {
if ( $rtokens_new->[$i] !~ /^(,|=>)/ ) {
foreach my $line ( @{$rnew_lines} ) {
my $rhash = {};
my $rtokens = $line->get_rtokens();
- if ( !$saw_list_type && $line->get_list_type() ) { $saw_list_type = 1}
- my $i = 0;
+ if ( !$saw_list_type && $line->get_list_type() ) { $saw_list_type = 1 }
+ my $i = 0;
my $i_eq;
my $lev_min;
foreach my $tok ( @{$rtokens} ) {
return;
}
-{ # fix_ragged_matches
+{ # fix_ragged_matches
my %is_comma_or_comment;
my $BLOCK_MERGE_RATIO;
@q = ( ',', '=>', '#' );
@is_comma_or_comment{@q} = (1) x scalar(@q);
- # This fraction controls merges. Only merge a long block into a shorter
- # block if the ratio of the number of lines is less than this ratio.
- # The idea is to avoid merging away a significant block that would
- # otherwise be aligned. This is not a critical parameter. Some
- # testing showed that it is best between about 0.3 and 0.5. The
- # original test snippet, git25, worked best with a value >=0.35.
- $BLOCK_MERGE_RATIO = 0.5;
+ # This fraction controls merges. Only merge a long block into a shorter
+ # block if the ratio of the number of lines is less than this ratio.
+ # The idea is to avoid merging away a significant block that would
+ # otherwise be aligned. This is not a critical parameter. Some
+ # testing showed that it is best between about 0.3 and 0.5. The
+ # original test snippet, git25, worked best with a value >=0.35.
+ $BLOCK_MERGE_RATIO = 0.5;
# Debug flag
$EXPLAIN = 0;
# which can be improved by adjusting alignments.
# TODO: This version only treats lists. It might be generalized
- # to handle more types of matches.
+ # to handle more types of matches.
#########################################################
# Step 1. Start by scanning the lines and collecting info
my $list_type = $line->get_list_type();
# No matches if there is a group ending flag set between these lines
- my $end_group = ( $jj_m >= 0 && $rlines->[$jj_m]->{_end_group} );
+ my $end_group = ( $jj_m >= 0 && $rlines->[$jj_m]->{_end_group} );
# Also skip past a non-list line; we are working on pure lists here
if ( $end_group || !$list_type ) {
# imax_match = index of maximum alignment token for lines in this batch.
# This value applies to matches between all lines j=jbeg to jend and
# j=jbeg-1 to jend-1. In other words, the value for a pair of lines
- # is stored with the line with the higher index.
+ # is stored with the line with the higher index.
my $imatch = -10;
my $j_last_line = @{$rlines} - 1;
my %counts;
# Now delete the unused alignment tokens
- # NOTE: We are currently only working on lists, so we can allow
- # lines to be promoted as lists. But if this coding is generalized
- # this flag may have to be adjusted to handle or non-lists.
- my $new_list_ok = 1;
+ # NOTE: We are currently only working on lists, so we can allow
+ # lines to be promoted as lists. But if this coding is generalized
+ # this flag may have to be adjusted to handle or non-lists.
+ my $new_list_ok = 1;
if ( $imax_match_j < $imax ) {
my @idel = ( $imax_match_j + 1 .. $imax );
}
}
-{ # decide_if_aligned_pair
+{ # decide_if_aligned_pair
my %is_if_or;
my %is_assignment;
package Perl::Tidy::VerticalAligner::Alignment;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
{
package Perl::Tidy::VerticalAligner::Line;
use strict;
use warnings;
-our $VERSION = '20200110.01';
+our $VERSION = '20200619';
{