From 35a029900773b28a88bd317ef64b23bf5187f0fd Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 18 Oct 2023 07:28:11 -0700 Subject: [PATCH] unpack args of non time-critical subs --- .perlcriticrc | 9 +-- lib/Perl/Tidy/FileWriter.pm | 15 ++-- lib/Perl/Tidy/IndentationItem.pm | 42 ++++++++---- lib/Perl/Tidy/VerticalAligner.pm | 19 +++-- lib/Perl/Tidy/VerticalAligner/Alignment.pm | 17 ++--- lib/Perl/Tidy/VerticalAligner/Line.pm | 80 +++++++++++----------- 6 files changed, 104 insertions(+), 78 deletions(-) diff --git a/.perlcriticrc b/.perlcriticrc index 57a1f3bd..f29fb9dc 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -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" diff --git a/lib/Perl/Tidy/FileWriter.pm b/lib/Perl/Tidy/FileWriter.pm index 52a5a60c..83f98103 100644 --- a/lib/Perl/Tidy/FileWriter.pm +++ b/lib/Perl/Tidy/FileWriter.pm @@ -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; } diff --git a/lib/Perl/Tidy/IndentationItem.pm b/lib/Perl/Tidy/IndentationItem.pm index d16dee06..3dffe82a 100644 --- a/lib/Perl/Tidy/IndentationItem.pm +++ b/lib/Perl/Tidy/IndentationItem.pm @@ -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; diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index b6012970..58debd06 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -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 ############################### diff --git a/lib/Perl/Tidy/VerticalAligner/Alignment.pm b/lib/Perl/Tidy/VerticalAligner/Alignment.pm index 9427877a..aee51051 100644 --- a/lib/Perl/Tidy/VerticalAligner/Alignment.pm +++ b/lib/Perl/Tidy/VerticalAligner/Alignment.pm @@ -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; diff --git a/lib/Perl/Tidy/VerticalAligner/Line.pm b/lib/Perl/Tidy/VerticalAligner/Line.pm index 107c52ad..a408e886 100644 --- a/lib/Perl/Tidy/VerticalAligner/Line.pm +++ b/lib/Perl/Tidy/VerticalAligner/Line.pm @@ -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; -- 2.39.5