| 1 | package Data::Unixish::trim; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use syntax 'each_on_array'; # to support perl < 5.12 | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | #use Log::Any '$log'; | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Data::Unixish::Util qw(%common_args); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||
| 12 | 3 | our $DATE = '2025-02-24'; # DATE | |||||||||||||||||||||||||||
| 13 | 3 | our $DIST = 'Data-Unixish'; # DIST | |||||||||||||||||||||||||||
| 14 | 3 | our $VERSION = '1.574'; # VERSION | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | our %SPEC; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | $SPEC{trim} = { | ||||||||||||||||||||||||||||
| 19 | 3 | v => 1.1, | |||||||||||||||||||||||||||
| 20 | summary => 'Strip whitespace at the beginning and 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 '. | ||||||||||||||||||||||||||||
| 28 | 'beginning and end of text', | ||||||||||||||||||||||||||||
| 29 | schema =>[bool => {default=>0}], | ||||||||||||||||||||||||||||
| 30 | cmdline_aliases => { nl=>{} }, | ||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||
| 33 | tags => [qw/text itemfunc/], | ||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||
| 35 | 2 | ▶ | sub trim { | ||||||||||||||||||||||||||
|
Subroutine
trim: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 2 | my %args = @_; | |||||||||||||||||||||||||||
| 37 | 2 | my ($in, $out) = ($args{in}, $args{out}); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | while (my ($index, $item) = each @$in) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 8 | push @$out, _trim_item($item, \%args); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | [200, "OK"]; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 20 | ▶ | sub _trim_item { | ||||||||||||||||||||||||||
|
Subroutine
_trim_item: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 47 | 20 | my ($item, $args) = @_; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 20 | ▶ | if (defined($item) && !ref($item)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $item and not ref $item
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
| |||||||||||||||||||||||||||||
| 50 | 16 | ▶ | $item =~ s/\A[\r\n]+// if $args->{strip_newline}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 16 | ▶ | $item =~ s/[\r\n]+\z// if $args->{strip_newline}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 16 | $item =~ s/^[ \t]+//mg; | |||||||||||||||||||||||||||
| 53 | 16 | $item =~ s/[ \t]+$//mg; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 20 | return $item; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 3 | 1; | |||||||||||||||||||||||||||
| 59 | # ABSTRACT: Strip whitespace at the beginning and end of each line of text | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||