| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Indent::Word; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
78067
|
use strict; |
|
|
4
|
|
|
|
|
34
|
|
|
|
4
|
|
|
|
|
117
|
|
|
4
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
127
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
1887
|
use Class::Utils qw(set_params); |
|
|
4
|
|
|
|
|
114937
|
|
|
|
4
|
|
|
|
|
77
|
|
|
7
|
4
|
|
|
4
|
|
292
|
use English qw(-no_match_vars); |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
22
|
|
|
8
|
4
|
|
|
4
|
|
1334
|
use Error::Pure qw(err); |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
165
|
|
|
9
|
4
|
|
|
4
|
|
1678
|
use Indent::Utils qw(line_size_check); |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
208
|
|
|
10
|
4
|
|
|
4
|
|
26
|
use Readonly; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
3078
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Constants. |
|
13
|
|
|
|
|
|
|
Readonly::Scalar my $EMPTY_STR => q{}; |
|
14
|
|
|
|
|
|
|
Readonly::Scalar my $LINE_SIZE => 79; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 0.06; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Constructor. |
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
10
|
|
|
10
|
1
|
8293
|
my ($class, @params) = @_; |
|
21
|
10
|
|
|
|
|
29
|
my $self = bless {}, $class; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Use with ANSI sequences. |
|
24
|
10
|
|
|
|
|
28
|
$self->{'ansi'} = 0; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Options. |
|
27
|
10
|
|
|
|
|
19
|
$self->{'line_size'} = $LINE_SIZE; |
|
28
|
10
|
|
|
|
|
18
|
$self->{'next_indent'} = "\t"; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Output. |
|
31
|
10
|
|
|
|
|
20
|
$self->{'output_separator'} = "\n"; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Process params. |
|
34
|
10
|
|
|
|
|
36
|
set_params($self, @params); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# 'line_size' check. |
|
37
|
8
|
|
|
|
|
142
|
line_size_check($self); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Check rutine for removing ANSI sequences. |
|
40
|
8
|
100
|
|
|
|
17
|
if ($self->{'ansi'}) { |
|
41
|
1
|
|
|
|
|
3
|
eval { |
|
42
|
1
|
|
|
|
|
6
|
require Text::ANSI::Util; |
|
43
|
|
|
|
|
|
|
}; |
|
44
|
1
|
50
|
|
|
|
4
|
if ($EVAL_ERROR) { |
|
45
|
0
|
|
|
|
|
0
|
err "Cannot load 'Text::ANSI::Util' module."; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Object. |
|
50
|
8
|
|
|
|
|
35
|
return $self; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Indent text by words to line_size block size. |
|
54
|
|
|
|
|
|
|
sub indent { |
|
55
|
10
|
|
|
10
|
1
|
2932
|
my ($self, $data, $indent, $non_indent) = @_; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# 'indent' initialization. |
|
58
|
10
|
100
|
|
|
|
26
|
if (! defined $indent) { |
|
59
|
4
|
|
|
|
|
7
|
$indent = $EMPTY_STR; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# If non_indent data, than return. |
|
63
|
10
|
100
|
|
|
|
18
|
if ($non_indent) { |
|
64
|
1
|
|
|
|
|
4
|
return $indent.$data; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
9
|
|
|
|
|
25
|
my ($first, $second) = (undef, $indent.$data); |
|
68
|
9
|
|
|
|
|
14
|
my $last_second_length = 0; |
|
69
|
9
|
|
|
|
|
10
|
my @data; |
|
70
|
9
|
|
|
|
|
11
|
my $one = 1; |
|
71
|
9
|
|
100
|
|
|
19
|
while ($self->_length($second) >= $self->{'line_size'} |
|
|
|
|
100
|
|
|
|
|
|
72
|
|
|
|
|
|
|
&& $second =~ /^\s*\S+\s+/ms |
|
73
|
|
|
|
|
|
|
&& $last_second_length != $self->_length($second)) { |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Last length of non-parsed part of data. |
|
76
|
15
|
|
|
|
|
92
|
$last_second_length = $self->_length($second); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Parse to indent length. |
|
79
|
15
|
|
|
|
|
93
|
($first, my $tmp) = $self->_parse_to_indent_length($second); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# If string is non-breakable in indent length, than parse to |
|
82
|
|
|
|
|
|
|
# blank char. |
|
83
|
15
|
100
|
100
|
|
|
45
|
if (! $first |
|
|
|
|
66
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|| $self->_length($first) < $self->_length($indent) |
|
85
|
|
|
|
|
|
|
|| $first =~ /^$indent\s*$/ms) { |
|
86
|
|
|
|
|
|
|
|
|
87
|
5
|
|
|
|
|
96
|
($first, $tmp) = $second |
|
88
|
|
|
|
|
|
|
=~ /^($indent\s*[^\s]+?)\s(.*)$/msx; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# If parsing is right. |
|
92
|
15
|
100
|
|
|
|
89
|
if ($tmp) { |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Non-parsed part of data. |
|
95
|
13
|
|
|
|
|
23
|
$second = $tmp; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Add next_indent to string. |
|
98
|
13
|
100
|
|
|
|
21
|
if ($one == 1) { |
|
99
|
5
|
|
|
|
|
10
|
$indent .= $self->{'next_indent'}; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
13
|
|
|
|
|
19
|
$one = 0; |
|
102
|
13
|
|
|
|
|
25
|
$second = $indent.$second; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Parsed part of data to @data array. |
|
105
|
13
|
|
|
|
|
34
|
push @data, $first; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Add other data to @data array. |
|
110
|
9
|
|
|
|
|
38
|
$second =~ s/\s+$//ms; |
|
111
|
9
|
100
|
|
|
|
18
|
if ($second) { |
|
112
|
7
|
|
|
|
|
14
|
push @data, $second; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Return as array or one line with output separator between its. |
|
116
|
9
|
100
|
|
|
|
47
|
return wantarray ? @data : join($self->{'output_separator'}, @data); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Get length. |
|
120
|
|
|
|
|
|
|
sub _length { |
|
121
|
78
|
|
|
78
|
|
290
|
my ($self, $string) = @_; |
|
122
|
78
|
100
|
|
|
|
129
|
if ($self->{'ansi'}) { |
|
123
|
16
|
|
|
|
|
33
|
return length Text::ANSI::Util::ta_strip($string); |
|
124
|
|
|
|
|
|
|
} else { |
|
125
|
62
|
|
|
|
|
314
|
return length $string; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Parse to indent length. |
|
130
|
|
|
|
|
|
|
sub _parse_to_indent_length { |
|
131
|
15
|
|
|
15
|
|
21
|
my ($self, $string) = @_; |
|
132
|
15
|
|
|
|
|
18
|
my @ret; |
|
133
|
15
|
100
|
|
|
|
27
|
if ($self->{'ansi'}) { |
|
134
|
3
|
|
|
|
|
7
|
my $string_wo_ansi = Text::ANSI::Util::ta_strip($string); |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# First part. |
|
137
|
3
|
|
|
|
|
92
|
my ($first_wo_ansi) = $string_wo_ansi |
|
138
|
|
|
|
|
|
|
=~ m/^(.{0,$self->{'line_size'}})\s+(.*)$/msx; |
|
139
|
3
|
|
|
|
|
12
|
push @ret, Text::ANSI::Util::ta_trunc($string, length $first_wo_ansi); |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Second part. (Remove first part + whitespace from string.) |
|
142
|
3
|
|
|
|
|
1380
|
my $other_string_wo_ansi = Text::ANSI::Util::ta_strip( |
|
143
|
|
|
|
|
|
|
Text::ANSI::Util::ta_substr($string, length $first_wo_ansi, |
|
144
|
|
|
|
|
|
|
Text::ANSI::Util::ta_length($string)) |
|
145
|
|
|
|
|
|
|
); |
|
146
|
3
|
|
|
|
|
1646
|
$other_string_wo_ansi =~ m/^(\s*)/ms; |
|
147
|
3
|
|
|
|
|
8
|
my $count_of_spaces = length $1; |
|
148
|
3
|
|
|
|
|
10
|
push @ret, Text::ANSI::Util::ta_substr($string, 0, (length $first_wo_ansi) |
|
149
|
|
|
|
|
|
|
+ $count_of_spaces, ''); |
|
150
|
|
|
|
|
|
|
} else { |
|
151
|
12
|
|
|
|
|
145
|
@ret = $string =~ m/^(.{0,$self->{'line_size'}})\s+(.*)$/msx; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
15
|
|
|
|
|
2497
|
return @ret; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
__END__ |