line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Indent::Form; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
69810
|
use strict; |
|
4
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
88
|
|
4
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
86
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
1498
|
use Class::Utils qw(set_params); |
|
4
|
|
|
|
|
77229
|
|
|
4
|
|
|
|
|
57
|
|
7
|
4
|
|
|
4
|
|
217
|
use English qw(-no_match_vars); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
18
|
|
8
|
4
|
|
|
4
|
|
977
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
116
|
|
9
|
4
|
|
|
4
|
|
1450
|
use Indent::Word; |
|
4
|
|
|
|
|
8021
|
|
|
4
|
|
|
|
|
149
|
|
10
|
4
|
|
|
4
|
|
20
|
use List::MoreUtils qw(none); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
18
|
|
11
|
4
|
|
|
4
|
|
2044
|
use Readonly; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
2648
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Constants. |
14
|
|
|
|
|
|
|
Readonly::Scalar my $EMPTY_STR => q{}; |
15
|
|
|
|
|
|
|
Readonly::Scalar my $LINE_SIZE => 79; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $SPACE => q{ }; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = 0.05; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Constructor. |
21
|
|
|
|
|
|
|
sub new { |
22
|
16
|
|
|
16
|
1
|
12989
|
my ($class, @params) = @_; |
23
|
16
|
|
|
|
|
33
|
my $self = bless {}, $class; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Use with ANSI sequences. |
26
|
16
|
|
|
|
|
38
|
$self->{'ansi'} = 0; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Align. |
29
|
16
|
|
|
|
|
21
|
$self->{'align'} = 'right'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Fill character. |
32
|
16
|
|
|
|
|
29
|
$self->{'fill_character'} = $SPACE; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Form separator. |
35
|
16
|
|
|
|
|
19
|
$self->{'form_separator'} = ': '; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Line size. |
38
|
16
|
|
|
|
|
20
|
$self->{'line_size'} = $LINE_SIZE; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Next indent. |
41
|
16
|
|
|
|
|
22
|
$self->{'next_indent'} = undef; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Output separator. |
44
|
16
|
|
|
|
|
48
|
$self->{'output_separator'} = "\n"; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Process params. |
47
|
16
|
|
|
|
|
39
|
set_params($self, @params); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Check align. |
50
|
14
|
100
|
|
27
|
|
184
|
if (none { $self->{'align'} eq $_ } qw(left right)) { |
|
27
|
|
|
|
|
148
|
|
51
|
1
|
|
|
|
|
3
|
err '\'align\' parameter must be a \'left\' or \'right\' '. |
52
|
|
|
|
|
|
|
'string.'; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# 'line_size' check. |
56
|
13
|
100
|
|
|
|
80
|
if ($self->{'line_size'} !~ /^\d*$/ms) { |
57
|
|
|
|
|
|
|
err '\'line_size\' parameter must be a number.', |
58
|
3
|
|
|
|
|
14
|
'line_size', $self->{'line_size'}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Check rutine for removing ANSI sequences. |
62
|
10
|
50
|
|
|
|
22
|
if ($self->{'ansi'}) { |
63
|
0
|
|
|
|
|
0
|
eval { |
64
|
0
|
|
|
|
|
0
|
require Text::ANSI::Util; |
65
|
|
|
|
|
|
|
}; |
66
|
0
|
0
|
|
|
|
0
|
if ($EVAL_ERROR) { |
67
|
0
|
|
|
|
|
0
|
err "Cannot load 'Text::ANSI::Util' module."; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Object. |
72
|
10
|
|
|
|
|
38
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Indent form data. |
76
|
|
|
|
|
|
|
sub indent { |
77
|
9
|
|
|
9
|
1
|
94
|
my ($self, $data_ar, $actual_indent, $non_indent_flag) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Undef indent. |
80
|
9
|
100
|
|
|
|
14
|
if (! $actual_indent) { |
81
|
8
|
|
|
|
|
11
|
$actual_indent = $EMPTY_STR; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Max size of key. |
85
|
9
|
|
|
|
|
10
|
my $max = 0; |
86
|
9
|
|
|
|
|
9
|
my @data; |
87
|
9
|
|
|
|
|
10
|
foreach my $dat (@{$data_ar}) { |
|
9
|
|
|
|
|
15
|
|
88
|
28
|
100
|
|
|
|
36
|
if ($self->_length($dat->[0]) > $max) { |
89
|
13
|
|
|
|
|
19
|
$max = $self->_length($dat->[0]); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Non-indent. |
93
|
28
|
100
|
|
|
|
47
|
if ($non_indent_flag) { |
94
|
8
|
|
|
|
|
13
|
push @data, $self->_value($dat->[0]).$self->{'form_separator'}. |
95
|
|
|
|
|
|
|
$self->_value($dat->[1]); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# If non-indent. |
100
|
|
|
|
|
|
|
# Return as array or one line with output separator between its. |
101
|
9
|
100
|
|
|
|
15
|
if ($non_indent_flag) { |
102
|
|
|
|
|
|
|
return wantarray ? @data |
103
|
2
|
100
|
|
|
|
9
|
: join $self->{'output_separator'}, @data; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Indent word. |
107
|
|
|
|
|
|
|
my $next_indent = $self->{'next_indent'} ? $self->{'next_indent'} |
108
|
7
|
50
|
|
|
|
15
|
: $SPACE x ($max + $self->_length($self->{'form_separator'})); |
109
|
|
|
|
|
|
|
my $word = Indent::Word->new( |
110
|
|
|
|
|
|
|
'ansi' => $self->{'ansi'}, |
111
|
|
|
|
|
|
|
'line_size' => $self->{'line_size'} - $max |
112
|
7
|
|
|
|
|
14
|
- $self->_length($self->{'form_separator'}), |
113
|
|
|
|
|
|
|
'next_indent' => $next_indent, |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
|
116
|
7
|
|
|
|
|
264
|
foreach my $dat_ar (@{$data_ar}) { |
|
7
|
|
|
|
|
12
|
|
117
|
20
|
|
|
|
|
21
|
my $output = $actual_indent; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Left side, left align. |
120
|
20
|
100
|
|
|
|
34
|
if ($self->{'align'} eq 'left') { |
121
|
3
|
|
|
|
|
6
|
$output .= $self->_value($dat_ar->[0]); |
122
|
3
|
|
|
|
|
5
|
$output .= $self->{'fill_character'} |
123
|
|
|
|
|
|
|
x ($max - $self->_length($dat_ar->[0])); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Left side, right align. |
126
|
|
|
|
|
|
|
} else { |
127
|
17
|
|
|
|
|
23
|
$output .= $self->{'fill_character'} |
128
|
|
|
|
|
|
|
x ($max - $self->_length($dat_ar->[0])); |
129
|
17
|
|
|
|
|
27
|
$output .= $self->_value($dat_ar->[0]); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Right side. |
133
|
20
|
|
|
|
|
27
|
$output .= $self->{'form_separator'}; |
134
|
20
|
|
|
|
|
29
|
my @tmp = $word->indent($self->_value($dat_ar->[1])); |
135
|
20
|
100
|
|
|
|
579
|
$output .= shift @tmp if @tmp; |
136
|
20
|
|
|
|
|
29
|
push @data, $output; |
137
|
20
|
|
|
|
|
36
|
while (@tmp) { |
138
|
4
|
|
|
|
|
10
|
push @data, $actual_indent.shift @tmp; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Return as array or one line with output separator between its. |
143
|
7
|
100
|
|
|
|
35
|
return wantarray ? @data : join $self->{'output_separator'}, @data; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# Get length. |
147
|
|
|
|
|
|
|
sub _length { |
148
|
75
|
|
|
75
|
|
97
|
my ($self, $string) = @_; |
149
|
|
|
|
|
|
|
|
150
|
75
|
100
|
|
|
|
100
|
if (! defined $string) { |
151
|
10
|
|
|
|
|
18
|
return 0; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
65
|
50
|
|
|
|
83
|
if ($self->{'ansi'}) { |
155
|
0
|
|
|
|
|
0
|
return length Text::ANSI::Util::ta_strip($string); |
156
|
|
|
|
|
|
|
} else { |
157
|
65
|
|
|
|
|
125
|
return length $string; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub _value { |
162
|
56
|
|
|
56
|
|
71
|
my ($self, $string) = @_; |
163
|
|
|
|
|
|
|
|
164
|
56
|
100
|
|
|
|
68
|
if (! defined $string) { |
165
|
13
|
|
|
|
|
24
|
return $EMPTY_STR; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
43
|
|
|
|
|
74
|
return $string; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__ |