Tidy/VerticalAligner/Line.pm

filter: Statementstmt 84.0% 37 / 44 Branchbran 50.0% 6 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 5 totaltotal 71.8% 51 / 71 CC 8 SCAR 10.2
CC
8
Cov
77%
AUTOLOAD
6.0
current_field_width
4.1
increase_field_width
3.0
CRAP 2.8
« Tidy/Debugger.pm ↑ Summary Tidy/VerticalAligner/Alignment.pm »
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 = '20260808';
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 sub AUTOLOAD {
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;
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
28 0 ▶ return if ( $AUTOLOAD =~ /\bDESTROY$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $Perl::Tidy::VerticalAligner::Line::AUTOLOAD =~ /\bDESTROY$/ 0 0 0
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 ▶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 sub new {
50  
51 3647 ▶ my ( $class, $rhash ) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
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 3647 my $self = bless $rhash, $class;
63 3647 return $self;
64 } ## end sub new
65  
66 sub get_column {
67  
68 3035 ▶ my ( $self, $j ) = @_;
Subroutine get_column: called CC=2 SCAR=7.0
Pod undocumented
69  
70 # Return the current column number of alignment $j
71  
72 3035 my $alignment = $self->{ralignments}->[$j];
73 3035 ▶ return unless ( defined($alignment) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $alignment 0 3035 3035
74 3035 return $alignment->get_column();
75 } ## end sub get_column
76  
77 sub current_field_width {
78  
79 4043 ▶ my ( $self, $j ) = @_;
Subroutine current_field_width: called CC=4 SCAR=14.0
Pod undocumented
80  
81 # Return number of columns of space between alignments $j and $j-1
82  
83 4043 my $alignment_j = $self->{ralignments}->[$j];
84 4043 ▶ my $col_j = defined($alignment_j) ? $alignment_j->get_column() : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $alignment_j ? : 4043 0 4043
85 4043 ▶ return $col_j if ( $j == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $j == 0 1149 2894 4043
86  
87 2894 my $alignment_jm = $self->{ralignments}->[ $j - 1 ];
88 2894 ▶ my $col_jm = defined($alignment_jm) ? $alignment_jm->get_column() : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $alignment_jm ? : 2894 0 2894
89 2894 return $col_j - $col_jm;
90  
91 } ## end sub current_field_width
92  
93 sub increase_field_width {
94  
95 3060 ▶ my ( $self, $j, $pad ) = @_;
Subroutine increase_field_width: called CC=3 SCAR=11.0
Pod undocumented
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 3060 my $jmax = $self->{jmax};
100 3060 foreach ( $j .. $jmax ) {
101 7228 my $alignment = $self->{ralignments}->[$_];
102 7228 ▶ if ( defined($alignment) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $alignment) 7228 0 7228
103 7228 $alignment->increment_column($pad);
104 }
105 }
106 3060 return;
107 } ## end sub increase_field_width
108  
109 sub get_available_space_on_right {
110 1811 ▶ my $self = shift;
Subroutine get_available_space_on_right: called CC=1 SCAR=0.0
Pod undocumented
111  
112 # Return the number of unused columns to the right of the last alignment
113 1811 my $jmax = $self->{jmax};
114 1811 return $self->{maximum_line_length} - $self->get_column($jmax);
115 } ## end sub get_available_space_on_right
116 45 1;
« Tidy/Debugger.pm ↑ Summary Tidy/VerticalAligner/Alignment.pm »