]> git.donarmstrong.com Git - perltidy.git/commitdiff
rewrite several arg lists as hashes for clarity
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 24 Oct 2023 15:04:44 +0000 (08:04 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 24 Oct 2023 15:04:44 +0000 (08:04 -0700)
lib/Perl/Tidy.pm
lib/Perl/Tidy/HtmlWriter.pm
lib/Perl/Tidy/VerticalAligner.pm

index 59c7386d0c4883b03300a7aa0460de81d0defa06..0dfbdc7768f51f2b70af5d0e90c6ef40b4fbf95e 100644 (file)
@@ -1044,23 +1044,23 @@ EOM
     # loop to process all files
     #--------------------------
     $self->process_all_files(
-
-        \%input_hash,
-        \@Arg_files,
-
-        # filename stuff...
-        $source_stream,
-        $output_extension,
-        $forbidden_file_extensions,
-        $in_place_modify,
-        $backup_extension,
-        $delete_backup,
-
-        # logfile stuff...
-        $logfile_header,
-        $rpending_complaint,
-        $rpending_logfile_message,
-
+        {
+            rinput_hash => \%input_hash,
+            rfiles      => \@Arg_files,
+
+            # filename stuff...
+            source_stream             => $source_stream,
+            output_extension          => $output_extension,
+            forbidden_file_extensions => $forbidden_file_extensions,
+            in_place_modify           => $in_place_modify,
+            backup_extension          => $backup_extension,
+            delete_backup             => $delete_backup,
+
+            # logfile stuff...
+            logfile_header           => $logfile_header,
+            rpending_complaint       => $rpending_complaint,
+            rpending_logfile_message => $rpending_logfile_message,
+        }
     );
 
     #-----
@@ -1899,24 +1899,19 @@ sub set_line_separator {
 
 sub process_all_files {
 
-    my (
-
-        $self,
-        $rinput_hash,
-        $rfiles,
-
-        $source_stream,
-        $output_extension,
-        $forbidden_file_extensions,
-        $in_place_modify,
-        $backup_extension,
-        $delete_backup,
+    my ( $self, $rcall_hash ) = @_;
 
-        $logfile_header,
-        $rpending_complaint,
-        $rpending_logfile_message,
-
-    ) = @_;
+    my $rinput_hash               = $rcall_hash->{rinput_hash};
+    my $rfiles                    = $rcall_hash->{rfiles};
+    my $source_stream             = $rcall_hash->{source_stream};
+    my $output_extension          = $rcall_hash->{output_extension};
+    my $forbidden_file_extensions = $rcall_hash->{forbidden_file_extensions};
+    my $in_place_modify           = $rcall_hash->{in_place_modify};
+    my $backup_extension          = $rcall_hash->{backup_extension};
+    my $delete_backup             = $rcall_hash->{delete_backup};
+    my $logfile_header            = $rcall_hash->{logfile_header};
+    my $rpending_complaint        = $rcall_hash->{rpending_complaint};
+    my $rpending_logfile_message  = $rcall_hash->{rpending_logfile_message};
 
     # This routine is the main loop to process all files.
     # Total formatting is done with these layers of subroutines:
@@ -2261,14 +2256,14 @@ EOM
         if ( $rOpts->{'format'} eq 'tidy' && defined($routput_string) ) {
 
             $self->write_tidy_output(
-
-                $routput_string,
-
-                \@input_file_stat,
-                $in_place_modify,
-                $input_file,
-                $backup_extension,
-                $delete_backup,
+                {
+                    routput_string   => $routput_string,
+                    rinput_file_stat => \@input_file_stat,
+                    in_place_modify  => $in_place_modify,
+                    input_file       => $input_file,
+                    backup_extension => $backup_extension,
+                    delete_backup    => $delete_backup,
+                }
             );
         }
 
@@ -2283,17 +2278,14 @@ sub write_tidy_output {
 
     # Write tidied output in '$routput_string' to its final destination
 
-    my (
-        $self,
-
-        $routput_string,
+    my ( $self, $rcall_hash ) = @_;
 
-        $rinput_file_stat,
-        $in_place_modify,
-        $input_file,
-        $backup_extension,
-        $delete_backup,
-    ) = @_;
+    my $routput_string   = $rcall_hash->{routput_string};
+    my $rinput_file_stat = $rcall_hash->{rinput_file_stat};
+    my $in_place_modify  = $rcall_hash->{in_place_modify};
+    my $input_file       = $rcall_hash->{input_file};
+    my $backup_extension = $rcall_hash->{backup_extension};
+    my $delete_backup    = $rcall_hash->{delete_backup};
 
     my $rOpts           = $self->[_rOpts_];
     my $is_encoded_data = $self->[_is_encoded_data_];
@@ -2612,7 +2604,7 @@ sub process_iteration_layer {
     my ( $self, $rinput_string ) = @_;
 
     # This is the iteration layer of processing.
-    # Do all formatting, iterating if requested, on the source string $buf.
+    # Do all formatting, iterating if requested, on the source $rinput_string
     # Output depends on format type:
     #   For 'tidy' formatting, output goes to sink object
     #   For 'html' formatting, output goes to the ultimate destination
index b61da89db020aa6c1064dc4b8ade83642f6efeb9..14ddf7c02795df2a0c50164cc88e0d52f0a047f4 100644 (file)
@@ -800,8 +800,6 @@ sub pod_to_html {
     while ( defined( my $line = $fh_tmp->getline() ) ) {
 
         if ( $line =~ /^\s*<html>\s*$/i ) {
-            ##my $date = localtime;
-            ##$html_print->("<!-- Generated by perltidy on $date -->\n");
             $html_print->("<!-- Generated by perltidy $timestamp -->\n");
             $html_print->($line);
         }
@@ -1016,9 +1014,15 @@ sub make_frame {
     # 1. Make the table of contents panel, with appropriate changes
     # to the anchor names
     my $src_frame_name = 'SRC';
-    my $first_anchor =
-      write_toc_html( $title, $toc_filename, $src_basename, $rtoc,
-        $src_frame_name );
+    my $first_anchor   = write_toc_html(
+        {
+            title          => $title,
+            toc_filename   => $toc_filename,
+            src_basename   => $src_basename,
+            rtoc           => $rtoc,
+            src_frame_name => $src_frame_name,
+        }
+    );
 
     # 2. The current .html filename is renamed to be the contents panel
     rename( $html_filename, $src_filename )
@@ -1027,8 +1031,14 @@ sub make_frame {
 
     # 3. Then use the original html filename for the frame
     write_frame_html(
-        $title,        $html_filename, $top_basename,
-        $toc_basename, $src_basename,  $src_frame_name
+        {
+            title          => $title,
+            frame_filename => $html_filename,
+            top_basename   => $top_basename,
+            toc_basename   => $toc_basename,
+            src_basename   => $src_basename,
+            src_frame_name => $src_frame_name,
+        }
     );
     return;
 } ## end sub make_frame
@@ -1036,7 +1046,14 @@ sub make_frame {
 sub write_toc_html {
 
     # write a separate html table of contents file for frames
-    my ( $title, $toc_filename, $src_basename, $rtoc, $src_frame_name ) = @_;
+    my ($rarg_hash) = @_;
+
+    my $title          = $rarg_hash->{title};
+    my $toc_filename   = $rarg_hash->{toc_filename};
+    my $src_basename   = $rarg_hash->{src_basename};
+    my $rtoc           = $rarg_hash->{rtoc};
+    my $src_frame_name = $rarg_hash->{src_frame_name};
+
     my $fh = IO::File->new( $toc_filename, 'w' )
       or Perl::Tidy::Die("Cannot open $toc_filename: $OS_ERROR\n");
     $fh->print(<<EOM);
@@ -1063,10 +1080,15 @@ EOM
 sub write_frame_html {
 
     # write an html file to be the table of contents frame
-    my (
-        $title,        $frame_filename, $top_basename,
-        $toc_basename, $src_basename,   $src_frame_name
-    ) = @_;
+
+    my ($rarg_hash) = @_;
+
+    my $title          = $rarg_hash->{title};
+    my $frame_filename = $rarg_hash->{frame_filename};
+    my $top_basename   = $rarg_hash->{top_basename};
+    my $toc_basename   = $rarg_hash->{toc_basename};
+    my $src_basename   = $rarg_hash->{src_basename};
+    my $src_frame_name = $rarg_hash->{src_frame_name};
 
     my $fh = IO::File->new( $frame_filename, 'w' )
       or Perl::Tidy::Die("Cannot open $toc_basename: $OS_ERROR\n");
index 58debd06d136a13b7b3f67c49e4103230564fdd5..12fecddf03daacb76a99a47dc4f949f48dc23d25 100644 (file)
@@ -794,9 +794,16 @@ sub valign_input {
     my $j_terminal_match;
 
     if ( $is_terminal_ternary && @{$rgroup_lines} ) {
-        $j_terminal_match =
-          fix_terminal_ternary( $rgroup_lines->[-1], $rfields, $rtokens,
-            $rpatterns, $rfield_lengths, $group_level, );
+        $j_terminal_match = fix_terminal_ternary(
+            {
+                old_line       => $rgroup_lines->[-1],
+                rfields        => $rfields,
+                rtokens        => $rtokens,
+                rpatterns      => $rpatterns,
+                rfield_lengths => $rfield_lengths,
+                group_level    => $group_level,
+            }
+        );
         $jmax = @{$rfields} - 1;
     }
 
@@ -811,10 +818,15 @@ sub valign_input {
         && @{$rgroup_lines}
         && $is_balanced_line )
     {
-
-        $j_terminal_match =
-          fix_terminal_else( $rgroup_lines->[-1], $rfields, $rtokens,
-            $rpatterns, $rfield_lengths );
+        $j_terminal_match = fix_terminal_else(
+            {
+                old_line       => $rgroup_lines->[-1],
+                rfields        => $rfields,
+                rtokens        => $rtokens,
+                rpatterns      => $rpatterns,
+                rfield_lengths => $rfield_lengths,
+            }
+        );
         $jmax = @{$rfields} - 1;
     }
 
@@ -1077,9 +1089,14 @@ sub fix_terminal_ternary {
     #
     # returns the index of the terminal question token, if any
 
-    my ( $old_line, $rfields, $rtokens, $rpatterns, $rfield_lengths,
-        $group_level )
-      = @_;
+    my ($rcall_hash) = @_;
+
+    my $old_line       = $rcall_hash->{old_line};
+    my $rfields        = $rcall_hash->{rfields};
+    my $rtokens        = $rcall_hash->{rtokens};
+    my $rpatterns      = $rcall_hash->{rpatterns};
+    my $rfield_lengths = $rcall_hash->{rfield_lengths};
+    my $group_level    = $rcall_hash->{group_level};
 
     return if ( !$old_line );
     use constant EXPLAIN_TERNARY => 0;
@@ -1253,7 +1270,13 @@ sub fix_terminal_else {
     #
     # returns a positive value if the else block should be indented
     #
-    my ( $old_line, $rfields, $rtokens, $rpatterns, $rfield_lengths ) = @_;
+    my ($rcall_hash) = @_;
+
+    my $old_line       = $rcall_hash->{old_line};
+    my $rfields        = $rcall_hash->{rfields};
+    my $rtokens        = $rcall_hash->{rtokens};
+    my $rpatterns      = $rcall_hash->{rpatterns};
+    my $rfield_lengths = $rcall_hash->{rfield_lengths};
 
     return if ( !$old_line );
     my $jmax = @{$rfields} - 1;
@@ -2258,8 +2281,16 @@ sub sweep_left_to_right {
     #------------------------------
     # Step 3: Execute the task list
     #------------------------------
-    do_left_to_right_sweep( $rlines, $rgroups, \@todo, \%max_move, $short_pad,
-        $group_level );
+    do_left_to_right_sweep(
+        {
+            rlines      => $rlines,
+            rgroups     => $rgroups,
+            rtodo       => \@todo,
+            rmax_move   => \%max_move,
+            short_pad   => $short_pad,
+            group_level => $group_level
+        }
+    );
     return;
 } ## end sub sweep_left_to_right
 
@@ -2308,9 +2339,17 @@ sub sweep_left_to_right {
         # This is a sub called by sub do_left_to_right_sweep to
         # move the alignment column of token $itok to $col_want for a
         # sequence of groups.
-        my ( $rlines, $rgroups, $rmax_move, $ngb, $nge, $itok, $col_want,
-            $raw_tok )
-          = @_;
+        my ($rcall_hash) = @_;
+
+        my $rlines    = $rcall_hash->{rlines};
+        my $rgroups   = $rcall_hash->{rgroups};
+        my $rmax_move = $rcall_hash->{rmax_move};
+        my $ngb       = $rcall_hash->{ngb};
+        my $nge       = $rcall_hash->{nge};
+        my $itok      = $rcall_hash->{itok};
+        my $col_want  = $rcall_hash->{col_want};
+        my $raw_tok   = $rcall_hash->{raw_tok};
+
         return if ( !defined($ngb) || $nge <= $ngb );
         foreach my $ng ( $ngb .. $nge ) {
 
@@ -2340,8 +2379,15 @@ sub sweep_left_to_right {
     } ## end sub move_to_common_column
 
     sub do_left_to_right_sweep {
-        my ( $rlines, $rgroups, $rtodo, $rmax_move, $short_pad, $group_level )
-          = @_;
+
+        my ($rcall_hash) = @_;
+
+        my $rlines      = $rcall_hash->{rlines};
+        my $rgroups     = $rcall_hash->{rgroups};
+        my $rtodo       = $rcall_hash->{rtodo};
+        my $rmax_move   = $rcall_hash->{rmax_move};
+        my $short_pad   = $rcall_hash->{short_pad};
+        my $group_level = $rcall_hash->{group_level};
 
         # $blocking_level[$nj is the level at a match failure between groups
         # $ng-1 and $ng
@@ -2503,8 +2549,16 @@ sub sweep_left_to_right {
                     }
 
                     move_to_common_column(
-                        $rlines, $rgroups, $rmax_move, $ng_first,
-                        $ng - 1, $itok,    $col_want,  $raw_tok
+                        {
+                            rlines    => $rlines,
+                            rgroups   => $rgroups,
+                            rmax_move => $rmax_move,
+                            ngb       => $ng_first,
+                            nge       => $ng - 1,
+                            itok      => $itok,
+                            col_want  => $col_want,
+                            raw_tok   => $raw_tok,
+                        }
                     );
                     $ng_first        = $ng;
                     $col_want        = $col;
@@ -2525,10 +2579,18 @@ sub sweep_left_to_right {
 
             if ( $ng_end > $ng_first ) {
                 move_to_common_column(
-                    $rlines, $rgroups, $rmax_move, $ng_first,
-                    $ng_end, $itok,    $col_want,  $raw_tok
+                    {
+                        rlines    => $rlines,
+                        rgroups   => $rgroups,
+                        rmax_move => $rmax_move,
+                        ngb       => $ng_first,
+                        nge       => $ng_end,
+                        itok      => $itok,
+                        col_want  => $col_want,
+                        raw_tok   => $raw_tok,
+                    }
                 );
-            } ## end loop over groups for one task
+            }
         } ## end loop over tasks
 
         return;
@@ -3291,9 +3353,16 @@ sub match_line_pairs {
                     if ( $pat_m ne $pat ) {
                         my $pad =
                           $rfield_lengths->[$i] - $rfield_lengths_m->[$i];
-                        my ( $match_code, $rmsg ) =
-                          compare_patterns( $group_level,
-                            $tok, $tok_m, $pat, $pat_m, $pad );
+                        my ( $match_code, $rmsg ) = compare_patterns(
+                            {
+                                group_level => $group_level,
+                                tok         => $tok,
+                                tok_m       => $tok_m,
+                                pat         => $pat,
+                                pat_m       => $pat_m,
+                                pad         => $pad
+                            }
+                        );
                         if ($match_code) {
                             if    ( $match_code == 1 ) { $i_nomatch = $i }
                             elsif ( $match_code == 2 ) { $i_nomatch = 0 }
@@ -3332,7 +3401,14 @@ sub match_line_pairs {
 
 sub compare_patterns {
 
-    my ( $group_level, $tok, $tok_m, $pat, $pat_m, $pad ) = @_;
+    my ($rcall_hash) = @_;
+
+    my $group_level = $rcall_hash->{group_level};
+    my $tok         = $rcall_hash->{tok};
+    my $tok_m       = $rcall_hash->{tok_m};
+    my $pat         = $rcall_hash->{pat};
+    my $pat_m       = $rcall_hash->{pat_m};
+    my $pad         = $rcall_hash->{pad};
 
     # helper routine for sub match_line_pairs to decide if patterns in two
     # lines match well enough..Given