Articulate/Sortation/Slug.pm

filter: Statementstmt 89.7% 35 / 39 Branchbran 75.0% 18 / 24 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 84.9% 62 / 73 SCAR 26.9
CC
14
Cov
85%
cmp
15.4
BEGIN
1.0
BEGIN
1.0
CRAP 14.7
« Articulate/Flow/MetaSwitch.pm ↑ Summary Articulate/Service.pm »
1 package Articulate::Sortation::Slug;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 with 'Articulate::Role::Sortation::AllYouNeedIsCmp';
7  
8 1 ▶sub _left { -1 }
Subroutine _left: called CC=1 SCAR=0.0
9  
10 4 ▶sub _right { 1 }
Subroutine _right: called CC=1 SCAR=0.0
11  
12 sub cmp {
13 19 ▶ my $self = shift;
Subroutine cmp: called CC=14 SCAR=27.3
Pod undocumented
14 19 my $left = shift;
15 19 my $right = shift;
16 19 my $re_break = qr/(?: # Breaks between groups of characters
17 # (?<=[a-z])|(?=[a-z]) # aa
18 (?<=[a-z])(?![a-z]) # a0
19 | (?<![a-z])(?=[a-z]) # 0a
20 | (?<=[0-9])(?![0-9]) # 0_
21 | (?<![0-9])(?=[0-9]) # _0
22 )/ix;
23 19 my $la = [ grep { $_ ne '' } split ($re_break, $left)];
24 19 my $ra = [ grep { $_ ne '' } split ($re_break, $right)];
25 #warn Dump {left => {$left, $la}, right => {$right,$ra}};
26 19 ▶ while (scalar @$la && scalar @$ra) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$la and scalar @$ra) 39 4 43
Condition100%2/2
scalar @$la and scalar @$ra
!ll
142
MC/DC100%1/1
scalar @$la and scalar @$ra
scalar @$la
Truth table100%2/2
A
A= scalar @$la
Aresult
00
11
27 39 my $l = shift @$la;
28 39 my $r = shift @$ra;
29 39 ▶ if ($l =~ /^[^a-z0-9]/i) {
Branch: 3 branches
BranchTrueFalseTotal
if ($l =~ /^[^a-z0-9]/i) { } 11 28 39
elsif ($r =~ /^[^a-z0-9]/i) { } 1 27 28
elsif ($l =~ /^[0-9]/) { } 11 16 27
30 11 ▶ if ($r =~ /^[a-z0-9]/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r =~ /^[a-z0-9]/i) 0 11 11
31 # left is dash and right is not - left wins
32 0 return _left;
33 }
34 11 next; # otherwise both are dash - continue
35 }
36 elsif ($r =~ /^[^a-z0-9]/i) {
37 # right is dash and left is not - right wins
38 1 return _right;
39 }
40 elsif ($l =~ /^[0-9]/) {
41 11 ▶ if ($r =~ /^[0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r =~ /^[0-9]/) { } 11 0 11
42 # both are numbers
43 11 my $res = ( $l <=> $r );
44 11 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 9 2 11
45 }
46 else {
47 # left is number, right is alpha - left wins
48 0 return _left;
49 }
50 }
51 else {
52 # both are alphabetic
53 16 my $res = ( $l cmp $r );
54 16 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 5 11 16
55 }
56 }
57 4 ▶ return @$ra ? _left : 0 if (!@$la);
Branch: 2 branches
BranchTrueFalseTotal
unless @$la 1 3 4
@$ra ? : 1 0 1
58 3 ▶ return _right if (!@$ra);
Branch: 1 branch
BranchTrueFalseTotal
unless @$ra 3 0 3
59 0 ▶ die 'shouldn\'t be here' if $left ne $right;
Branch: 1 branch
BranchTrueFalseTotal
if $left ne $right 0 0 0
60 0 return $left cmp $right;
61 }
62  
63 2 1;
« Articulate/Flow/MetaSwitch.pm ↑ Summary Articulate/Service.pm »