]> git.donarmstrong.com Git - perltidy.git/commitdiff
unpack args of non time-critical subs
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 18 Oct 2023 14:28:11 +0000 (07:28 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 18 Oct 2023 14:28:11 +0000 (07:28 -0700)
.perlcriticrc
lib/Perl/Tidy/FileWriter.pm
lib/Perl/Tidy/IndentationItem.pm
lib/Perl/Tidy/VerticalAligner.pm
lib/Perl/Tidy/VerticalAligner/Alignment.pm
lib/Perl/Tidy/VerticalAligner/Line.pm

index 57a1f3bd15b8ecf6d8c5d5515a486d80af6a146b..f29fb9dcffa1ca809373f359864a4ecd95973f10 100644 (file)
@@ -30,14 +30,15 @@ verbose = %f: [%p] %m at line %l, column %c.\n
 # sure if this can be avoided.
 [-Subroutines::ProhibitNestedSubs]
 
-# Make an exception for very short (possibly time-critical) subs.
+# Make an exception for very short time-critical subs.
 [Subroutines::RequireArgUnpacking]
 short_subroutine_statements = 2
 
 # Disagree: The advantages of 'use constant' greatly outweigh the few
-# disadvantages.  Perl::Tidy relies heavily on constants for efficient and
-# robust coding of array indexes and for compiling out debug code, and to avoid
-# autovivication problems that would occur if hashes were used instead.
+# disadvantages.  Perl::Tidy relies heavily on constants
+#  -for efficient and robust coding of array indexes,
+#  -for avoiding autovivication issues if hashes were used instead,
+#  -and for eliminating debug code during compilation.
 [-ValuesAndExpressions::ProhibitConstantPragma]
 
 # Disagree: adding quotes on here doc terminators causes needless "line noise"
index 52a5a60cb58b8e0e98500816d762f8e6d7347074..83f981033b80124cc8535e1670e61634f1879ce5 100644 (file)
@@ -226,24 +226,29 @@ sub get_convergence_check {
 } ## end sub get_convergence_check
 
 sub get_output_line_number {
-    return $_[0]->[_output_line_number_];
+    my $self = shift;
+    return $self->[_output_line_number_];
 }
 
 sub decrement_output_line_number {
-    $_[0]->[_output_line_number_]--;
+    my $self = shift;
+    $self->[_output_line_number_]--;
     return;
 }
 
 sub get_consecutive_nonblank_lines {
-    return $_[0]->[_consecutive_nonblank_lines_];
+    my $self = shift;
+    return $self->[_consecutive_nonblank_lines_];
 }
 
 sub get_consecutive_blank_lines {
-    return $_[0]->[_consecutive_blank_lines_];
+    my $self = shift;
+    return $self->[_consecutive_blank_lines_];
 }
 
 sub reset_consecutive_blank_lines {
-    $_[0]->[_consecutive_blank_lines_] = 0;
+    my $self = shift;
+    $self->[_consecutive_blank_lines_] = 0;
     return;
 }
 
index d16dee066e3656938c420095ca53298f6701db35..3dffe82ac6849f99260d2d4c4358a9fcd42234e3 100644 (file)
@@ -8,6 +8,7 @@
 package Perl::Tidy::IndentationItem;
 use strict;
 use warnings;
+
 our $VERSION = '20230912.04';
 
 BEGIN {
@@ -149,14 +150,17 @@ sub tentatively_decrease_available_spaces {
     return $deleted_spaces;
 } ## end sub tentatively_decrease_available_spaces
 
+# time-critical sub
 sub get_spaces {
     return $_[0]->[_spaces_];
 }
 
 sub get_standard_spaces {
-    return $_[0]->[_standard_spaces_];
+    my $self = shift;
+    return $self->[_standard_spaces_];
 }
 
+# time-critical sub
 sub get_marked {
     return $_[0]->[_marked_];
 }
@@ -170,7 +174,8 @@ sub set_marked {
 } ## end sub set_marked
 
 sub get_available_spaces {
-    return $_[0]->[_available_spaces_];
+    my $self = shift;
+    return $self->[_available_spaces_];
 }
 
 sub decrease_SPACES {
@@ -191,11 +196,13 @@ sub decrease_available_spaces {
 } ## end sub decrease_available_spaces
 
 sub get_align_seqno {
-    return $_[0]->[_align_seqno_];
+    my $self = shift;
+    return $self->[_align_seqno_];
 }
 
 sub get_recoverable_spaces {
-    return $_[0]->[_recoverable_spaces_];
+    my $self = shift;
+    return $self->[_recoverable_spaces_];
 }
 
 sub set_recoverable_spaces {
@@ -215,11 +222,13 @@ sub increase_recoverable_spaces {
 } ## end sub increase_recoverable_spaces
 
 sub get_ci_level {
-    return $_[0]->[_ci_level_];
+    my $self = shift;
+    return $self->[_ci_level_];
 }
 
 sub get_level {
-    return $_[0]->[_level_];
+    my $self = shift;
+    return $self->[_level_];
 }
 
 sub get_spaces_level_ci {
@@ -228,15 +237,18 @@ sub get_spaces_level_ci {
 }
 
 sub get_lp_item_index {
-    return $_[0]->[_lp_item_index_];
+    my $self = shift;
+    return $self->[_lp_item_index_];
 }
 
 sub get_K_begin_line {
-    return $_[0]->[_K_begin_line_];
+    my $self = shift;
+    return $self->[_K_begin_line_];
 }
 
 sub get_K_extra_space {
-    return $_[0]->[_K_extra_space_];
+    my $self = shift;
+    return $self->[_K_extra_space_];
 }
 
 sub set_have_child {
@@ -248,7 +260,8 @@ sub set_have_child {
 } ## end sub set_have_child
 
 sub get_have_child {
-    return $_[0]->[_have_child_];
+    my $self = shift;
+    return $self->[_have_child_];
 }
 
 sub set_arrow_count {
@@ -260,7 +273,8 @@ sub set_arrow_count {
 } ## end sub set_arrow_count
 
 sub get_arrow_count {
-    return $_[0]->[_arrow_count_];
+    my $self = shift;
+    return $self->[_arrow_count_];
 }
 
 sub set_comma_count {
@@ -272,7 +286,8 @@ sub set_comma_count {
 } ## end sub set_comma_count
 
 sub get_comma_count {
-    return $_[0]->[_comma_count_];
+    my $self = shift;
+    return $self->[_comma_count_];
 }
 
 sub set_closed {
@@ -284,6 +299,7 @@ sub set_closed {
 } ## end sub set_closed
 
 sub get_closed {
-    return $_[0]->[_closed_];
+    my $self = shift;
+    return $self->[_closed_];
 }
 1;
index b60129700f51a342133ae5ac3e094e4126520773..58debd06d136a13b7b3f67c49e4103230564fdd5 100644 (file)
@@ -2,8 +2,11 @@ package Perl::Tidy::VerticalAligner;
 use strict;
 use warnings;
 use Carp;
-use English qw( -no_match_vars );
+
+{ #<<< A non-indenting brace to contain all lexical variables
+
 our $VERSION = '20230912.04';
+use English qw( -no_match_vars );
 use Perl::Tidy::VerticalAligner::Alignment;
 use Perl::Tidy::VerticalAligner::Line;
 
@@ -11,8 +14,6 @@ use constant DEVEL_MODE   => 0;
 use constant EMPTY_STRING => q{};
 use constant SPACE        => q{ };
 
-{ #<<< A non-indenting brace to contain all lexical variables
-
 # The Perl::Tidy::VerticalAligner package collects output lines and
 # attempts to line up certain common tokens, such as => and #, which are
 # identified by the calling routine.
@@ -199,7 +200,8 @@ BEGIN {
     use constant DEBUG_TABS => 0;
 
     my $debug_warning = sub {
-        print {*STDOUT} "VALIGN_DEBUGGING with key $_[0]\n";
+        my $msg = shift;
+        print {*STDOUT} "VALIGN_DEBUGGING with key $msg\n";
         return;
     };
 
@@ -423,7 +425,8 @@ sub initialize_for_new_group {
 } ## end sub initialize_for_new_group
 
 sub group_line_count {
-    return +@{ $_[0]->[_rgroup_lines_] };
+    my $self = shift;
+    return +@{ $self->[_rgroup_lines_] };
 }
 
 # interface to Perl::Tidy::Diagnostics routines
@@ -4872,11 +4875,13 @@ sub combine_fields {
 
 sub get_output_line_number {
 
+    # Return the output line number to external modules.
     # The output line number reported to a caller =
     # the number of items still in the buffer +
     # the number of items written.
-    return $_[0]->group_line_count() +
-      $_[0]->[_file_writer_object_]->get_output_line_number();
+    my $self = shift;
+    return $self->group_line_count() +
+      $self->[_file_writer_object_]->get_output_line_number();
 } ## end sub get_output_line_number
 
 ###############################
index 9427877a47efee47180ec07b9b2c01959cb39ff5..aee5105121b35856f9f813fdbfd0ea71938d40fa 100644 (file)
@@ -4,12 +4,11 @@
 # on a single column being aligned
 #
 #####################################################################
+
 package Perl::Tidy::VerticalAligner::Alignment;
 use strict;
 use warnings;
 
-{ #<<< A non-indenting brace
-
 our $VERSION = '20230912.04';
 
 sub new {
@@ -45,23 +44,25 @@ sub DESTROY {
 }
 
 sub get_column {
-    return $_[0]->{'column'};
+    my $self = shift;
+    return $self->{'column'};
 }
 
 sub increment_column {
-    $_[0]->{'column'} += $_[1];
-
+    my ( $self, $pad ) = @_;
+    $self->{'column'} += $pad;
     return;
 }
 
 sub save_column {
-    $_[0]->{'saved_column'} = $_[0]->{'column'};
+    my $self = shift;
+    $self->{'saved_column'} = $self->{'column'};
     return;
 }
 
 sub restore_column {
-    $_[0]->{'column'} = $_[0]->{'saved_column'};
+    my $self = shift;
+    $self->{'column'} = $self->{'saved_column'};
     return;
 }
-} ## end of package VerticalAligner::Alignment
 1;
index 107c52addfa3be5a4f75fcc159067232a5644d9c..a408e88661ab8493d436eaf1cf7a36d372397bb3 100644 (file)
@@ -9,8 +9,9 @@
 package Perl::Tidy::VerticalAligner::Line;
 use strict;
 use warnings;
-use English qw( -no_match_vars );
+
 our $VERSION = '20230912.04';
+use English qw( -no_match_vars );
 
 sub AUTOLOAD {
 
@@ -33,54 +34,51 @@ EOM
     exit 1;
 } ## end sub AUTOLOAD
 
-{
+# Constructor may be called as a class method
+sub new {
+    my ( $class, $ri ) = @_;
+    my $self = bless $ri, $class;
+    return $self;
+}
 
-    # Constructor may be called as a class method
-    sub new {
-        my ( $class, $ri ) = @_;
-        my $self = bless $ri, $class;
-        return $self;
-    }
+sub get_column {
+    my ( $self, $j ) = @_;
+    my $alignment = $self->{ralignments}->[$j];
+    return unless defined($alignment);
+    return $alignment->get_column();
+} ## end sub get_column
 
-    sub get_column {
-        my ( $self, $j ) = @_;
-        my $alignment = $self->{ralignments}->[$j];
-        return unless defined($alignment);
-        return $alignment->get_column();
-    } ## end sub get_column
+sub current_field_width {
+    my ( $self, $j ) = @_;
 
-    sub current_field_width {
-        my ( $self, $j ) = @_;
-        my $col_j  = 0;
-        my $col_jm = 0;
+    # Return number of columns of space between alignments $j and $j-1
 
-        my $alignment_j = $self->{ralignments}->[$j];
-        $col_j = $alignment_j->get_column() if defined($alignment_j);
+    my $alignment_j = $self->{ralignments}->[$j];
+    my $col_j       = defined($alignment_j) ? $alignment_j->get_column() : 0;
+    return $col_j if ( $j == 0 );
 
-        if ( $j > 0 ) {
-            my $alignment_jm = $self->{ralignments}->[ $j - 1 ];
-            $col_jm = $alignment_jm->get_column() if defined($alignment_jm);
-        }
-        return $col_j - $col_jm;
-    } ## end sub current_field_width
+    my $alignment_jm = $self->{ralignments}->[ $j - 1 ];
+    my $col_jm       = defined($alignment_jm) ? $alignment_jm->get_column() : 0;
+    return $col_j - $col_jm;
 
-    sub increase_field_width {
+} ## end sub current_field_width
 
-        my ( $self, $j, $pad ) = @_;
-        my $jmax = $self->{jmax};
-        foreach ( $j .. $jmax ) {
-            my $alignment = $self->{ralignments}->[$_];
-            if ( defined($alignment) ) {
-                $alignment->increment_column($pad);
-            }
-        }
-        return;
-    } ## end sub increase_field_width
+sub increase_field_width {
 
-    sub get_available_space_on_right {
-        my $jmax = $_[0]->{jmax};
-        return $_[0]->{maximum_line_length} - $_[0]->get_column($jmax);
+    my ( $self, $j, $pad ) = @_;
+    my $jmax = $self->{jmax};
+    foreach ( $j .. $jmax ) {
+        my $alignment = $self->{ralignments}->[$_];
+        if ( defined($alignment) ) {
+            $alignment->increment_column($pad);
+        }
     }
-}
+    return;
+} ## end sub increase_field_width
 
+sub get_available_space_on_right {
+    my $self = shift;
+    my $jmax = $self->{jmax};
+    return $self->{maximum_line_length} - $self->get_column($jmax);
+}
 1;