]> git.donarmstrong.com Git - perltidy.git/commitdiff
Bump to v 20221112.05; update one-line block docs 20221112.05
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 1 Feb 2023 02:14:16 +0000 (18:14 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 1 Feb 2023 02:14:16 +0000 (18:14 -0800)
21 files changed:
CHANGES.md
bin/perltidy
lib/Perl/Tidy.pm
lib/Perl/Tidy.pod
lib/Perl/Tidy/Debugger.pm
lib/Perl/Tidy/DevNull.pm
lib/Perl/Tidy/Diagnostics.pm
lib/Perl/Tidy/FileWriter.pm
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/HtmlWriter.pm
lib/Perl/Tidy/IOScalar.pm
lib/Perl/Tidy/IOScalarArray.pm
lib/Perl/Tidy/IndentationItem.pm
lib/Perl/Tidy/LineBuffer.pm
lib/Perl/Tidy/LineSink.pm
lib/Perl/Tidy/LineSource.pm
lib/Perl/Tidy/Logger.pm
lib/Perl/Tidy/Tokenizer.pm
lib/Perl/Tidy/VerticalAligner.pm
lib/Perl/Tidy/VerticalAligner/Alignment.pm
lib/Perl/Tidy/VerticalAligner/Line.pm

index 1a9f84b7515be20621d05f2ae4e59b0f742b3c93..bcf9422d025490722d6f8aae127b62a5f847553c 100644 (file)
@@ -1,6 +1,6 @@
 # Perltidy Change Log
 
-## 2022 11 12.04
+## 2022 11 12.05
 
     - 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
index 02a6a779714482f5a799dcab348cd95535c2d8e7..b6fe87065a049502d9c24276ea2a65bee7cce383 100755 (executable)
@@ -2345,7 +2345,7 @@ following set of parameters could be used:
   perltidy -ce -cbl='else elsif continue' -cblx
 
 
-=item B<-cbo=n>,   B<--cuddled-break-option=n>
+=item B<-cbo=n>, B<--cuddled-break-option=n>
 
 Cuddled formatting is only possible between a pair of code blocks if the
 closing brace of the first block starts a new line. If a block is encountered
@@ -4326,9 +4326,9 @@ B<-nst> and/or B<-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 B<-ci=2> be used instead, or the flag B<-xci> be set.  This will help
-show structure, particularly when there are ternary statements. The following
-snippet illustrates these options.
+parameter B<-ci=2> be used instead, or (2) the flag B<-xci> be set.  This will
+help show structure, particularly when there are ternary statements. The
+following snippet illustrates these options.
 
     # perltidy -pbp
     $self->{_text} = (
@@ -4368,78 +4368,72 @@ snippet illustrates these options.
 The B<-xci> flag was developed after the B<-pbp> parameters were published so you need
 to include it separately.
 
-=item B<One-line blocks>
+=back
+
+=head2 One-Line Blocks
 
-There are a few points to note regarding one-line blocks.  A one-line
-block is something like this,
+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 C<map>, C<eval>, and C<sort>, C<eval>,
+because these code blocks are often small and most clearly displayed in a
+single line. This behavior can be controlled with the flag
+B<--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 B<-nasc>
-option is used) if the block is a code block.
+When the B<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 B<--cuddled-break-option=n> described elsehwere.
 
-The main exception is that perltidy will attempt to form new one-line
-blocks following the keywords C<map>, C<eval>, and C<sort>, C<eval>, because
-these code blocks are often small and most clearly displayed in a single
-line. This behavior can be controlled with the flag B<--one-line-block-exclusion-list> described below.
+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 B<-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.
+=over 4
 
-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.
+=item B<-olbxl=s>, B<--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 B<-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 B<s>.  The list B<s> may
+include any of the words C<sort>, C<map>, C<grep>, C<eval>,  or it may be C<*>
+to indicate all of these.
 
-     cat infile | perltidy -nanl | perltidy >outfile
+So for example to prevent multi-line B<eval> blocks from becomming one-line
+blocks, the command would be B<-olbxl='eval'>.  In this case, existing one-line B<eval> blocks will remain on one-line if possible, and existing multi-line
+B<eval> blocks will remain multi-line blocks.
 
-When executed on this snippet
+=item B<-olbn=n>, B<--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:
 
-This shows that blocks with a single statement become one-line blocks.
+  n=0 break nested one-line blocks into multiple lines [DEFAULT]
+  n=1 stable: keep existing nested-one line blocks intact
 
-=item B<-olbxl=s>, B<--one-line-block-exclusion-list=s>
+For the above example, the default formatting (B<-olbn=0>) is
 
-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 B<s>.  The list B<s> may
-include any of the words C<sort>, C<map>, C<grep>, C<eval>,  or it may be C<*>
-to indicate all of these.
+    foreach (@list) {
+        if ( $_ eq $asked_for ) { last }
+        ++$found;
+    }
 
-So for example to prevent multi-line 'eval' blocks from becomming one-line
-blocks, the command would be B<-olbxl='eval'>.  In this case, existing one-line B<eval> blocks will remain on one-line if possible, and existing multi-line
-B<eval> blocks will remain multi-line blocks.
+If the parameter B<-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.
 
 =item B<-olbs=n>, B<--one-line-block-semicolons=n>
 
@@ -4459,29 +4453,47 @@ all one-line blocks, regardless of complexity, the B<n=0> option only removes
 ending semicolons which terminate one-line blocks containing just one
 semicolon.  So these two options are not exact inverses.
 
-=item B<-olbn=n>, B<--one-line-block-nesting=n>
+=item B<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 B<-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 (B<-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 B<-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.
+
+=item B<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 B<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 B<-cuddled-else> flag and B<--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.
 
 =back
 
@@ -4648,16 +4660,12 @@ 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:
+a syntax error:
 
-    method deposit( Num $amount) {
+    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 B<--nooutdent-labels> flag
-to prevent lines such as 'default:' from being outdented.
-
 This flag is enabled by default but it can be deactivated with B<-nxs>.
 Probably the only reason to deactivate this flag is to generate more diagnostic
 messages when debugging a script.
@@ -5545,7 +5553,7 @@ The perltidy binary uses the Perl::Tidy module and is installed when that module
 
 =head1 VERSION
 
-This man page documents perltidy version 20221112.04
+This man page documents perltidy version 20221112.05
 
 =head1 BUG REPORTS
 
index 8fe08edcff437cb0e002bc1f1c0807fed3506ce8..a8d6b8342db1db489e7b3004d13ca617c5069d0c 100644 (file)
@@ -113,7 +113,7 @@ BEGIN {
     # then the Release version must be bumped, and it is probably past time for
     # a release anyway.
 
-    $VERSION = '20221112.04';
+    $VERSION = '20221112.05';
 }
 
 sub DESTROY {
index 3981a317217c0d2c0532ca06385c3b353a49f9b5..864111f5aaa011b4b228a3f825af6ff205f2a37c 100644 (file)
@@ -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.04
+This man page documents Perl::Tidy version 20221112.05
 
 =head1 LICENSE
 
index b2dd78d4f6fcdc72a205586309deb4bc2edff604..24896f3ca9192d28ec65b679d46d691c2417eb9f 100644 (file)
@@ -8,7 +8,7 @@ package Perl::Tidy::Debugger;
 use strict;
 use warnings;
 use English qw( -no_match_vars );
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 use constant EMPTY_STRING => q{};
 use constant SPACE        => q{ };
index 842585204b2f35ef4e2f1c5f3a445b1a3e4e477b..bb41468ab44276a185466ba0588589af27bd78b8 100644 (file)
@@ -7,7 +7,7 @@
 package Perl::Tidy::DevNull;
 use strict;
 use warnings;
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 sub new   { my $self = shift; return bless {}, $self }
 sub print { return }
 sub close { return }
index 7a82aa882076b1b9527d9813522355e3c544d4c2..6b27ec31e39f4c208c5c2c46978ec2b0823c5e1a 100644 (file)
@@ -21,7 +21,7 @@ package Perl::Tidy::Diagnostics;
 use strict;
 use warnings;
 use English qw( -no_match_vars );
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 use constant EMPTY_STRING => q{};
 
index 58b7e22ca6c44b2c6e16c5edcc828f617ade8ee0..6db1293bfb15d05633c5b0cd253232cb9bae6045 100644 (file)
@@ -7,7 +7,7 @@
 package Perl::Tidy::FileWriter;
 use strict;
 use warnings;
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 use constant DEVEL_MODE   => 0;
 use constant EMPTY_STRING => q{};
index ca8a4f0b18577a44f783be3e37c78eb977e6a012..0aa02702138cb95235791859e2dcf7697740ae32 100644 (file)
@@ -53,7 +53,7 @@ use constant SPACE        => q{ };
 use Carp;
 use English    qw( -no_match_vars );
 use List::Util qw( min max );          # min, max are in Perl 5.8
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 # The Tokenizer will be loaded with the Formatter
 ##use Perl::Tidy::Tokenizer;    # for is_keyword()
index c6fe7c55a21560e910d8a140dcf30e9778125165..c8d7556008b1b3423ebf30c39b3007a5ef5e4a03 100644 (file)
@@ -7,7 +7,7 @@
 package Perl::Tidy::HtmlWriter;
 use strict;
 use warnings;
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 use English qw( -no_match_vars );
 use File::Basename;
index 64a171db2db265689d05368449fdc7ea21eedfba..8a78e6d5162bb63df57fd63b2860daa3566fd6bb 100644 (file)
@@ -10,7 +10,7 @@ package Perl::Tidy::IOScalar;
 use strict;
 use warnings;
 use Carp;
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 use constant EMPTY_STRING => q{};
 
index 3b62a32a7e6f1a433c03f53281fdf63f06d29962..339582f298a86c7a741cfd7bf2074d682b937d7a 100644 (file)
@@ -14,7 +14,7 @@ package Perl::Tidy::IOScalarArray;
 use strict;
 use warnings;
 use Carp;
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 sub AUTOLOAD {
 
index f456eb559f2b665f9ccd69c73025422fb1bef001..71a253e0261f935e62e1e61c4388fdeb3b5c5349 100644 (file)
@@ -8,7 +8,7 @@
 package Perl::Tidy::IndentationItem;
 use strict;
 use warnings;
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 BEGIN {
 
index 1b0e91eab859cded15b917b8e552fdc83cca82f4..c0192547f114b3d114933b1bed43ff4eb9e27ef0 100644 (file)
@@ -12,7 +12,7 @@
 package Perl::Tidy::LineBuffer;
 use strict;
 use warnings;
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 sub AUTOLOAD {
 
index 2e2af90de885b61f480c312ac82647409f660e0f..4db6a4cdde7d029815a9880afeacd5891ccb168f 100644 (file)
@@ -8,7 +8,7 @@
 package Perl::Tidy::LineSink;
 use strict;
 use warnings;
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 sub AUTOLOAD {
 
index b97533dd9f5a40ee17dc7e48038d79b2c332159b..3c089a09fba64d43cca9b1e8cda60cd6847273d2 100644 (file)
@@ -9,7 +9,7 @@ package Perl::Tidy::LineSource;
 use strict;
 use warnings;
 use English qw( -no_match_vars );
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 use constant DEVEL_MODE => 0;
 
index dde26e307a2ff627372919f9b327625cc01d8bc0..43617e233ac5c6debbeaac3c213ff39776c23b75 100644 (file)
@@ -8,7 +8,7 @@
 package Perl::Tidy::Logger;
 use strict;
 use warnings;
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 use English qw( -no_match_vars );
 
 use constant DEVEL_MODE   => 0;
index d5bbeaba4b1118dd67c82f5c1c2169e81ce9bf45..0d45e7459ee2abc70226fd7124fddd621c2d6aa6 100644 (file)
@@ -23,7 +23,7 @@ use strict;
 use warnings;
 use English qw( -no_match_vars );
 
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 use Perl::Tidy::LineBuffer;
 use Carp;
index 76b729178f30029c59377459db9fd947c9e411f0..d22a265fdb0a20361732dfaf1c12095a384e8585 100644 (file)
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 use Carp;
 use English qw( -no_match_vars );
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 use Perl::Tidy::VerticalAligner::Alignment;
 use Perl::Tidy::VerticalAligner::Line;
 
index b1b037bb4f6140a66ad652df8355e0a6d644582f..f612f74f5c93150601849de24bb3daa16f67d0c9 100644 (file)
@@ -10,7 +10,7 @@ use warnings;
 
 { #<<< A non-indenting brace
 
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 sub new {
     my ( $class, $rarg ) = @_;
index e11f66614eb8f2eda36b419d3c33fd19b34a9252..3105743422229c714fe1a4e6b95542ce54140520 100644 (file)
@@ -10,7 +10,7 @@ package Perl::Tidy::VerticalAligner::Line;
 use strict;
 use warnings;
 use English qw( -no_match_vars );
-our $VERSION = '20221112.04';
+our $VERSION = '20221112.05';
 
 sub AUTOLOAD {