]> git.donarmstrong.com Git - perltidy.git/commitdiff
convert some eq tests to a hash
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 18 Jun 2020 13:41:39 +0000 (06:41 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 18 Jun 2020 13:41:39 +0000 (06:41 -0700)
bin/perltidy
lib/Perl/Tidy/Tokenizer.pm

index 04c4363103a0739890cdd14a5db45cc8e7c7f685..87cb3d4e0818388bde482037d85b7ebfa1be531b 100755 (executable)
@@ -720,9 +720,11 @@ The value given to B<-ci> is also used by some commands when a small
 space is required.  Examples are commands for outdenting labels,
 B<-ola>, and control keywords, B<-okw>.  
 
-When default values are not used, it is suggested that the value B<n>
-given with B<-ci=n> be no more than about one-half of the number of
-spaces assigned to a full indentation level on the B<-i=n> command.
+When default values are not used, it is highly recommended that the value B<n>
+given with B<-ci=n> be no more than about one-half of the number of spaces
+assigned to a full indentation level on the B<-i=n> 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.
 
 =item B<-sil=n> B<--starting-indentation-level=n>   
 
@@ -1084,7 +1086,7 @@ misinterpreted by your command shell.
 
 =item Note: Perltidy does always follow whitespace controls 
 
-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:
+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:
 
    sub print_div {
       my ($x,$y)=@_;
@@ -1098,9 +1100,9 @@ Suppose the user requests that / signs have a space to the left but not to the r
        print $x /$y;
    }
 
-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.
+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.
 
-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.
+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.
 
 =item Space between specific keywords and opening paren
 
index db8c81e56f2f5cfcceec1aa9117076f99df315b7..872a37e75efaef8fea2a9e2d0e7c01b9f9cf946e 100644 (file)
@@ -1542,6 +1542,10 @@ sub prepare_for_a_new_file {
       qw(if elsif unless while until for foreach switch case given when catch);
     @is_blocktype_with_paren{@_} = (1) x scalar(@_);
 
+    my %is_case_default;
+    @_ = qw(case default);
+    @is_case_default{@_} = (1) x scalar(@_);
+
     my $extended_syntax_type = sub {
 
         # check for certain extended syntax variations, and
@@ -1557,7 +1561,7 @@ sub prepare_for_a_new_file {
             #  default:
             # Note that the line 'default:' will be parsed as a label elsewhere.
 
-            if ( $statement_type eq 'case' || $statement_type eq 'default' ) {
+            if ( $is_case_default{$statement_type} ) {
 
                 # The type will be the same as a label
                 $type = 'J';