From 5a118059274436956f4939357a0893bb41eac1f2 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 6 Mar 2023 17:50:20 -0800 Subject: [PATCH] update version number This will be the next release to CPAN after testing is complete. --- CHANGES.md | 9 +- bin/perltidy | 15 +- docs/ChangeLog.html | 133 ++++++++ docs/Tidy.html | 2 +- docs/perltidy.html | 343 ++++++++++++++------- lib/Perl/Tidy.pm | 23 +- lib/Perl/Tidy.pod | 2 +- lib/Perl/Tidy/Debugger.pm | 2 +- lib/Perl/Tidy/DevNull.pm | 2 +- lib/Perl/Tidy/Diagnostics.pm | 2 +- lib/Perl/Tidy/FileWriter.pm | 2 +- lib/Perl/Tidy/Formatter.pm | 4 +- lib/Perl/Tidy/HtmlWriter.pm | 2 +- lib/Perl/Tidy/IOScalar.pm | 2 +- lib/Perl/Tidy/IOScalarArray.pm | 2 +- lib/Perl/Tidy/IndentationItem.pm | 2 +- lib/Perl/Tidy/LineBuffer.pm | 2 +- lib/Perl/Tidy/LineSink.pm | 2 +- lib/Perl/Tidy/LineSource.pm | 2 +- lib/Perl/Tidy/Logger.pm | 2 +- lib/Perl/Tidy/Tokenizer.pm | 2 +- lib/Perl/Tidy/VerticalAligner.pm | 2 +- lib/Perl/Tidy/VerticalAligner/Alignment.pm | 2 +- lib/Perl/Tidy/VerticalAligner/Line.pm | 2 +- local-docs/Release-Checklist.md | 3 +- 25 files changed, 391 insertions(+), 175 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 22490835..eb36279f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # Perltidy Change Log -## 2022 11 12.05 +## 2023 03 09 - No significant bugs have been found since the last release to CPAN. Several minor issues have been fixed, and some new parameters have been @@ -11,7 +11,7 @@ into one-line blocks. This implements the issue raised in PR #111. The list s may include any of the words 'sort map grep eval', or it may be '*' to indicate all of these. So for example to prevent - multi-line 'eval' blocks from becomming one-line blocks, the command + multi-line 'eval' blocks from becoming one-line blocks, the command would be -olbxl='eval'. - For the -b (--backup-and-modify-in-place) option, the file timestamps @@ -129,9 +129,8 @@ input parameters. No failures to converge, internal fault checks, undefined variable references or other irregularities were seen. - - This version runs about 4 percent faster than the previous - release on large files due to optimizations made with the help of - Devel::NYTProf. + - This version runs a few percent faster than the previous release on + large files due to optimizations made with the help of Devel::NYTProf. ## 2022 11 12 diff --git a/bin/perltidy b/bin/perltidy index 84e05fdf..73801af9 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -2720,7 +2720,7 @@ must either (1) be adjacent as in the above example, or (2) have an anonymous sub declaration following an outer opening container symbol which is not a code block brace, or (3) have an outer opening paren separated from the inner opening symbol by any single non-container symbol or something that looks like -a function evaluation, as illustrated in the next examples. An additonal +a function evaluation, as illustrated in the next examples. An additional option (4) which can be turned on with the flag B<--weld-fat-comma> is when the opening container symbols are separated by a hash key and fat comma (=>). Any container symbol may serve as both the inner container of one pair and as @@ -2835,7 +2835,7 @@ last represents a quoted list. For example the string -wnxl='[ { q' -means do B include square-bracets, braces, or quotes in any welds. The only unspecified +means do B include square-brackets, braces, or quotes in any welds. The only unspecified container is '(', so this string means that only welds involving parens will be made. To illustrate, following welded snippet consists of a chain of three welded @@ -3616,7 +3616,7 @@ can be useful on a temporary basis for reformatting a script. If the closing tokens of two nested containers are separated by a comma, then welding requested with B<--weld-nested-containers> cannot occur. Any commas in this situation are optional trailing commas and can be removed with B<-dwic>. -For example, a comma in this scipt prevents welding: +For example, a comma in this script prevents welding: # perltidy -wn skip_symbols( @@ -4411,7 +4411,7 @@ blocks for certain block types. This flag allows the user to prevent this behav include any of the words C, C, C, C, or it may be C<*> to indicate all of these. -So for example to prevent multi-line B blocks from becomming one-line +So for example to prevent multi-line B blocks from becoming one-line blocks, the command would be B<-olbxl='eval'>. In this case, existing one-line B blocks will remain on one-line if possible, and existing multi-line B blocks will remain multi-line blocks. @@ -5090,7 +5090,8 @@ a few symbols for special block types, as follows: closure - any nameless block In addition, specific block loop types which are nested in other loops can be -selected by adding a B<+> after the block name. +selected by adding a B<+> after the block name. (Nested loops are sometimes +good candidates for restructuring). The default is B<-dbt='sub'>. @@ -5117,7 +5118,7 @@ are inner loops. perltidy -dbs -dbl=2 -dbt='sub +' somefile.pl >blocks.csv =item * -This selectes every block and package. +This selects every block and package. perltidy -dbs -dbl=1 -dbt='* closure' somefile.pl >blocks.csv @@ -5557,7 +5558,7 @@ The perltidy binary uses the Perl::Tidy module and is installed when that module =head1 VERSION -This man page documents perltidy version 20221112.05 +This man page documents perltidy version 20230309 =head1 BUG REPORTS diff --git a/docs/ChangeLog.html b/docs/ChangeLog.html index f64cf1d9..e3aaf087 100644 --- a/docs/ChangeLog.html +++ b/docs/ChangeLog.html @@ -1,5 +1,138 @@

Perltidy Change Log

+

2023 03 09

+ +
- No significant bugs have been found since the last release to CPAN.
+  Several minor issues have been fixed, and some new parameters have been
+  added, as follows:
+
+- Added parameter --one-line-block-exclusion-list=s, or -olbxl=s, where
+  s is a list of block types which should not automatically be turned
+  into one-line blocks.  This implements the issue raised in PR #111.
+  The list s may include any of the words 'sort map grep eval', or
+  it may be '*' to indicate all of these.  So for example to prevent
+  multi-line 'eval' blocks from becomming one-line blocks, the command
+  would be -olbxl='eval'.
+
+- For the -b (--backup-and-modify-in-place) option, the file timestamps
+  are changing (git #113, rt#145999).  First, if there are no formatting
+  changes to an input file, it will keep its original modification time.
+  Second, any backup file will keep its original modification time.  This
+  was previously true for --backup-method=move but not for the default
+  --backup-method=copy.  The purpose of these changes is to avoid
+  triggering Makefile operations when there are no actual file changes.
+  If this causes a problem please open an issue for discussion on github.
+
+- A change was made to the way line breaks are made at the '.'
+  operator when the user sets -wba='.' to requests breaks after a '.'
+  ( this setting is not recommended because it can be hard to read ).
+  The goal of the change is to make switching from breaks before '.'s
+  to breaks after '.'s just move the dots from the end of
+  lines to the beginning of lines.  For example:
+
+        # default and recommended (--want-break-before='.'):
+        $output_rules .=
+          (     'class'
+              . $dir
+              . '.stamp: $('
+              . $dir
+              . '_JAVA)' . "\n" . "\t"
+              . '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) '
+              . '$(JAVACFLAGS) $?' . "\n" . "\t"
+              . 'echo timestamp > class'
+              . $dir
+              . '.stamp'
+              . "\n" );
+
+        # perltidy --want-break-after='.'
+        $output_rules .=
+          ( 'class' .
+              $dir .
+              '.stamp: $(' .
+              $dir .
+              '_JAVA)' . "\n" . "\t" .
+              '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) ' .
+              '$(JAVACFLAGS) $?' . "\n" . "\t" .
+              'echo timestamp > class' .
+              $dir .
+              '.stamp' .
+              "\n" );
+
+  For existing code formatted with -wba='.', this may cause some
+  changes in the formatting of code with long concatenation chains.
+
+- Added option --use-feature=class, or -uf=class, for issue rt #145706.
+  This adds keywords 'class', 'method', 'field', and 'ADJUST' in support of
+  this feature which is being tested for future inclusion in Perl.
+  An effort has been made to avoid conflicts with past uses of these
+  words, especially 'method' and 'class'. The default setting
+  is --use-feature=class. If this causes a conflict, this option can
+  be turned off by entering -uf=' '.
+
+  In other words, perltidy should work for both old and new uses of
+  these keywords with the default settings, but this flag is available
+  if a conflict arises.
+
+- Added option -bfvt=n, or --brace-follower-vertical-tightness=n,
+  for part of issue git #110.  For n=2, this option looks for lines
+  which would otherwise be, by default,
+
+  }
+    or ..
+
+  and joins them into a single line
+
+  } or ..
+
+  where the or can be one of a number of logical operators or if unless.
+  The default is not to do this and can be indicated with n=1.
+
+- Added option -cpb, or --cuddled-paren-brace, for issue git #110.
+  This option will cause perltidy to join two lines which
+  otherwise would be, by default,
+
+    )
+  {
+
+  into a single line
+
+  ) {
+
+- Some minor changes to existing formatted output may occur as a result
+  of fixing minor formatting issues with edge cases.  This is especially
+  true for code which uses the -lp or -xlp styles.
+
+- Added option -dbs, or --dump-block-summary, to dump summary
+  information about code blocks in a file to standard output.
+  The basic command is:
+
+      perltidy -dbs somefile.pl >blocks.csv
+
+  Instead of formatting ``somefile.pl``, this dumps the following
+  comma-separated items describing its blocks to the standard output:
+
+   filename     - the name of the file
+   line         - the line number of the opening brace of this block
+   line_count   - the number of lines between opening and closing braces
+   code_lines   - the number of lines excluding blanks, comments, and pod
+   type         - the block type (sub, for, foreach, ...)
+   name         - the block name if applicable (sub name, label, asub name)
+   depth        - the nesting depth of the opening block brace
+   max_change   - the change in depth to the most deeply nested code block
+   block_count  - the total number of code blocks nested in this block
+   mccabe_count - the McCabe complexity measure of this code block
+
+  This can be useful for code restructuring. The man page for perltidy
+  has more information and describes controls for selecting block types.
+
+- This version was stress-tested for over 100 cpu hours with random
+  input parameters. No failures to converge, internal fault checks,
+  undefined variable references or other irregularities were seen.
+
+- This version runs a few percent faster than the previous release on
+  large files due to optimizations made with the help of Devel::NYTProf.
+
+

2022 11 12

- Fix rt #145095, undef warning in Perl before 5.12. Version 20221112 is
diff --git a/docs/Tidy.html b/docs/Tidy.html
index f81e2786..400318fd 100644
--- a/docs/Tidy.html
+++ b/docs/Tidy.html
@@ -401,7 +401,7 @@
 
 

VERSION

-

This man page documents Perl::Tidy version 20221112

+

This man page documents Perl::Tidy version 20230309

LICENSE

diff --git a/docs/perltidy.html b/docs/perltidy.html index 70df09d2..b8fa37f4 100644 --- a/docs/perltidy.html +++ b/docs/perltidy.html @@ -37,7 +37,9 @@
  • Retaining or Ignoring Existing Line Breaks
  • Blank Line Control
  • Styles
  • +
  • One-Line Blocks
  • Controlling Vertical Alignment
  • +
  • Extended Syntax
  • Other Controls
  • @@ -75,7 +77,7 @@

    DESCRIPTION

    -

    Perltidy reads a perl script and writes an indented, reformatted script. This document describes the parameters available for controlling this formatting.

    +

    Perltidy reads a perl script and writes an indented, reformatted script. The formatting process involves converting the script into a string of tokens, removing any non-essential whitespace, and then rewriting the string of tokens with whitespace using whatever rules are specified, or defaults. This happens in a series of operations which can be controlled with the parameters described in this document.

    Perltidy is a commandline frontend to the module Perl::Tidy. For documentation describing how to call the Perl::Tidy module from other applications see the separate documentation for Perl::Tidy. It is the file Perl::Tidy.pod in the source distribution.

    @@ -332,48 +334,6 @@

    This flag asserts that the input and output code streams are different, or in other words that the input code is 'untidy' according to the formatting parameters. If this is not the case, an error message noting this is produced. This flag has no other effect on the functioning of perltidy.

    - -
    -sal=s, --sub-alias-list=s
    -
    - -

    This flag causes one or more words to be treated the same as if they were the keyword 'sub'. The string s contains one or more alias words, separated by spaces or commas.

    - -

    For example,

    - -
            perltidy -sal='method fun _sub M4'
    - -

    will cause the perltidy to treat the words 'method', 'fun', '_sub' and 'M4' the same as if they were 'sub'. Note that if the alias words are separated by spaces then the string of words should be placed in quotes.

    - -

    Note that several other parameters accept a list of keywords, including 'sub' (see "Specifying Block Types"). You do not need to include any sub aliases in these lists. Just include keyword 'sub' if you wish, and all aliases are automatically included.

    - -
    -
    -gal=s, --grep-alias-list=s
    -
    - -

    This flag allows a code block following an external 'list operator' function to be formatted as if it followed one of the built-in keywords grep, map or sort. The string s contains the names of one or more such list operators, separated by spaces or commas.

    - -

    By 'list operator' is meant a function which is invoked in the form

    - -
          word {BLOCK} @list
    - -

    Perltidy tries to keep code blocks for these functions intact, since they are usually short, and does not automatically break after the closing brace since a list may follow. It also does some special handling of continuation indentation.

    - -

    For example, the code block arguments to functions 'My_grep' and 'My_map' can be given formatting like 'grep' with

    - -
            perltidy -gal='My_grep My_map'
    - -

    By default, the following list operators in List::Util are automatically included:

    - -
          all any first none notall reduce reductions
    - -

    Any operators specified with --grep-alias-list are added to this list. The next parameter can be used to remove words from this default list.

    - -
    -
    -gaxl=s, --grep-alias-exclusion-list=s
    -
    - -

    The -gaxl=s flag provides a method for removing any of the default list operators given above by listing them in the string s. To remove all of the default operators use -gaxl='*'.

    -
    @@ -466,24 +426,6 @@ - -
    -xs, --extended-syntax
    -
    - -

    A problem with formatting Perl code is that some modules can introduce new syntax. This flag allows perltidy to handle certain common extensions to the standard syntax without complaint.

    - -

    For example, without this flag a structure such as the following would generate a syntax error and the braces would not be balanced:

    - -
        method deposit( Num $amount) {
    -        $self->balance( $self->balance + $amount );
    -    }
    - -

    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 --nooutdent-labels flag to prevent lines such as 'default:' from being outdented.

    - -

    This flag is enabled by default but it can be deactivated with -nxs. Probably the only reason to deactivate this flag is to generate more diagnostic messages when debugging a script.

    - -

    For another method of handling extended syntax see the section "Skipping Selected Sections of Code".

    -
    -io, --indent-only
    @@ -1194,7 +1136,7 @@

    You will probably also want to use the flag -skp (previous item) too.

    -

    The reason this is not recommended is that spacing a function paren can make a program vulnerable to parsing problems by Perl. For example, the following two-line program will run as written but will have a syntax error if reformatted with -sfp:

    +

    The parameter is not recommended because spacing a function paren can make a program vulnerable to parsing problems by Perl. For example, the following two-line program will run as written but will have a syntax error if reformatted with -sfp:

      if ( -e filename() ) { print "I'm here\n"; }
       sub filename { return $0 }
    @@ -2205,7 +2147,7 @@ next if $x == $y; } } until $x++ > $z;
    -

    When this flag is set perltidy makes a preliminary pass through the file and identifies all nested pairs of containers. To qualify as a nested pair, the closing container symbols must be immediately adjacent and the opening symbols must either (1) be adjacent as in the above example, or (2) have an anonymous sub declaration following an outer opening container symbol which is not a code block brace, or (3) have an outer opening paren separated from the inner opening symbol by any single non-container symbol or something that looks like a function evaluation, as illustrated in the next examples. An additonal option (4) which can be turned on with the flag --weld-fat-comma is when the opening container symbols are separated by a hash key and fat comma (=>).

    +

    When this flag is set perltidy makes a preliminary pass through the file and identifies all nested pairs of containers. To qualify as a nested pair, the closing container symbols must be immediately adjacent and the opening symbols must either (1) be adjacent as in the above example, or (2) have an anonymous sub declaration following an outer opening container symbol which is not a code block brace, or (3) have an outer opening paren separated from the inner opening symbol by any single non-container symbol or something that looks like a function evaluation, as illustrated in the next examples. An additional option (4) which can be turned on with the flag --weld-fat-comma is when the opening container symbols are separated by a hash key and fat comma (=>).

    Any container symbol may serve as both the inner container of one pair and as the outer container of an adjacent pair. Consequently, any number of adjacent opening or closing symbols may join together in weld. For example, here are three levels of wrapped function calls:

    @@ -2295,7 +2237,7 @@
      -wnxl='[ { q'
    -

    means do NOT include square-bracets, braces, or quotes in any welds. The only unspecified container is '(', so this string means that only welds involving parens will be made.

    +

    means do NOT include square-brackets, braces, or quotes in any welds. The only unspecified container is '(', so this string means that only welds involving parens will be made.

    To illustrate, following welded snippet consists of a chain of three welded containers with types '(' '[' and 'q':

    @@ -2718,7 +2660,7 @@
    -mft=n, --maximum-fields-per-table=n
    -

    If the computed number of fields for any table exceeds n, then it will be reduced to n. The default value for n is a large number, 40. While this value should probably be left unchanged as a general rule, it might be used on a small section of code to force a list to have a particular number of fields per line, and then either the -boc flag could be used to retain this formatting, or a single comment could be introduced somewhere to freeze the formatting in future applications of perltidy.

    +

    If n is a positive number, and the computed number of fields for any table exceeds n, then it will be reduced to n. This parameter might be used on a small section of code to force a list to have a particular number of fields per line, and then either the -boc flag could be used to retain this formatting, or a single comment could be introduced somewhere to freeze the formatting in future applications of perltidy. For example

        # perltidy -mft=2
         @month_of_year = (
    @@ -2730,6 +2672,8 @@
             'Nov', 'Dec'
         );
    +

    The default value is n=0, which does not place a limit on the number of fields in a table.

    +
    -cab=n, --comma-arrow-breakpoints=n
    @@ -2904,7 +2848,7 @@
    -dwic, --delete-weld-interfering-commas
    -

    If the closing tokens of two nested containers are separated by a comma, then welding requested with --weld-nested-containers cannot occur. Any commas in this situation are optional trailing commas and can be removed with -dwic. For example, a comma in this scipt prevents welding:

    +

    If the closing tokens of two nested containers are separated by a comma, then welding requested with --weld-nested-containers cannot occur. Any commas in this situation are optional trailing commas and can be removed with -dwic. For example, a comma in this script prevents welding:

        # perltidy -wn
         skip_symbols(
    @@ -3462,7 +3406,7 @@
     
     

    Please note that this parameter set includes -st and -se flags, which make perltidy act as a filter on one file only. These can be overridden by placing -nst and/or -nse after the -pbp parameter.

    -

    Also note that the value of continuation indentation, -ci=4, is equal to the value of the full indentation, -i=4. It is recommended that the either (1) the parameter -ci=2 be used instead, or the flag -xci be set. This will help show structure, particularly when there are ternary statements. The following snippet illustrates these options.

    +

    Also note that the value of continuation indentation, -ci=4, is equal to the value of the full indentation, -i=4. It is recommended that the either (1) the parameter -ci=2 be used instead, or (2) the flag -xci be set. This will help show structure, particularly when there are ternary statements. The following snippet illustrates these options.

        # perltidy -pbp
         $self->{_text} = (
    @@ -3502,48 +3446,52 @@
     

    The -xci flag was developed after the -pbp parameters were published so you need to include it separately.

    -
    One-line blocks
    -
    + -

    There are a few points to note regarding one-line blocks. A one-line block is something like this,

    +

    One-Line Blocks

    + +

    A one-line block is a block of code where the contents within the curly braces is short enough to fit on a single line. For example,

        if ( -e $file ) { print "'$file' exists\n" }
    -

    where the contents within the curly braces is short enough to fit on a single line.

    +

    The alternative, a block which spans multiple lines, is said to be a broken block. With few exceptions, perltidy retains existing one-line blocks, if it is possible within the line-length constraint, but it does not attempt to form new ones. In other words, perltidy will try to follow the input file regarding broken and unbroken blocks.

    -

    With few exceptions, perltidy retains existing one-line blocks, if it is possible within the line-length constraint, but it does not attempt to form new ones. In other words, perltidy will try to follow the one-line block style of the input file.

    +

    The main exception to this rule is that perltidy will attempt to form new one-line blocks following the keywords map, eval, and sort, eval, because these code blocks are often small and most clearly displayed in a single line. This behavior can be controlled with the flag --one-line-block-exclusion-list described below.

    -

    If an existing one-line block is longer than the maximum line length, however, it will be broken into multiple lines. When this happens, perltidy checks for and adds any optional terminating semicolon (unless the -nasc option is used) if the block is a code block.

    +

    When the cuddled-else style is used, the default treatment of one-line blocks may interfere with the cuddled style. In this case, the default behavior may be changed with the flag --cuddled-break-option=n described elsehwere.

    -

    The main exception is that perltidy will attempt to form new one-line blocks following the keywords map, eval, and sort, because these code blocks are often small and most clearly displayed in a single line.

    +

    When an existing one-line block is longer than the maximum line length, and must therefore be broken into multiple lines, perltidy checks for and adds any optional terminating semicolon (unless the -nasc option is used) if the block is a code block.

    -

    One-line block rules can conflict with the cuddled-else option. When the cuddled-else option is used, perltidy retains existing one-line blocks, even if they do not obey cuddled-else formatting.

    +
    -

    Occasionally, when one-line blocks get broken because they exceed the available line length, the formatting will violate the requested brace style. If this happens, reformatting the script a second time should correct the problem.

    +
    -olbxl=s, --one-line-block-exclusion-list=s
    +
    -

    Sometimes it might be desirable to convert a script to have one-line blocks whenever possible. Although there is currently no flag for this, a simple workaround is to execute perltidy twice, once with the flag -noadd-newlines and then once again with normal parameters, like this:

    +

    As noted above, perltidy will, by default, attempt to create new one-line blocks for certain block types. This flag allows the user to prevent this behavior for the block types listed in the string s. The list s may include any of the words sort, map, grep, eval, or it may be * to indicate all of these.

    -
         cat infile | perltidy -nanl | perltidy >outfile
    +

    So for example to prevent multi-line eval blocks from becoming one-line blocks, the command would be -olbxl='eval'. In this case, existing one-line eval blocks will remain on one-line if possible, and existing multi-line eval blocks will remain multi-line blocks.

    -

    When executed on this snippet

    +
    +
    -olbn=n, --one-line-block-nesting=n
    +
    -
        if ( $? == -1 ) {
    -        die "failed to execute: $!\n";
    -    }
    -    if ( $? == -1 ) {
    -        print "Had enough.\n";
    -        die "failed to execute: $!\n";
    -    }
    +

    Nested one-line blocks are lines with code blocks which themselves contain code blocks. For example, the following line is a nested one-line block.

    -

    the result is

    +
             foreach (@list) { if ($_ eq $asked_for) { last } ++$found }
    -
        if ( $? == -1 ) { die "failed to execute: $!\n"; }
    -    if ( $? == -1 ) {
    -        print "Had enough.\n";
    -        die "failed to execute: $!\n";
    +

    The default behavior is to break such lines into multiple lines, but this behavior can be controlled with this flag. The values of n are:

    + +
      n=0 break nested one-line blocks into multiple lines [DEFAULT]
    +  n=1 stable: keep existing nested-one line blocks intact
    + +

    For the above example, the default formatting (-olbn=0) is

    + +
        foreach (@list) {
    +        if ( $_ eq $asked_for ) { last }
    +        ++$found;
         }
    -

    This shows that blocks with a single statement become one-line blocks.

    +

    If the parameter -olbn=1 is given, then the line will be left intact if it is a single line in the source, or it will be broken into multiple lines if it is broken in multiple lines in the source.

    -olbs=n, --one-line-block-semicolons=n
    @@ -3558,26 +3506,40 @@

    Note that the n=2 option has no effect if adding semicolons is prohibited with the -nasc flag. Also not that while n=2 adds missing semicolons to all one-line blocks, regardless of complexity, the n=0 option only removes ending semicolons which terminate one-line blocks containing just one semicolon. So these two options are not exact inverses.

    -
    -olbn=n, --one-line-block-nesting=n
    +
    Forming new one-line blocks
    -

    Nested one-line blocks are lines with code blocks which themselves contain code blocks. For example, the following line is a nested one-line block.

    +

    Sometimes it might be desirable to convert a script to have one-line blocks whenever possible. Although there is currently no flag for this, a simple workaround is to execute perltidy twice, once with the flag -noadd-newlines and then once again with normal parameters, like this:

    -
             foreach (@list) { if ($_ eq $asked_for) { last } ++$found }
    +
         cat infile | perltidy -nanl | perltidy >outfile
    -

    The default behavior is to break such lines into multiple lines, but this behavior can be controlled with this flag. The values of n are:

    +

    When executed on this snippet

    -
      n=0 break nested one-line blocks into multiple lines [DEFAULT]
    -  n=1 stable: keep existing nested-one line blocks intact
    +
        if ( $? == -1 ) {
    +        die "failed to execute: $!\n";
    +    }
    +    if ( $? == -1 ) {
    +        print "Had enough.\n";
    +        die "failed to execute: $!\n";
    +    }
    -

    For the above example, the default formatting (-olbn=0) is

    +

    the result is

    -
        foreach (@list) {
    -        if ( $_ eq $asked_for ) { last }
    -        ++$found;
    +
        if ( $? == -1 ) { die "failed to execute: $!\n"; }
    +    if ( $? == -1 ) {
    +        print "Had enough.\n";
    +        die "failed to execute: $!\n";
         }
    -

    If the parameter -olbn=1 is given, then the line will be left intact if it is a single line in the source, or it will be broken into multiple lines if it is broken in multiple lines in the source.

    +

    This shows that blocks with a single statement become one-line blocks.

    + +
    +
    Breaking existing one-line blocks
    +
    + +

    There is no automatic way to break existing long one-line blocks into multiple lines, but this can be accomplished by processing a script, or section of a script, with a short value of the parameter maximum-line-length=n. Then, when the script is reformatted again with the normal parameters, the blocks which were broken will remain broken (with the exceptions noted above).

    + +

    Another trick for doing this for certain block types is to format one time with the -cuddled-else flag and --cuddled-break-option=2. Then format again with the normal parameters. This will break any one-line blocks which are involved in a cuddled-else style.

    @@ -3701,6 +3663,80 @@ +

    Extended Syntax

    + +

    This section describes some parameters for dealing with extended syntax.

    + +

    For another method of handling extended syntax see the section "Skipping Selected Sections of Code".

    + +

    Also note that the module Perl::Tidy supplies a pre-filter and post-filter capability. This requires calling the module from a separate program rather than through the binary perltidy.

    + +
    + +
    -xs, --extended-syntax
    +
    + +

    This flag allows perltidy to handle certain common extensions to the standard syntax without complaint.

    + +

    For example, without this flag a structure such as the following would generate a syntax error:

    + +
        Method deposit( Num $amount) {
    +        $self->balance( $self->balance + $amount );
    +    }
    + +

    This flag is enabled by default but it can be deactivated with -nxs. Probably the only reason to deactivate this flag is to generate more diagnostic messages when debugging a script.

    + +
    +
    -sal=s, --sub-alias-list=s
    +
    + +

    This flag causes one or more words to be treated the same as if they were the keyword sub. The string s contains one or more alias words, separated by spaces or commas.

    + +

    For example,

    + +
            perltidy -sal='method fun _sub M4'
    + +

    will cause the perltidy to treat the words 'method', 'fun', '_sub' and 'M4' the same as if they were 'sub'. Note that if the alias words are separated by spaces then the string of words should be placed in quotes.

    + +

    Note that several other parameters accept a list of keywords, including 'sub' (see "Specifying Block Types"). You do not need to include any sub aliases in these lists. Just include keyword 'sub' if you wish, and all aliases are automatically included.

    + +
    +
    -gal=s, --grep-alias-list=s
    +
    + +

    This flag allows a code block following an external 'list operator' function to be formatted as if it followed one of the built-in keywords grep, map or sort. The string s contains the names of one or more such list operators, separated by spaces or commas.

    + +

    By 'list operator' is meant a function which is invoked in the form

    + +
          word {BLOCK} @list
    + +

    Perltidy tries to keep code blocks for these functions intact, since they are usually short, and does not automatically break after the closing brace since a list may follow. It also does some special handling of continuation indentation.

    + +

    For example, the code block arguments to functions 'My_grep' and 'My_map' can be given formatting like 'grep' with

    + +
            perltidy -gal='My_grep My_map'
    + +

    By default, the following list operators in List::Util are automatically included:

    + +
          all any first none notall reduce reductions
    + +

    Any operators specified with --grep-alias-list are added to this list. The next parameter can be used to remove words from this default list.

    + +
    +
    -gaxl=s, --grep-alias-exclusion-list=s
    +
    + +

    The -gaxl=s flag provides a method for removing any of the default list operators given above by listing them in the string s. To remove all of the default operators use -gaxl='*'.

    + +
    +
    -uf=s, --use-feature=s
    +
    + +

    This flag tells perltidy to allow the syntax associated a pragma in string s. Currently only the recognized values for the string are s='class' or string s=' '. The default is --use-feature='class'. This enables perltidy to recognized the special words class, method, field, and ADJUST. If this causes a conflict with other uses of these words, the default can be turned off with --use-feature=' '.

    + +
    +
    +

    Other Controls

    @@ -3891,6 +3927,73 @@

    -DEBUG will write a file with extension .DEBUG for each input file showing the tokenization of all lines of code.

    + +
    Making a table of information on code blocks
    +
    + +

    A table listing information about the blocks of code in a file can be made with --dump-block-summary, or -dbs. This causes perltidy to read and parse the file, write a table of comma-separated values for selected code blocks to the standard output, and then exit. This parameter must be on the command line, not in a .perlticyrc file, and it requires a single file name on the command line. For example

    + +
       perltidy -dbs somefile.pl >blocks.csv
    + +

    produces an output file blocks.csv whose lines hold these parameters:

    + +
        filename     - the name of the file
    +    line         - the line number of the opening brace of this block
    +    line_count   - the number of lines between opening and closing braces
    +    code_lines   - the number of lines excluding blanks, comments, and pod
    +    type         - the block type (sub, for, foreach, ...)
    +    name         - the block name if applicable (sub name, label, asub name)
    +    depth        - the nesting depth of the opening block brace
    +    max_change   - the change in depth to the most deeply nested code block
    +    block_count  - the total number of code blocks nested in this block
    +    mccabe_count - the McCabe complexity measure of this code block
    + +

    This feature was developed to help identify complex sections of code as an aid in refactoring. The McCabe complexity measure follows the definition used by Perl::Critic. By default the table contains these values for subroutines, but the user may request them for any or all blocks of code or packages. For blocks which are loops nested within loops, a postfix '+' to the type is added to indicate possible code complexity. Although the table does not otherwise indicate which blocks are nested in other blocks, this can be determined by computing and comparing the block ending line numbers.

    + +

    By default the table lists subroutines with more than 20 code_lines, but this can be changed with the following two parameters:

    + +

    --dump-block-minimum-lines=n, or -dbl=n, where n is the minimum number of code_lines to be included. The default is -n=20. Note that code_lines is the number of lines excluding and comments, blanks and pod.

    + +

    --dump-block-types=s, or -dbt=s, where string s is a list of block types to be included. The type of a block is either the name of the perl builtin keyword for that block (such as sub if elsif else for foreach ..) or the word immediately before the opening brace. In addition, there are a few symbols for special block types, as follows:

    + +
       if elsif else for foreach ... any keyword introducing a block
    +   sub  - any sub or anynomous sub
    +   asub - any anonymous sub
    +   *    - any block except nameless blocks
    +   +    - any nested inner block loop
    +   package - any package or class
    +   closure - any nameless block
    + +

    In addition, specific block loop types which are nested in other loops can be selected by adding a + after the block name. (Nested loops are sometimes good candidates for restructuring).

    + +

    The default is -dbt='sub'.

    + +

    In the following examples a table block.csv is created for a file somefile.pl:

    + +
      + +
    • This selects both subs and packages which have 20 or more lines of code. This can be useful in code which contains multiple packages.

      + +
          perltidy -dbs -dbt='sub package' somefile.pl >blocks.csv
      + +
    • +
    • This selects block types sub for foreach while with 10 or more code lines.

      + +
          perltidy -dbs -dbl=10 -dbt='sub for foreach while' somefile.pl >blocks.csv
      + +
    • +
    • This selects blocks with 2 or more code lines which are type sub or which are inner loops.

      + +
          perltidy -dbs -dbl=2 -dbt='sub +' somefile.pl >blocks.csv
      + +
    • +
    • This selects every block and package.

      + +
          perltidy -dbs -dbl=1 -dbt='* closure' somefile.pl >blocks.csv
      + +
    • +
    +
    Working with MakeMaker, AutoLoader and SelfLoader
    @@ -4121,22 +4224,22 @@
     D      anl    asbl   asc    ast    asu    atc    atnl   aws    b
      baa    baao   bar    bbao   bbb    bbc    bbs    bl     bli    boa
    - boc    bok    bol    bom    bos    bot    cblx   ce     conv   cs
    - csc    cscb   cscw   dac    dbc    dcbl   dcsc   ddf    dln    dnl
    - dop    dp     dpro   drc    dsc    dsm    dsn    dtc    dtt    dwic
    - dwls   dwrs   dws    eos    f      fll    fpva   frm    fs     fso
    - gcs    hbc    hbcm   hbco   hbh    hbhh   hbi    hbj    hbk    hbm
    - hbn    hbp    hbpd   hbpu   hbq    hbs    hbsc   hbv    hbw    hent
    - hic    hicm   hico   hih    hihh   hii    hij    hik    him    hin
    - hip    hipd   hipu   hiq    his    hisc   hiv    hiw    hsc    html
    - ibc    icb    icp    iob    isbc   iscl   kgb    kgbd   kgbi   kis
    - lal    log    lop    lp     lsl    mem    nib    ohbr   okw    ola
    - olc    oll    olq    opr    opt    osbc   osbr   otr    ple    pod
    - pvl    q      sac    sbc    sbl    scbb   schb   scp    scsb   sct
    - se     sfp    sfs    skp    sob    sobb   sohb   sop    sosb   sot
    - ssc    st     sts    t      tac    tbc    toc    tp     tqw    trp
    - ts     tsc    tso    vbc    vc     vmll   vsc    w      wfc    wn
    - x      xci    xlp    xs
    + boc bok bol bom bos bot cblx ce conv cpb + cs csc cscb cscw dac dbc dbs dcbl dcsc ddf + dln dnl dop dp dpro drc dsc dsm dsn dtc + dtt dwic dwls dwrs dws eos f fll fpva frm + fs fso gcs hbc hbcm hbco hbh hbhh hbi hbj + hbk hbm hbn hbp hbpd hbpu hbq hbs hbsc hbv + hbw hent hic hicm hico hih hihh hii hij hik + him hin hip hipd hipu hiq his hisc hiv hiw + hsc html ibc icb icp iob isbc iscl kgb kgbd + kgbi kis lal log lop lp lsl mem nib ohbr + okw ola olc oll olq opr opt osbc osbr otr + ple pod pvl q sac sbc sbl scbb schb scp + scsb sct se sfp sfs skp sob sobb sohb sop + sosb sot ssc st sts t tac tbc toc tp + tqw trp ts tsc tso vbc vc vmll vsc w + wfc wn x xci xlp xs

    Equivalently, the prefix 'no' or 'no-' on the corresponding long names may be used.

    @@ -4214,7 +4317,7 @@

    VERSION

    -

    This man page documents perltidy version 20221112

    +

    This man page documents perltidy version 20230309

    BUG REPORTS

    diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 1093b786..63cfdb33 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -113,7 +113,7 @@ BEGIN { # then the Release version must be bumped, and it is probably past time for # a release anyway. - $VERSION = '20221112.05'; + $VERSION = '20230309'; } ## end BEGIN sub DESTROY { @@ -2996,19 +2996,6 @@ sub make_logfile_header { return $msg; } ## end sub make_logfile_header -sub write_logfile_header { - my ( - $rOpts, $logger_object, $config_file, - $rraw_options, $Windows_type, $readable_options - ) = @_; - - my $msg = make_logfile_header( $rOpts, $config_file, - $rraw_options, $Windows_type, $readable_options ); - - $logger_object->write_logfile_entry($msg); - return; -} ## end sub write_logfile_header - sub generate_options { ###################################################################### @@ -4787,14 +4774,6 @@ EOS return ( $os eq "2000" && $major != 5 ) ? "NT4" : $os; } ## end sub Win_OS_Type -sub is_unix { - return - ( $OSNAME !~ /win32|dos/i ) - && ( $OSNAME ne 'VMS' ) - && ( $OSNAME ne 'OS2' ) - && ( $OSNAME ne 'MacOS' ); -} ## end sub is_unix - sub look_for_Windows { # determine Windows sub-type and location of diff --git a/lib/Perl/Tidy.pod b/lib/Perl/Tidy.pod index 864111f5..5a48feac 100644 --- a/lib/Perl/Tidy.pod +++ b/lib/Perl/Tidy.pod @@ -475,7 +475,7 @@ The module 'Perl::Tidy' comes with a binary 'perltidy' which is installed when t =head1 VERSION -This man page documents Perl::Tidy version 20221112.05 +This man page documents Perl::Tidy version 20230309 =head1 LICENSE diff --git a/lib/Perl/Tidy/Debugger.pm b/lib/Perl/Tidy/Debugger.pm index fa89f9a0..457da0d5 100644 --- a/lib/Perl/Tidy/Debugger.pm +++ b/lib/Perl/Tidy/Debugger.pm @@ -8,7 +8,7 @@ package Perl::Tidy::Debugger; use strict; use warnings; use English qw( -no_match_vars ); -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; use constant EMPTY_STRING => q{}; use constant SPACE => q{ }; diff --git a/lib/Perl/Tidy/DevNull.pm b/lib/Perl/Tidy/DevNull.pm index bb41468a..7253a6bb 100644 --- a/lib/Perl/Tidy/DevNull.pm +++ b/lib/Perl/Tidy/DevNull.pm @@ -7,7 +7,7 @@ package Perl::Tidy::DevNull; use strict; use warnings; -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; sub new { my $self = shift; return bless {}, $self } sub print { return } sub close { return } diff --git a/lib/Perl/Tidy/Diagnostics.pm b/lib/Perl/Tidy/Diagnostics.pm index 6b27ec31..847a1f04 100644 --- a/lib/Perl/Tidy/Diagnostics.pm +++ b/lib/Perl/Tidy/Diagnostics.pm @@ -21,7 +21,7 @@ package Perl::Tidy::Diagnostics; use strict; use warnings; use English qw( -no_match_vars ); -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; use constant EMPTY_STRING => q{}; diff --git a/lib/Perl/Tidy/FileWriter.pm b/lib/Perl/Tidy/FileWriter.pm index 6f1dc96d..834d1adf 100644 --- a/lib/Perl/Tidy/FileWriter.pm +++ b/lib/Perl/Tidy/FileWriter.pm @@ -7,7 +7,7 @@ package Perl::Tidy::FileWriter; use strict; use warnings; -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; use constant DEVEL_MODE => 0; use constant EMPTY_STRING => q{}; diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 211bfa0f..b762fa32 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -18682,9 +18682,9 @@ EOM $rhash->{_optimization_on} = 1; if (DEBUG_RECOMBINE) { my $num_compares = $rhash->{_num_compares}; - my $num_joints = @ix_list; + my $pair_count = @ix_list; print STDERR -"Entering optimization phase at $num_compares compares, remaining joints = $num_joints\n"; +"Entering optimization phase at $num_compares compares, pair count = $pair_count\n"; } } } diff --git a/lib/Perl/Tidy/HtmlWriter.pm b/lib/Perl/Tidy/HtmlWriter.pm index ecd940ad..02acb00a 100644 --- a/lib/Perl/Tidy/HtmlWriter.pm +++ b/lib/Perl/Tidy/HtmlWriter.pm @@ -7,7 +7,7 @@ package Perl::Tidy::HtmlWriter; use strict; use warnings; -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; use English qw( -no_match_vars ); use File::Basename; diff --git a/lib/Perl/Tidy/IOScalar.pm b/lib/Perl/Tidy/IOScalar.pm index 8a78e6d5..66b674b2 100644 --- a/lib/Perl/Tidy/IOScalar.pm +++ b/lib/Perl/Tidy/IOScalar.pm @@ -10,7 +10,7 @@ package Perl::Tidy::IOScalar; use strict; use warnings; use Carp; -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; use constant EMPTY_STRING => q{}; diff --git a/lib/Perl/Tidy/IOScalarArray.pm b/lib/Perl/Tidy/IOScalarArray.pm index 339582f2..3894cc44 100644 --- a/lib/Perl/Tidy/IOScalarArray.pm +++ b/lib/Perl/Tidy/IOScalarArray.pm @@ -14,7 +14,7 @@ package Perl::Tidy::IOScalarArray; use strict; use warnings; use Carp; -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; sub AUTOLOAD { diff --git a/lib/Perl/Tidy/IndentationItem.pm b/lib/Perl/Tidy/IndentationItem.pm index c1c788ae..55390821 100644 --- a/lib/Perl/Tidy/IndentationItem.pm +++ b/lib/Perl/Tidy/IndentationItem.pm @@ -8,7 +8,7 @@ package Perl::Tidy::IndentationItem; use strict; use warnings; -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; BEGIN { diff --git a/lib/Perl/Tidy/LineBuffer.pm b/lib/Perl/Tidy/LineBuffer.pm index c0192547..7665e37e 100644 --- a/lib/Perl/Tidy/LineBuffer.pm +++ b/lib/Perl/Tidy/LineBuffer.pm @@ -12,7 +12,7 @@ package Perl::Tidy::LineBuffer; use strict; use warnings; -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; sub AUTOLOAD { diff --git a/lib/Perl/Tidy/LineSink.pm b/lib/Perl/Tidy/LineSink.pm index 4db6a4cd..6516a987 100644 --- a/lib/Perl/Tidy/LineSink.pm +++ b/lib/Perl/Tidy/LineSink.pm @@ -8,7 +8,7 @@ package Perl::Tidy::LineSink; use strict; use warnings; -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; sub AUTOLOAD { diff --git a/lib/Perl/Tidy/LineSource.pm b/lib/Perl/Tidy/LineSource.pm index 7a9dbd50..8bf97b91 100644 --- a/lib/Perl/Tidy/LineSource.pm +++ b/lib/Perl/Tidy/LineSource.pm @@ -9,7 +9,7 @@ package Perl::Tidy::LineSource; use strict; use warnings; use English qw( -no_match_vars ); -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; use constant DEVEL_MODE => 0; diff --git a/lib/Perl/Tidy/Logger.pm b/lib/Perl/Tidy/Logger.pm index 0b3d49fb..fa3f5284 100644 --- a/lib/Perl/Tidy/Logger.pm +++ b/lib/Perl/Tidy/Logger.pm @@ -8,7 +8,7 @@ package Perl::Tidy::Logger; use strict; use warnings; -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; use English qw( -no_match_vars ); use constant DEVEL_MODE => 0; diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 6198b1fa..8d16dd2f 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -23,7 +23,7 @@ use strict; use warnings; use English qw( -no_match_vars ); -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; use Perl::Tidy::LineBuffer; use Carp; diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index f6167ac6..f582c6a8 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -3,7 +3,7 @@ use strict; use warnings; use Carp; use English qw( -no_match_vars ); -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; use Perl::Tidy::VerticalAligner::Alignment; use Perl::Tidy::VerticalAligner::Line; diff --git a/lib/Perl/Tidy/VerticalAligner/Alignment.pm b/lib/Perl/Tidy/VerticalAligner/Alignment.pm index f612f74f..50edd51a 100644 --- a/lib/Perl/Tidy/VerticalAligner/Alignment.pm +++ b/lib/Perl/Tidy/VerticalAligner/Alignment.pm @@ -10,7 +10,7 @@ use warnings; { #<<< A non-indenting brace -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; sub new { my ( $class, $rarg ) = @_; diff --git a/lib/Perl/Tidy/VerticalAligner/Line.pm b/lib/Perl/Tidy/VerticalAligner/Line.pm index fbe583aa..a1994601 100644 --- a/lib/Perl/Tidy/VerticalAligner/Line.pm +++ b/lib/Perl/Tidy/VerticalAligner/Line.pm @@ -10,7 +10,7 @@ package Perl::Tidy::VerticalAligner::Line; use strict; use warnings; use English qw( -no_match_vars ); -our $VERSION = '20221112.05'; +our $VERSION = '20230309'; sub AUTOLOAD { diff --git a/local-docs/Release-Checklist.md b/local-docs/Release-Checklist.md index 556415b2..863685c4 100644 --- a/local-docs/Release-Checklist.md +++ b/local-docs/Release-Checklist.md @@ -56,8 +56,9 @@ (this is an option in build.pl after making a new .tar.gz) - Do test installs on several systems - Review the suggestions in Release::Checklist - https://metacpan.org/pod/Release::Checklist + and the Berlin concensus + https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/berlin-consensus.md - Upload Release to CPAN - Update CPAN tickets -- 2.39.5