]> git.donarmstrong.com Git - perltidy.git/blob - lib/Perl/Tidy/VerticalAligner/Line.pm
New upstream version 20230309
[perltidy.git] / lib / Perl / Tidy / VerticalAligner / Line.pm
1 #####################################################################
2 #
3 # The Perl::Tidy::VerticalAligner::Line class supplies an object to
4 # contain a single output line.  It allows manipulation of the
5 # alignment columns on that line.
6 #
7 #####################################################################
8
9 package Perl::Tidy::VerticalAligner::Line;
10 use strict;
11 use warnings;
12 use English qw( -no_match_vars );
13 our $VERSION = '20230309';
14
15 sub AUTOLOAD {
16
17     # Catch any undefined sub calls so that we are sure to get
18     # some diagnostic information.  This sub should never be called
19     # except for a programming error.
20     our $AUTOLOAD;
21     return if ( $AUTOLOAD =~ /\bDESTROY$/ );
22     my ( $pkg, $fname, $lno ) = caller();
23     my $my_package = __PACKAGE__;
24     print STDERR <<EOM;
25 ======================================================================
26 Error detected in package '$my_package', version $VERSION
27 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
28 Called from package: '$pkg'  
29 Called from File '$fname'  at line '$lno'
30 This error is probably due to a recent programming change
31 ======================================================================
32 EOM
33     exit 1;
34 } ## end sub AUTOLOAD
35
36 {
37
38     # Constructor may be called as a class method
39     sub new {
40         my ( $class, $ri ) = @_;
41         my $self = bless $ri, $class;
42         return $self;
43     }
44
45     sub get_column {
46         my ( $self, $j ) = @_;
47         my $alignment = $self->{ralignments}->[$j];
48         return unless defined($alignment);
49         return $alignment->get_column();
50     } ## end sub get_column
51
52     sub current_field_width {
53         my ( $self, $j ) = @_;
54         my $col_j  = 0;
55         my $col_jm = 0;
56
57         my $alignment_j = $self->{ralignments}->[$j];
58         $col_j = $alignment_j->get_column() if defined($alignment_j);
59
60         if ( $j > 0 ) {
61             my $alignment_jm = $self->{ralignments}->[ $j - 1 ];
62             $col_jm = $alignment_jm->get_column() if defined($alignment_jm);
63         }
64         return $col_j - $col_jm;
65     } ## end sub current_field_width
66
67     sub increase_field_width {
68
69         my ( $self, $j, $pad ) = @_;
70         my $jmax = $self->{jmax};
71         foreach ( $j .. $jmax ) {
72             my $alignment = $self->{ralignments}->[$_];
73             if ( defined($alignment) ) {
74                 $alignment->increment_column($pad);
75             }
76         }
77         return;
78     } ## end sub increase_field_width
79
80     sub get_available_space_on_right {
81         my $jmax = $_[0]->{jmax};
82         return $_[0]->{maximum_line_length} - $_[0]->get_column($jmax);
83     }
84 }
85
86 1;