| 1 | package Perl::Tidy::VerticalAligner::Line; | ||||||||||
| 2 | |||||||||||
| 3 | ##################################################################### | ||||||||||
| 4 | # | ||||||||||
| 5 | # The Perl::Tidy::VerticalAligner::Line class supplies an object to | ||||||||||
| 6 | # contain a single output line. It allows manipulation of the | ||||||||||
| 7 | # alignment columns on that line. | ||||||||||
| 8 | # | ||||||||||
| 9 | ##################################################################### | ||||||||||
| 10 | |||||||||||
| 11 | 45 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 45 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 45 | our $VERSION = '20260826'; | |||||||||
| 15 | 45 | ▶ | use English qw( -no_match_vars ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | { | ||||||||||
| 18 | # List of hash keys to prevent -duk from listing them. | ||||||||||
| 19 | 45 | my @unique_hash_keys_uu = qw( maximum_line_length ); | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | sub AUTOLOAD { | ||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=17.9
| |||||||||||
| 23 | |||||||||||
| 24 | # Catch any undefined sub calls so that we are sure to get | ||||||||||
| 25 | # some diagnostic information. This sub should never be called | ||||||||||
| 26 | # except for a programming error. | ||||||||||
| 27 | 0 | our $AUTOLOAD; | |||||||||
| 28 | 0 | ▶ | return if ( $AUTOLOAD =~ /\bDESTROY$/ ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | my ( $pkg, $fname, $lno ) = caller(); | |||||||||
| 30 | 0 | my $my_package = __PACKAGE__; | |||||||||
| 31 | 0 | print {*STDERR} <<EOM; | |||||||||
| 32 | ====================================================================== | ||||||||||
| 33 | Error detected in package '$my_package', version $VERSION | ||||||||||
| 34 | Received unexpected AUTOLOAD call for sub '$AUTOLOAD' | ||||||||||
| 35 | Called from package: '$pkg' | ||||||||||
| 36 | Called from File '$fname' at line '$lno' | ||||||||||
| 37 | This error is probably due to a recent programming change | ||||||||||
| 38 | ====================================================================== | ||||||||||
| 39 | EOM | ||||||||||
| 40 | 0 | exit 1; | |||||||||
| 41 | } ## end sub AUTOLOAD | ||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub DESTROY { | ||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||
| 44 | |||||||||||
| 45 | # required to avoid call to AUTOLOAD in some versions of perl | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | # Constructor may be called as a class method | ||||||||||
| 49 | 3651 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 50 | |||||||||||
| 51 | 3651 | my ( $class, $rhash ) = @_; | |||||||||
| 52 | |||||||||||
| 53 | # Create a new VerticalAligner::Line object | ||||||||||
| 54 | # Given: | ||||||||||
| 55 | # $rhash = ref to hash for a Line | ||||||||||
| 56 | # This hash contains parameters describing one line. | ||||||||||
| 57 | # The parameters currently used by this object are: | ||||||||||
| 58 | # {ralignments} = ref to array of vertical alignment columns | ||||||||||
| 59 | # {jmax} = max index of {ralignments} | ||||||||||
| 60 | # {maximum_line_length} = maximum number of spaces for this line | ||||||||||
| 61 | |||||||||||
| 62 | 3651 | my $self = bless $rhash, $class; | |||||||||
| 63 | 3651 | return $self; | |||||||||
| 64 | } ## end sub new | ||||||||||
| 65 | |||||||||||
| 66 | 3033 | ▶ | sub get_column { | ||||||||
|
Subroutine
get_column: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 67 | |||||||||||
| 68 | 3033 | my ( $self, $j ) = @_; | |||||||||
| 69 | |||||||||||
| 70 | # Return the current column number of alignment $j | ||||||||||
| 71 | |||||||||||
| 72 | 3033 | my $alignment = $self->{ralignments}->[$j]; | |||||||||
| 73 | 3033 | ▶ | return unless ( defined($alignment) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 3033 | return $alignment->get_column(); | |||||||||
| 75 | } ## end sub get_column | ||||||||||
| 76 | |||||||||||
| 77 | 4037 | ▶ | sub current_field_width { | ||||||||
|
Subroutine
current_field_width: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||
| 78 | |||||||||||
| 79 | 4037 | my ( $self, $j ) = @_; | |||||||||
| 80 | |||||||||||
| 81 | # Return number of columns of space between alignments $j and $j-1 | ||||||||||
| 82 | |||||||||||
| 83 | 4037 | my $alignment_j = $self->{ralignments}->[$j]; | |||||||||
| 84 | 4037 | ▶ | my $col_j = defined($alignment_j) ? $alignment_j->get_column() : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 4037 | ▶ | return $col_j if ( $j == 0 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | |||||||||||
| 87 | 2890 | my $alignment_jm = $self->{ralignments}->[ $j - 1 ]; | |||||||||
| 88 | 2890 | ▶ | my $col_jm = defined($alignment_jm) ? $alignment_jm->get_column() : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 2890 | return $col_j - $col_jm; | |||||||||
| 90 | |||||||||||
| 91 | } ## end sub current_field_width | ||||||||||
| 92 | |||||||||||
| 93 | 3056 | ▶ | sub increase_field_width { | ||||||||
|
Subroutine
increase_field_width: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 94 | |||||||||||
| 95 | 3056 | my ( $self, $j, $pad ) = @_; | |||||||||
| 96 | |||||||||||
| 97 | # Increase the width of alignment field $j by $pad spaces. | ||||||||||
| 98 | # So we must increase the widths of the higher alignments by $pad spaces. | ||||||||||
| 99 | 3056 | my $jmax = $self->{jmax}; | |||||||||
| 100 | 3056 | foreach ( $j .. $jmax ) { | |||||||||
| 101 | 7222 | my $alignment = $self->{ralignments}->[$_]; | |||||||||
| 102 | 7222 | ▶ | if ( defined($alignment) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 7222 | $alignment->increment_column($pad); | |||||||||
| 104 | } | ||||||||||
| 105 | } | ||||||||||
| 106 | 3056 | return; | |||||||||
| 107 | } ## end sub increase_field_width | ||||||||||
| 108 | |||||||||||
| 109 | 1809 | ▶ | sub get_available_space_on_right { | ||||||||
|
Subroutine
get_available_space_on_right: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 110 | 1809 | my $self = shift; | |||||||||
| 111 | |||||||||||
| 112 | # Return the number of unused columns to the right of the last alignment | ||||||||||
| 113 | 1809 | my $jmax = $self->{jmax}; | |||||||||
| 114 | 1809 | return $self->{maximum_line_length} - $self->get_column($jmax); | |||||||||
| 115 | } ## end sub get_available_space_on_right | ||||||||||
| 116 | 45 | 1; | |||||||||