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