]> git.donarmstrong.com Git - perltidy.git/blob - lib/Perl/Tidy/VerticalAligner/Alignment.pm
New upstream version 20210717
[perltidy.git] / lib / Perl / Tidy / VerticalAligner / Alignment.pm
1 #####################################################################
2 #
3 # the Perl::Tidy::VerticalAligner::Alignment class holds information
4 # on a single column being aligned
5 #
6 #####################################################################
7 package Perl::Tidy::VerticalAligner::Alignment;
8 use strict;
9 use warnings;
10
11 { #<<< A non-indenting brace
12
13 our $VERSION = '20210717';
14
15 #    _column_          # the current column number
16 #    _saved_column_    # a place for temporary storage
17 my $i = 0;
18 use constant {
19     _column_       => $i++,
20     _saved_column_ => $i++,
21 };
22
23 sub new {
24     my ( $class, $rarg ) = @_;
25     my $self = bless [], $class;
26     $self->[_column_]       = $rarg->{column};
27     $self->[_saved_column_] = $rarg->{saved_column};
28     return $self;
29 }
30
31 sub AUTOLOAD {
32
33     # Catch any undefined sub calls so that we are sure to get
34     # some diagnostic information.  This sub should never be called
35     # except for a programming error.
36     our $AUTOLOAD;
37     return if ( $AUTOLOAD =~ /\bDESTROY$/ );
38     my ( $pkg, $fname, $lno ) = caller();
39     my $my_package = __PACKAGE__;
40     print STDERR <<EOM;
41 ======================================================================
42 Error detected in package '$my_package', version $VERSION
43 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
44 Called from package: '$pkg'  
45 Called from File '$fname'  at line '$lno'
46 This error is probably due to a recent programming change
47 ======================================================================
48 EOM
49     exit 1;
50 }
51
52 sub DESTROY {
53
54     # required to avoid call to AUTOLOAD in some versions of perl
55 }
56
57 sub get_column {
58     return $_[0]->[_column_];
59 }
60
61 sub increment_column {
62     $_[0]->[_column_] += $_[1];
63     return;
64 }
65
66 sub save_column {
67     $_[0]->[_saved_column_] = $_[0]->[_column_];
68     return;
69 }
70
71 sub restore_column {
72     $_[0]->[_column_] = $_[0]->[_saved_column_];
73     return;
74 }
75 } ## end of package VerticalAligner::Alignment
76 1;
77