lib/App/perlmv/scriptlet/remove_common_suffix.pm

filter: Statementstmt 100% 31 / 31 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 93.8% 46 / 49 CC 8 SCAR 17.4
CC
8
Cov
95%
__ANON__
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.7
« lib/App/perlmv.pm ↑ Summary lib/App/perlmv/scriptlet/remove_common_prefix.pm »
1 package App::perlmv::scriptlet::remove_common_suffix;
2  
3 6 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 6 our $DATE = '2026-11-06'; # DATE
9 6 our $DIST = 'App-perlmv'; # DIST
10 6 our $VERSION = '0.610'; # VERSION
11  
12 our $SCRIPTLET = {
13 summary => q[Remove suffix that are common to all args, while preserving extension, e.g. (1-radiolab.mp3, 2-radiolab.mp3) -> (1.mp3, 2.mp3)],
14 18 ▶ code => sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
15 package
16 App::perlmv::code;
17 6 ▶ use vars qw($COMMON_SUFFIX $TESTING $FILES $EXT);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 18 ▶ if (!defined($COMMON_SUFFIX) && !$TESTING) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $App::perlmv::code::COMMON_SUFFIX or $App::perlmv::code::TESTING) 5 13 18
Condition66%2/3
defined $App::perlmv::code::COMMON_SUFFIX or $App::perlmv::code::TESTING
l!l&&r!l&&!r
1305
MC/DC50%1/2
defined $App::perlmv::code::COMMON_SUFFIX or $App::perlmv::code::TESTING
defined $App::perlmv::code::COMMON_SUFFIX $App::perlmv::code::TESTING
Truth table66%2/3
A or B
A= defined $App::perlmv::code::COMMON_SUFFIXB= $App::perlmv::code::TESTING
ABresult
1X1
011
000
20 5 for (@$FILES) { $_ = reverse };
21 5 my $i;
22 5 ▶ for ($i=0; $i<length($FILES->[0]); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $App::perlmv::code::FILES->[0]) 22 0 22
23 22 ▶ last if grep { substr($_, $i, 1) ne substr($FILES->[0], $i, 1) } @{$FILES}[1..@$FILES-1];
Branch: 1 branch
BranchTrueFalseTotal
if grep {substr($_, $i, 1) ne substr($App::perlmv::code::FILES->[0], $i, 1);} @{$App::perlmv::code::FILES;}[1 .. @$App::perlmv::code::FILES - 1] 5 17 22
24 }
25 5 $COMMON_SUFFIX = reverse substr($FILES->[0], 0, $i);
26 5 for (@$FILES) { $_ = reverse };
27 # don't wipe extension, if exists
28 5 ▶ $EXT = $COMMON_SUFFIX =~ /.(\.\w+)$/ ? $1 : "";
Branch: 1 branch
BranchTrueFalseTotal
$App::perlmv::code::COMMON_SUFFIX =~ /.(\.\w+)$/ ? : 2 3 5
29 }
30 18 s/\Q$COMMON_SUFFIX\E$/$EXT/;
31 18 $_;
32 },
33 6 };
34  
35 6 1;
36  
37 # ABSTRACT: Remove suffix that are common to all args, while preserving extension, e.g. (1-radiolab.mp3, 2-radiolab.mp3) -> (1.mp3, 2.mp3)
38  
39 __END__
« lib/App/perlmv.pm ↑ Summary lib/App/perlmv/scriptlet/remove_common_prefix.pm »