| 1 | package Alien::Util; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 18 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 18 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | # ABSTRACT: Alien Utilities used at build and runtime | ||||||||||||||||||||||||||||||||
| 8 | 18 | our $VERSION = '2.88'; # VERSION | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 18 | our @EXPORT_OK = qw( version_cmp ); | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | # Sort::Versions isn't quite the same algorithm because it differs in | ||||||||||||||||||||||||||||||||
| 15 | # behaviour with leading zeroes. | ||||||||||||||||||||||||||||||||
| 16 | # See also https://dev.gentoo.org/~mgorny/pkg-config-spec.html#version-comparison | ||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | sub version_cmp { | ||||||||||||||||||||||||||||||
|
Subroutine
version_cmp: called CC=9 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 18 | 9 | my @x = (shift =~ m/([0-9]+|[a-z]+)/ig); | |||||||||||||||||||||||||||||||
| 19 | 9 | my @y = (shift =~ m/([0-9]+|[a-z]+)/ig); | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 9 | ▶ | while(@x and @y) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@x and @y
MC/DC100%2/2
@x and @y
@x
@y
Truth table100%3/3
A and B
A= @xB= @y
| |||||||||||||||||||||||||||||||||
| 22 | 21 | my $x = shift @x; my $x_isnum = $x =~ m/[0-9]/; | |||||||||||||||||||||||||||||||
| 23 | 21 | my $y = shift @y; my $y_isnum = $y =~ m/[0-9]/; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 21 | ▶ | if($x_isnum and $y_isnum) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$x_isnum and $y_isnum
MC/DC0%0/2
$x_isnum and $y_isnum
$x_isnum
$y_isnum
Truth table33%1/3
A and B
A= $x_isnumB= $y_isnum
| |||||||||||||||||||||||||||||||||
| 26 | # Numerical comparison | ||||||||||||||||||||||||||||||||
| 27 | 21 | ▶ | return $x <=> $y if $x != $y; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||
| 29 | ▶ | elsif(!$x_isnum && !$y_isnum) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$x_isnum || $y_isnum
MC/DC0%0/2
$x_isnum || $y_isnum
$x_isnum
$y_isnum
Truth table0%0/3
A || B
A= $x_isnumB= $y_isnum
| |||||||||||||||||||||||||||||||||
| 30 | # Alphabetic comparison | ||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return $x cmp $y if $x ne $y; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||||||
| 34 | # Of differing types, the numeric one is newer | ||||||||||||||||||||||||||||||||
| 35 | 0 | return $x_isnum - $y_isnum; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | # Equal so far; the longer is newer | ||||||||||||||||||||||||||||||||
| 40 | 3 | return @x <=> @y; | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 18 | 1; | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | __END__ | ||||||||||||||||||||||||||||||||