line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::linum; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
432
|
use 5.010; |
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
340
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
1
|
|
|
|
|
19522
|
|
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
2863
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
7
|
|
|
|
|
|
|
#use Log::Any '$log'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
361
|
use Data::Unixish::Util qw(%common_args); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
414
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.572'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %SPEC; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$SPEC{linum} = { |
16
|
|
|
|
|
|
|
v => 1.1, |
17
|
|
|
|
|
|
|
summary => 'Add line numbers', |
18
|
|
|
|
|
|
|
args => { |
19
|
|
|
|
|
|
|
%common_args, |
20
|
|
|
|
|
|
|
format => { |
21
|
|
|
|
|
|
|
summary => 'Sprintf-style format to use', |
22
|
|
|
|
|
|
|
description => <<'_', |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Example: `%04d|`. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
_ |
27
|
|
|
|
|
|
|
schema => [str => default=>'%4s|'], |
28
|
|
|
|
|
|
|
cmdline_aliases => { f=>{} }, |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
start => { |
31
|
|
|
|
|
|
|
summary => 'Number to start from', |
32
|
|
|
|
|
|
|
schema => [int => default => 1], |
33
|
|
|
|
|
|
|
cmdline_aliases => { s=>{} }, |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
blank_empty_lines => { |
36
|
|
|
|
|
|
|
schema => [bool => default=>1], |
37
|
|
|
|
|
|
|
description => <<'_', |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Example when set to false: |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1|use Foo::Bar; |
42
|
|
|
|
|
|
|
2| |
43
|
|
|
|
|
|
|
3|sub blah { |
44
|
|
|
|
|
|
|
4| my %args = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Example when set to true: |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1|use Foo::Bar; |
49
|
|
|
|
|
|
|
| |
50
|
|
|
|
|
|
|
3|sub blah { |
51
|
|
|
|
|
|
|
4| my %args = @_; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
_ |
54
|
|
|
|
|
|
|
cmdline_aliases => { |
55
|
|
|
|
|
|
|
b => {}, |
56
|
|
|
|
|
|
|
B => { |
57
|
|
|
|
|
|
|
summary => 'Equivalent to --noblank-empty-lines', |
58
|
|
|
|
|
|
|
code => sub { $_[0]{blank_empty_lines} = 0 }, |
59
|
|
|
|
|
|
|
}, |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
tags => [qw/text itemfunc/], |
64
|
|
|
|
|
|
|
"x.dux.strip_newlines" => 0, # for duxapp < 1.41, will be removed later |
65
|
|
|
|
|
|
|
"x.app.dux.strip_newlines" => 0, |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
sub linum { |
68
|
3
|
|
|
3
|
1
|
8
|
my %args = @_; |
69
|
3
|
|
|
|
|
7
|
my ($in, $out) = ($args{in}, $args{out}); |
70
|
|
|
|
|
|
|
|
71
|
3
|
|
|
|
|
7
|
_linum_begin(\%args); |
72
|
3
|
|
|
|
|
19
|
while (my ($index, $item) = each @$in) { |
73
|
9
|
|
|
|
|
20
|
push @$out, _linum_item($item, \%args); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
3
|
|
|
|
|
11
|
[200, "OK"]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _linum_begin { |
80
|
6
|
|
|
6
|
|
18
|
my $args = shift; |
81
|
|
|
|
|
|
|
|
82
|
6
|
|
100
|
|
|
27
|
$args->{format} //= '%4s|'; |
83
|
6
|
|
100
|
|
|
17
|
$args->{blank_empty_lines} //= 1; |
84
|
6
|
|
50
|
|
|
24
|
$args->{start} //= 1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# abuse, use args to store a temp var |
87
|
6
|
|
|
|
|
13
|
$args->{_lineno} = $args->{start}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _linum_item { |
91
|
18
|
|
|
18
|
|
26
|
my ($item, $args) = @_; |
92
|
|
|
|
|
|
|
|
93
|
18
|
100
|
66
|
|
|
49
|
if (defined($item) && !ref($item)) { |
94
|
14
|
|
|
|
|
14
|
my @l; |
95
|
14
|
|
|
|
|
31
|
for (split /^/, $item) { |
96
|
22
|
|
|
|
|
21
|
my $n; |
97
|
22
|
100
|
100
|
|
|
67
|
$n = ($args->{blank_empty_lines} && !/\S/) ? "" : $args->{_lineno}; |
98
|
22
|
|
|
|
|
57
|
push @l, sprintf($args->{format}, $n), $_; |
99
|
22
|
|
|
|
|
31
|
$args->{_lineno}++; |
100
|
|
|
|
|
|
|
} |
101
|
14
|
|
|
|
|
28
|
$item = join "", @l; |
102
|
14
|
50
|
|
|
|
27
|
chomp($item) if $args->{-dux_cli}; |
103
|
|
|
|
|
|
|
} |
104
|
18
|
|
|
|
|
47
|
return $item; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
# ABSTRACT: Add line numbers |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |