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 CC 14 SCAR 24.5
CC
14
Cov
85%
cmp
15.4
BEGIN
1.0
BEGIN
1.0
CRAP 11.6
« Articulate/Serialisation/StatusSetter.pm ↑ Summary Articulate/Authentication.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  
26 #warn Dump {left => {$left, $la}, right => {$right,$ra}};
27 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
28 39 my $l = shift @$la;
29 39 my $r = shift @$ra;
30 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
31 11 ▶ if ( $r =~ /^[a-z0-9]/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r =~ /^[a-z0-9]/i) 0 11 11
32  
33 # left is dash and right is not - left wins
34 0 return _left;
35 }
36 11 next; # otherwise both are dash - continue
37 }
38 elsif ( $r =~ /^[^a-z0-9]/i ) {
39  
40 # right is dash and left is not - right wins
41 1 return _right;
42 }
43 elsif ( $l =~ /^[0-9]/ ) {
44 11 ▶ if ( $r =~ /^[0-9]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r =~ /^[0-9]/) { } 11 0 11
45  
46 # both are numbers
47 11 my $res = ( $l <=> $r );
48 11 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 9 2 11
49 }
50 else {
51 # left is number, right is alpha - left wins
52 0 return _left;
53 }
54 }
55 else {
56 # both are alphabetic
57 16 my $res = ( $l cmp $r );
58 16 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 5 11 16
59 }
60 }
61 4 ▶ return @$ra ? _left : 0 if ( !@$la );
Branch: 2 branches
BranchTrueFalseTotal
unless @$la 1 3 4
@$ra ? : 1 0 1
62 3 ▶ return _right if ( !@$ra );
Branch: 1 branch
BranchTrueFalseTotal
unless @$ra 3 0 3
63 0 ▶ die 'shouldn\'t be here' if $left ne $right;
Branch: 1 branch
BranchTrueFalseTotal
if $left ne $right 0 0 0
64 0 return $left cmp $right;
65 }
66  
67 2 1;
« Articulate/Serialisation/StatusSetter.pm ↑ Summary Articulate/Authentication.pm »