File Coverage

blib/lib/Data/Unixish/lins.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 1 1 100.0
total 35 36 97.2


line stmt bran cond sub pod time code
1             package Data::Unixish::lins;
2              
3 1     1   428 use 5.010;
  1         6  
4 1     1   4 use strict;
  1         2  
  1         19  
5 1     1   347 use syntax 'each_on_array'; # to support perl < 5.12
  1         19636  
  1         4  
6 1     1   2887 use warnings;
  1         2  
  1         23  
7             #use Log::Any '$log';
8              
9 1     1   380 use Data::Unixish::Util qw(%common_args);
  1         3  
  1         260  
10              
11             our $VERSION = '1.572'; # VERSION
12              
13             our %SPEC;
14              
15             $SPEC{lins} = {
16             v => 1.1,
17             summary => 'Add some text at the beginning of each line of text',
18             description => <<'_',
19              
20             This is sort of a counterpart for ltrim, which removes whitespace at the
21             beginning (left) of each line of text.
22              
23             _
24             args => {
25             %common_args,
26             text => {
27             summary => 'The text to add',
28             schema => ['str*'],
29             req => 1,
30             pos => 0,
31             },
32             },
33             tags => [qw/text itemfunc/],
34             };
35             sub lins {
36 1     1 1 4 my %args = @_;
37 1         2 my ($in, $out) = ($args{in}, $args{out});
38              
39 1         4 while (my ($index, $item) = each @$in) {
40 4         7 push @$out, _lins_item($item, \%args);
41             }
42              
43 1         4 [200, "OK"];
44             }
45              
46             sub _lins_item {
47 8     8   12 my ($item, $args) = @_;
48              
49 8 100 66     28 if (defined($item) && !ref($item)) {
50 6         28 $item =~ s/^/$args->{text}/mg;
51             }
52 8         24 return $item;
53             }
54              
55             1;
56             # ABSTRACT: Add some text at the beginning of each line of text
57              
58             __END__