| 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
Condition100%2/2
scalar @$la and scalar @$ra
MC/DC100%1/1
scalar @$la and scalar @$ra
scalar @$la
Truth table100%2/2
A
A= scalar @$la
| |||||||||||||||||||||
| 27 | 39 | my $l = shift @$la; | |||||||||||||||||||
| 28 | 39 | my $r = shift @$ra; | |||||||||||||||||||
| 29 | 39 | ▶ | if ($l =~ /^[^a-z0-9]/i) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 30 | 11 | ▶ | if ($r =~ /^[a-z0-9]/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 42 | # both are numbers | ||||||||||||||||||||
| 43 | 11 | my $res = ( $l <=> $r ); | |||||||||||||||||||
| 44 | 11 | ▶ | return $res if $res; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | 4 | ▶ | return @$ra ? _left : 0 if (!@$la); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 58 | 3 | ▶ | return _right if (!@$ra); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 0 | ▶ | die 'shouldn\'t be here' if $left ne $right; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | return $left cmp $right; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 2 | 1; | |||||||||||||||||||