| 1 | package SemVer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use version 0.82; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | use overload ( | ||||||||||||||||||||||||||||
| 9 | 1 | '""' => 'stringify', | |||||||||||||||||||||||||||
| 10 | '<=>' => 'vcmp', | ||||||||||||||||||||||||||||
| 11 | 'cmp' => 'vcmp', | ||||||||||||||||||||||||||||
| 12 | 1 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | our @ISA = qw(version); | |||||||||||||||||||||||||||
| 15 | 1 | our $VERSION = '0.6.0'; # For Module::Build | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 9 | ▶ | sub _die { require Carp; Carp::croak(@_) } | ||||||||||||||||||||||||||
|
Subroutine
_die: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Prevent version.pm from mucking with our internals. | ||||||||||||||||||||||||||||
| 20 | ▶ | sub import {} | |||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # Adapted from version.pm. | ||||||||||||||||||||||||||||
| 23 | 1 | my $STRICT_INTEGER_PART = qr/0|[1-9][0-9]*/; | |||||||||||||||||||||||||||
| 24 | 1 | my $STRICT_DOTTED_INTEGER_PART = qr/\.$STRICT_INTEGER_PART/; | |||||||||||||||||||||||||||
| 25 | 1 | my $STRICT_DOTTED_INTEGER_VERSION = | |||||||||||||||||||||||||||
| 26 | qr/ $STRICT_INTEGER_PART $STRICT_DOTTED_INTEGER_PART{2,} /x; | ||||||||||||||||||||||||||||
| 27 | 1 | my $OPTIONAL_EXTRA_PART = qr/[a-zA-Z][-0-9A-Za-z]*/; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub new { | ||||||||||||||||||||||||||||
| 30 | 338 | ▶ | my ($class, $ival) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Handle vstring. | ||||||||||||||||||||||||||||
| 33 | 338 | ▶ | return $class->SUPER::new($ival) if Scalar::Util::isvstring($ival); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # Let version handle cloning. | ||||||||||||||||||||||||||||
| 36 | 333 | ▶ | if (eval { $ival->isa('version') }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 231 | my $self = $class->SUPER::new($ival); | |||||||||||||||||||||||||||
| 38 | 231 | $self->{extra} = $ival->{extra}; | |||||||||||||||||||||||||||
| 39 | 231 | $self->{dash} = $ival->{dash}; | |||||||||||||||||||||||||||
| 40 | 231 | return $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 102 | my ($val, $dash, $extra) = ( | |||||||||||||||||||||||||||
| 44 | $ival =~ /^v?($STRICT_DOTTED_INTEGER_VERSION)(?:(-)($OPTIONAL_EXTRA_PART))?$/ | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | 102 | ▶ | _die qq{Invalid semantic version string format: "$ival"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | unless defined $val; | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 94 | my $self = $class->SUPER::new($val); | |||||||||||||||||||||||||||
| 50 | 94 | $self->{dash} = $dash; | |||||||||||||||||||||||||||
| 51 | 94 | $self->{extra} = $extra; | |||||||||||||||||||||||||||
| 52 | 94 | return $self; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | $VERSION = __PACKAGE__->new($VERSION); # For ourselves. | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub declare { | ||||||||||||||||||||||||||||
| 58 | 270 | ▶ | my ($class, $ival) = @_; | ||||||||||||||||||||||||||
|
Subroutine
declare: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | return $class->new($ival) if Scalar::Util::isvstring($ival) | ||||||||||||||||||||||||||||
| 60 | 270 | ▶ | or eval { $ival->isa('version') }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&Scalar::Util::isvstring($ival) or eval {
do {
$ival->isa("version")
}
}
MC/DC100%2/2
&Scalar::Util::isvstring($ival) or eval {
do {
$ival->isa("version")
}
}
&Scalar::Util::isvstring($ival)
eval {
do {
$ival->isa("version")
}
}
Truth table100%3/3
A or B
A= &Scalar::Util::isvstring($ival)B= eval {
do {
$ival->isa("version")
}
}
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 58 | (my $v = $ival) =~ s/(?:(-?)($OPTIONAL_EXTRA_PART))[[:space:]]*$//; | |||||||||||||||||||||||||||
| 63 | 58 | my $dash = $1; | |||||||||||||||||||||||||||
| 64 | 58 | my $extra = $2; | |||||||||||||||||||||||||||
| 65 | 58 | ▶ | $v += 0 if $v =~ s/_//g; # ignore underscores. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 58 | my $self = $class->SUPER::declare($v); | |||||||||||||||||||||||||||
| 67 | 58 | $self->{dash} = $dash; | |||||||||||||||||||||||||||
| 68 | 58 | $self->{extra} = $extra; | |||||||||||||||||||||||||||
| 69 | 58 | return $self; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub parse { | ||||||||||||||||||||||||||||
| 73 | 24 | ▶ | my ($class, $ival) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | return $class->new($ival) if Scalar::Util::isvstring($ival) | ||||||||||||||||||||||||||||
| 75 | 24 | ▶ | or eval { $ival->isa('version') }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
&Scalar::Util::isvstring($ival) or eval {
do {
$ival->isa("version")
}
}
MC/DC50%1/2
&Scalar::Util::isvstring($ival) or eval {
do {
$ival->isa("version")
}
}
&Scalar::Util::isvstring($ival)
eval {
do {
$ival->isa("version")
}
}
Truth table66%2/3
A or B
A= &Scalar::Util::isvstring($ival)B= eval {
do {
$ival->isa("version")
}
}
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 23 | (my $v = $ival) =~ s/(?:(-?)($OPTIONAL_EXTRA_PART))[[:space:]]*$//; | |||||||||||||||||||||||||||
| 78 | 23 | my $dash = $1; | |||||||||||||||||||||||||||
| 79 | 23 | my $extra = $2; | |||||||||||||||||||||||||||
| 80 | 23 | ▶ | $v += 0 if $v =~ s/_//g; # ignore underscores. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 23 | my $self = $class->SUPER::parse($v); | |||||||||||||||||||||||||||
| 82 | 23 | $self->{dash} = $dash; | |||||||||||||||||||||||||||
| 83 | 23 | $self->{extra} = $extra; | |||||||||||||||||||||||||||
| 84 | 23 | return $self; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | sub stringify { | ||||||||||||||||||||||||||||
| 88 | 511 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 511 | my $str = $self->SUPER::stringify; | |||||||||||||||||||||||||||
| 90 | # This is purely for SemVers constructed from version objects. | ||||||||||||||||||||||||||||
| 91 | 511 | ▶ | $str += 0 if $str =~ s/_//g; # ignore underscores. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 511 | ▶ | return $str . ($self->{dash} || '') . ($self->{extra} || ''); | ||||||||||||||||||||||||||
|
Condition100%4/4
$self->{'dash'} || ''
$self->{'extra'} || ''
MC/DC100%1/1
$self->{'dash'} || ''
$self->{'dash'}
MC/DC100%1/1
$self->{'extra'} || ''
$self->{'extra'}
Truth table100%2/2
A
A= $self->{'dash'}
Truth table100%2/2
A
A= $self->{'extra'}
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub normal { | ||||||||||||||||||||||||||||
| 96 | 125 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
normal: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 125 | (my $norm = $self->SUPER::normal) =~ s/^v//; | |||||||||||||||||||||||||||
| 98 | 125 | $norm =~ s/_/./g; | |||||||||||||||||||||||||||
| 99 | 125 | ▶ | return $norm . ($self->{extra} ? "-$self->{extra}" : ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 1 | ▶ | sub numify { _die 'Semantic versions cannot be numified'; } | ||||||||||||||||||||||||||
|
Subroutine
numify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 12 | ▶ | sub is_alpha { !!shift->{extra} } | ||||||||||||||||||||||||||
|
Subroutine
is_alpha: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub vcmp { | ||||||||||||||||||||||||||||
| 106 | 244 | ▶ | my $left = shift; | ||||||||||||||||||||||||||
|
Subroutine
vcmp: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 244 | my $right = ref($left)->declare(shift); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # Reverse? | ||||||||||||||||||||||||||||
| 110 | 244 | ▶ | ($left, $right) = shift() ? ($right, $left): ($left, $right); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # Major and minor win. | ||||||||||||||||||||||||||||
| 113 | 244 | ▶ | if (my $ret = $left->SUPER::vcmp($right, 0)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 62 | return $ret; | |||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||
| 116 | # They're equal. Check the extra text stuff. | ||||||||||||||||||||||||||||
| 117 | 182 | ▶ | if (my $l = $left->{extra}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 74 | ▶ | my $r = $right->{extra} or return -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 66 | return lc $l cmp lc $r; | |||||||||||||||||||||||||||
| 120 | } else { | ||||||||||||||||||||||||||||
| 121 | 108 | ▶ | return $right->{extra} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | 1; | |||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||