File Coverage

blib/lib/Data/Unixish/ltrim.pm
Criterion Covered Total %
statement 24 24 100.0
branch 4 4 100.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 1 1 100.0
total 38 39 97.4


line stmt bran cond sub pod time code
1             package Data::Unixish::ltrim;
2              
3 1     1   496 use 5.010;
  1         6  
4 1     1   5 use strict;
  1         2  
  1         24  
5 1     1   414 use syntax 'each_on_array'; # to support perl < 5.12
  1         23888  
  1         7  
6 1     1   3495 use warnings;
  1         2  
  1         28  
7             #use Log::Any '$log';
8              
9 1     1   434 use Data::Unixish::Util qw(%common_args);
  1         3  
  1         402  
10              
11             our $VERSION = '1.571'; # VERSION
12              
13             our %SPEC;
14              
15             $SPEC{ltrim} = {
16             v => 1.1,
17             summary => 'Strip whitespace at the beginning 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 beginning of text',
25             schema =>[bool => {default=>0}],
26             cmdline_aliases => { nl=>{} },
27             },
28             },
29             tags => [qw/text itemfunc/],
30             };
31             sub ltrim {
32 2     2 1 7 my %args = @_;
33 2         4 my ($in, $out) = ($args{in}, $args{out});
34              
35 2         9 while (my ($index, $item) = each @$in) {
36 8         17 push @$out, _ltrim_item($item, \%args);
37             }
38              
39 2         8 [200, "OK"];
40             }
41              
42             sub _ltrim_item {
43 16     16   29 my ($item, $args) = @_;
44              
45 16 100 66     63 if (defined($item) && !ref($item)) {
46 12 100       33 $item =~ s/\A[\r\n]+// if $args->{strip_newline};
47 12         37 $item =~ s/^[ \t]+//mg;
48             }
49 16         53 return $item;
50             }
51              
52             1;
53             # ABSTRACT: Strip whitespace at the beginning of each line of text
54              
55             __END__