CommonSuffix.pm

filter: Statementstmt 92.5% 25 / 27 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 90.7% 39 / 43 CC 7 SCAR 16.2
CC
7
Cov
89%
common_suffix
7.4
BEGIN
1.0
BEGIN
1.0
CRAP 5.1
« CommonPrefix.pm ↑ Summary
1 package String::CommonSuffix;
2  
3 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 2 our $DATE = '2025-08-02'; # DATE
9 2 our $DIST = 'String-CommonPrefix'; # DIST
10 2 our $VERSION = '0.021'; # VERSION
11  
12 2 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our @EXPORT_OK = qw(
15 common_suffix
16 );
17  
18 6 ▶sub common_suffix {
Subroutine common_suffix: called CC=7 SCAR=20.0
Pod documented
19 6 require List::Util;
20  
21 6 ▶ return undef unless @_; ## no critic: Subroutines::ProhibitExplicitReturnUndef
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 6 6
22 6 my $i;
23 L1:
24 6 ▶ for ($i = 0; $i < length($_[0]); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $_[0]) 6 3 9
25 6 for (@_[1..$#_]) {
26 9 ▶ if (length($_) < $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_ < $i) { } 0 9 9
27 0 $i--; last L1;
28 } else {
29 9 ▶ last L1 if substr($_, -($i+1), 1) ne substr($_[0], -($i+1), 1);
Branch: 1 branch
BranchTrueFalseTotal
if substr($_, -($i + 1), 1) ne substr($_[0], -($i + 1), 1) 3 6 9
30 }
31 }
32 }
33 6 ▶ $i ? substr($_[0], -$i) : "";
Branch: 1 branch
BranchTrueFalseTotal
$i ? : 2 4 6
34 }
35  
36 2 1;
37 # ABSTRACT: Return suffix common to all strings
38  
39 __END__
« CommonPrefix.pm ↑ Summary