From: Steve Hancock Date: Thu, 12 May 2022 15:57:07 +0000 (-0700) Subject: misc code cleanups X-Git-Tag: 20220613~33 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c450fbaff26ec3c7e73ddc6e74bb8c64b3eb09e0;p=perltidy.git misc code cleanups --- diff --git a/bin/perltidy b/bin/perltidy index 8aa6af74..e6c1418e 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -50,8 +50,7 @@ Perltidy can produce output on either of two modes, depending on the existence of an B<-html> flag. Without this flag, the output is passed through a formatter. The default formatting tries to follow the recommendations in perlstyle(1), but it can be controlled in detail with -numerous input parameters, which are described in L<"FORMATTING -OPTIONS">. +numerous input parameters, which are described in L<"FORMATTING OPTIONS">. When the B<-html> flag is given, the output is passed through an HTML formatter which is described in L<"HTML OPTIONS">. @@ -209,7 +208,7 @@ desired with B<-nse> on the command line. Change the extension of the output file to be F instead of the default F (or F in case the -B<-html> option is used). -See L. +See L<"Specifying File Extensions">. =item B<-opath>=path, B<--output-path>=path @@ -254,7 +253,7 @@ file to be something other than the default F<.bak>, and (2) to indicate that no backup file should be saved. To change the default extension to something other than F<.bak> see -L. +L<"Specifying File Extensions">. A backup file of the source is always written, but you can request that it be deleted at the end of processing if there were no errors. This is risky @@ -387,7 +386,7 @@ For example, will cause the perltidy to treate the words 'method', 'fun', '_sub' and 'M4' to be treated 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 L). +Note that several other parameters accept a list of keywords, including 'sub' (see L<"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. =item B<-gal=s>, B<--grep-alias-list=s> @@ -430,7 +429,7 @@ This flag disables all formatting and causes the input to be copied unchanged to the output except for possible changes in line ending characters and any pre- and post-filters. This can be useful in conjunction with a hierarchical set of F<.perltidyrc> files to avoid unwanted code tidying. See also -L for a way to avoid tidying specific +L<"Skipping Selected Sections of Code"> for a way to avoid tidying specific sections of code. =item B<-i=n>, B<--indent-columns=n> @@ -570,7 +569,7 @@ 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. -For another method of handling extended syntax see the section L. +For another method of handling extended syntax see the section L<"Skipping Selected Sections of Code">. =item B<-io>, B<--indent-only> @@ -1158,7 +1157,7 @@ has been set to), if possible. This is the default. For example: fixit($i); } -Use B<-nola> to not outdent labels. To control line breaks after labels see L. +Use B<-nola> to not outdent labels. To control line breaks after labels see L<"bal=n, --break-after-labels=n">. =item B @@ -1828,7 +1827,7 @@ where C is a list of block types to be tagged with closing side comments. By default, all code block types preceded by a keyword or label (such as C, C, and so on) will be tagged. The B<-cscl> command changes the default list to be any selected block types; see -L. +L<"Specifying Block Types">. For example, the following command requests that only C's, labels, C, and C blocks be affected by any B<-csc> or B<-dcsc> operation: @@ -2151,7 +2150,7 @@ but they can be helpful for working around occasional problems. Note that it may be possible to avoid the use of B<--format-skipping> for the specific case of a comma-separated list of values, as in the above example, by simply inserting a blank or comment somewhere between the opening and closing -parens. See the section L. +parens. See the section L<"Controlling List Formatting">. The following sections describe the available controls for these options. They should not normally be needed. @@ -2232,8 +2231,7 @@ The default is equivalent to -cse='#>>V'. The parameters in this section control breaks after non-blank lines of code. Blank lines are controlled -separately by parameters in the section L. +separately by parameters in the section L<"Blank Line Control">. =over 4 @@ -2243,13 +2241,13 @@ If you do not want any changes to the line breaks within lines of code in your script, set B<-fnl>, and they will remain fixed, and the rest of the commands in this section and sections -L, -L. +L<"Controlling List Formatting">, +L<"Retaining or Ignoring Existing Line Breaks">. You may want to use B<-noll> with this. Note: If you also want to keep your blank lines exactly as they are, you can use the B<-fbl> flag which is described -in the section L. +in the section L<"Blank Line Control">. =item B<-ce>, B<--cuddled-else> @@ -2400,14 +2398,14 @@ parameters B<--brace-left-list> and B<-brace-left-exclusion-list> described in t =item B<-bll=s>, B<--brace-left-list=s> Use this parameter to change the types of block braces for which the -B<-bl> flag applies; see L. For example, +B<-bl> flag applies; see L<"Specifying Block Types">. For example, B<-bll='if elsif else sub'> would apply it to only C and named sub blocks. The default is all blocks, B<-bll='*'>. =item B<-blxl=s>, B<--brace-left-exclusion-list=s> Use this parameter to exclude types of block braces for which the -B<-bl> flag applies; see L. For example, +B<-bl> flag applies; see L<"Specifying Block Types">. For example, the default settings B<-bll='*'> and B<-blxl='sort map grep eval asub'> mean all blocks except B and anonymous sub blocks. @@ -2487,14 +2485,14 @@ a certain block type, the B<-bli> style has priority. =item B<-blil=s>, B<--brace-left-and-indent-list=s> Use this parameter to change the types of block braces for which the -B<-bli> flag applies; see L. +B<-bli> flag applies; see L<"Specifying Block Types">. The default is B<-blil='if else elsif unless while for foreach do : sub'>. =item B<-blixl=s>, B<--brace-left-and-indent-exclusion-list=s> Use this parameter to exclude types of block braces for which the B<-bli> flag -applies; see L. +applies; see L<"Specifying Block Types">. This might be useful in conjunction with selecting all blocks B<-blil='*'>. The default setting is B<-blixl=' '>, which does not exclude any blocks. @@ -3080,7 +3078,7 @@ B, and also with a preceding label. This can be changed with the parameter B<-bbvtl=string>, or B<--block-brace-vertical-tightness-list=string>, where B is a space-separated list of block types. For more information on the -possible values of this string, see L +possible values of this string, see L<"Specifying Block Types"> For example, if we want to just apply this style to C, C, and C blocks, we could use @@ -3345,7 +3343,7 @@ anywhere between the opening and closing parens. Vertical alignment of the list items will still occur if possible. For another possibility see -the -fs flag in L. +the -fs flag in L<"Skipping Selected Sections of Code">. =over 4 @@ -4839,13 +4837,13 @@ ignored. Use this flag to specify the extra file extension of the table of contents file when html frames are used. The default is "toc". -See L. +See L<"Specifying File Extensions">. =item The B<-sext=s>, or B<--html-src-extension> flag Use this flag to specify the extra file extension of the content file when html frames are used. The default is "src". -See L. +See L<"Specifying File Extensions">. =item The B<-hent>, or B<--html-entities> flag diff --git a/dev-bin/build.pl b/dev-bin/build.pl index ec99ca41..ff70af77 100755 --- a/dev-bin/build.pl +++ b/dev-bin/build.pl @@ -231,7 +231,7 @@ sub run_perl_critic { $rstatus->{'PC'} = 'TBD'; # running with parameters in .perlcritic - my $cmd = "perlcritic lib/Perl/* >tmp/perlcritic.out"; + my $cmd = "perlcritic lib/Perl/ >tmp/perlcritic.out"; system_echo($cmd); my $fh; if ( !open( $fh, '<', $pcoutput ) ) { diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 0a497fb6..2b1dca4e 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -944,7 +944,8 @@ EOM @ARGV = map { $_->[0] } sort { $a->[1] <=> $b->[1] } - map { [ $_, -e $_ ? -s $_ : 0 ] } @ARGV; + map { [ $_, -e ? -s : 0 ] } @ARGV; + ##map { [ $_, -e $_ ? -s $_ : 0 ] } @ARGV; } my $number_of_files = @ARGV; @@ -996,7 +997,8 @@ EOM my $dh; if ( opendir( $dh, './' ) ) { my @files = - grep { /$pattern/ && !-d $_ } readdir($dh); + grep { /$pattern/ && !-d } readdir($dh); + ##grep { /$pattern/ && !-d $_ } readdir($dh); closedir($dh); if (@files) { unshift @ARGV, @files; @@ -1860,8 +1862,8 @@ EOM # destination stream must be an object with print method else { - foreach (@lines) { - $destination_stream->print($_); + foreach my $line (@lines) { + $destination_stream->print($line); } if ( $ref_destination_stream->can('close') ) { $destination_stream->close(); @@ -2294,6 +2296,9 @@ sub write_logfile_header { $rOpts, $logger_object, $config_file, $rraw_options, $Windows_type, $readable_options ) = @_; + + # Note: the punctuation variable '$]' is not in older versions of + # English.pm so leave it as is to avoid failing installation tests. $logger_object->write_logfile_entry( "perltidy version $VERSION log file on a $OSNAME system, OLD_PERL_VERSION=$]\n" ); diff --git a/lib/Perl/Tidy.pod b/lib/Perl/Tidy.pod index d4320a84..4dd8bc69 100644 --- a/lib/Perl/Tidy.pod +++ b/lib/Perl/Tidy.pod @@ -1,3 +1,4 @@ + =head1 NAME Perl::Tidy - Parses and beautifies perl source @@ -38,7 +39,7 @@ For example, the perltidy script is basically just this: The call to B returns a scalar B<$error_flag> which is TRUE if an error caused premature termination, and FALSE if the process ran to normal completion. Additional discuss of errors is contained below in the -L section. +L section. The module accepts input and output streams by a variety of methods. The following list of parameters may be any of the following: a diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index f1d7709b..4cae92a4 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -2296,10 +2296,11 @@ list is: @list; EOM } - # - pull out any any leading container code, like f( or *{ - foreach (@list) { - if ( $_ =~ /^( [ \w\* ] )( [ \{\(\[\}\)\] ] )$/x ) { - $_ = $2; + # pull out any any leading container code, like f( or *{ + # For example: 'f(' becomes flags hash entry '(' => 'f' + foreach my $item (@list) { + if ( $item =~ /^( [ \w\* ] )( [ \{\(\[\}\)\] ] )$/x ) { + $item = $2; $flags{$2} = $1; } } diff --git a/lib/Perl/Tidy/HtmlWriter.pm b/lib/Perl/Tidy/HtmlWriter.pm index 5435a8f5..909a5abc 100644 --- a/lib/Perl/Tidy/HtmlWriter.pm +++ b/lib/Perl/Tidy/HtmlWriter.pm @@ -762,9 +762,9 @@ sub pod_to_html { # This routine will write the html selectively and store the toc my $html_print = sub { - foreach (@_) { - $html_fh->print($_) unless ($no_print); - if ($in_toc) { push @toc, $_ } + foreach my $line (@_) { + $html_fh->print($line) unless ($no_print); + if ($in_toc) { push @toc, $line } } return; }; diff --git a/lib/Perl/Tidy/Logger.pm b/lib/Perl/Tidy/Logger.pm index eefaa99a..6595f3bc 100644 --- a/lib/Perl/Tidy/Logger.pm +++ b/lib/Perl/Tidy/Logger.pm @@ -489,7 +489,7 @@ sub finish { Perl::Tidy::streamhandle( $log_file, 'w', $is_encoded_data ); if ($fh) { my $routput_array = $self->{_output_array}; - foreach ( @{$routput_array} ) { $fh->print($_) } + foreach my $line ( @{$routput_array} ) { $fh->print($line) } if ( $log_file ne '-' && !ref $log_file ) { eval { $fh->close() }; } diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index 454736f0..3de4badc 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -3757,11 +3757,11 @@ sub prune_alignment_tree { $levels_next[$MAX_DEPTH] = $rlevs->[-1]; } my $depth = 0; - foreach (@levels_next) { + foreach my $item (@levels_next) { $token_patterns_next[$depth] = - defined($_) ? $rtoken_patterns->{$_} : undef; + defined($item) ? $rtoken_patterns->{$item} : undef; $token_indexes_next[$depth] = - defined($_) ? $rtoken_indexes->{$_} : undef; + defined($item) ? $rtoken_indexes->{$item} : undef; $depth++; } @@ -3958,7 +3958,7 @@ sub Dump_tree_groups { local $LIST_SEPARATOR = ')('; foreach my $item ( @{$rgroup} ) { my @fix = @{$item}; - foreach (@fix) { $_ = "undef" unless defined $_; } + foreach my $val (@fix) { $val = "undef" unless defined $val; } $fix[4] = "..."; print "(@fix)\n"; }