line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::trim; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
476
|
use 5.010; |
|
2
|
|
|
|
|
9
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
45
|
|
5
|
2
|
|
|
2
|
|
332
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
2
|
|
|
|
|
19395
|
|
|
2
|
|
|
|
|
15
|
|
6
|
2
|
|
|
2
|
|
3082
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
89
|
|
7
|
|
|
|
|
|
|
#use Log::Any '$log'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.570'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
386
|
use Data::Unixish::Util qw(%common_args); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
759
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %SPEC; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$SPEC{trim} = { |
16
|
|
|
|
|
|
|
v => 1.1, |
17
|
|
|
|
|
|
|
summary => 'Strip whitespace at the beginning and end of each line of text', |
18
|
|
|
|
|
|
|
description => <<'_', |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
_ |
21
|
|
|
|
|
|
|
args => { |
22
|
|
|
|
|
|
|
%common_args, |
23
|
|
|
|
|
|
|
strip_newline => { |
24
|
|
|
|
|
|
|
summary => 'Whether to strip newlines at the '. |
25
|
|
|
|
|
|
|
'beginning and end of text', |
26
|
|
|
|
|
|
|
schema =>[bool => {default=>0}], |
27
|
|
|
|
|
|
|
cmdline_aliases => { nl=>{} }, |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
tags => [qw/text itemfunc/], |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
sub trim { |
33
|
2
|
|
|
2
|
1
|
9
|
my %args = @_; |
34
|
2
|
|
|
|
|
6
|
my ($in, $out) = ($args{in}, $args{out}); |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
12
|
while (my ($index, $item) = each @$in) { |
37
|
8
|
|
|
|
|
29
|
push @$out, _trim_item($item, \%args); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
11
|
[200, "OK"]; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _trim_item { |
44
|
20
|
|
|
20
|
|
29
|
my ($item, $args) = @_; |
45
|
|
|
|
|
|
|
|
46
|
20
|
100
|
66
|
|
|
65
|
if (defined($item) && !ref($item)) { |
47
|
16
|
100
|
|
|
|
39
|
$item =~ s/\A[\r\n]+// if $args->{strip_newline}; |
48
|
16
|
100
|
|
|
|
36
|
$item =~ s/[\r\n]+\z// if $args->{strip_newline}; |
49
|
16
|
|
|
|
|
47
|
$item =~ s/^[ \t]+//mg; |
50
|
16
|
|
|
|
|
46
|
$item =~ s/[ \t]+$//mg; |
51
|
|
|
|
|
|
|
} |
52
|
20
|
|
|
|
|
91
|
return $item; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
# ABSTRACT: Strip whitespace at the beginning and end of each line of text |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |