Data/Unixish/rtrim.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 6 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 96.0% 48 / 50 CC 5 SCAR 8.2
CC
5
Cov
98%
_rtrim_item
4.0
rtrim
2.0
BEGIN
1.0
CRAP 2.3
« Data/Unixish/ltrim.pm ↑ Summary Data/Unixish/avg.pm »
1 package Data::Unixish::rtrim;
2  
3 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use syntax 'each_on_array'; # to support perl < 5.12
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #use Log::Any '$log';
8  
9 2 ▶use Data::Unixish::Util qw(%common_args);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
12 2 our $DATE = '2025-02-24'; # DATE
13 2 our $DIST = 'Data-Unixish'; # DIST
14 2 our $VERSION = '1.574'; # VERSION
15  
16 2 our %SPEC;
17  
18 $SPEC{rtrim} = {
19 2 v => 1.1,
20 summary => 'Strip whitespace at the end of each line of text',
21 description => <<'MARKDOWN',
22  
23 MARKDOWN
24 args => {
25 %common_args,
26 strip_newline => {
27 summary => 'Whether to strip newlines at the end of text',
28 schema =>[bool => {default=>0}],
29 cmdline_aliases => { nl=>{} },
30 },
31 },
32 tags => [qw/text itemfunc/],
33 };
34 2 ▶sub rtrim {
Subroutine rtrim: called CC=2 SCAR=6.9
Pod documented
35 2 my %args = @_;
36 2 my ($in, $out) = ($args{in}, $args{out});
37  
38 2 ▶ while (my ($index, $item) = each @$in) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @$in) 8 2 10
39 8 push @$out, _rtrim_item($item, \%args);
40 }
41  
42 2 [200, "OK"];
43 }
44  
45 16 ▶sub _rtrim_item {
Subroutine _rtrim_item: called CC=4 SCAR=13.9
46 16 my ($item, $args) = @_;
47  
48 16 ▶ if (defined($item) && !ref($item)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $item and not ref $item) 12 4 16
Condition66%2/3
defined $item and not ref $item
!ll&&!rl&&r
0412
MC/DC50%1/2
defined $item and not ref $item
defined $item not ref $item
Truth table66%2/3
A and not(B)
A= defined $itemB= not ref $item
ABresult
0X0
100
111
49 12 ▶ $item =~ s/[\r\n]+\z// if $args->{strip_newline};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"strip_newline"} 6 6 12
50 12 $item =~ s/[ \t]+$//mg;
51 }
52 16 return $item;
53 }
54  
55 2 1;
56 # ABSTRACT: Strip whitespace at the end of each line of text
57  
58 __END__
« Data/Unixish/ltrim.pm ↑ Summary Data/Unixish/avg.pm »