File Coverage

blib/lib/Perl/Tidy/VerticalAligner/Line.pm
Criterion Covered Total %
statement 36 40 90.0
branch 7 12 58.3
condition n/a
subroutine 9 9 100.0
pod 0 5 0.0
total 52 66 78.7


line stmt bran cond sub pod time code
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 38     38   290 use strict;
  38         83  
  38         1441  
11 38     38   231 use warnings;
  38         95  
  38         1056  
12 38     38   222 use English qw( -no_match_vars );
  38         98  
  38         239  
13             our $VERSION = '20230701';
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 2991     2991   6139 our $AUTOLOAD;
21 2991 50       46391 return if ( $AUTOLOAD =~ /\bDESTROY$/ );
22 0         0 my ( $pkg, $fname, $lno ) = caller();
23 0         0 my $my_package = __PACKAGE__;
24 0         0 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 0         0 exit 1;
34             } ## end sub AUTOLOAD
35              
36             {
37              
38             # Constructor may be called as a class method
39             sub new {
40 3061     3061 0 8529 my ( $class, $ri ) = @_;
41 3061         7277 my $self = bless $ri, $class;
42 3061         8238 return $self;
43             }
44              
45             sub get_column {
46 2638     2638 0 4944 my ( $self, $j ) = @_;
47 2638         4666 my $alignment = $self->{ralignments}->[$j];
48 2638 50       5652 return unless defined($alignment);
49 2638         6803 return $alignment->get_column();
50             } ## end sub get_column
51              
52             sub current_field_width {
53 3425     3425 0 5950 my ( $self, $j ) = @_;
54 3425         4918 my $col_j = 0;
55 3425         4682 my $col_jm = 0;
56              
57 3425         5393 my $alignment_j = $self->{ralignments}->[$j];
58 3425 50       8731 $col_j = $alignment_j->get_column() if defined($alignment_j);
59              
60 3425 100       7442 if ( $j > 0 ) {
61 2433         6467 my $alignment_jm = $self->{ralignments}->[ $j - 1 ];
62 2433 50       6390 $col_jm = $alignment_jm->get_column() if defined($alignment_jm);
63             }
64 3425         7284 return $col_j - $col_jm;
65             } ## end sub current_field_width
66              
67             sub increase_field_width {
68              
69 2659     2659 0 4947 my ( $self, $j, $pad ) = @_;
70 2659         4444 my $jmax = $self->{jmax};
71 2659         5479 foreach ( $j .. $jmax ) {
72 6338         9619 my $alignment = $self->{ralignments}->[$_];
73 6338 50       11974 if ( defined($alignment) ) {
74 6338         12693 $alignment->increment_column($pad);
75             }
76             }
77 2659         4987 return;
78             } ## end sub increase_field_width
79              
80             sub get_available_space_on_right {
81 1562     1562 0 3173 my $jmax = $_[0]->{jmax};
82 1562         4684 return $_[0]->{maximum_line_length} - $_[0]->get_column($jmax);
83             }
84             }
85              
86             1;