| 1 | # class to represent the version number in a stream attribute | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | package DJabberd::StreamVersion; | ||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | 21 | ▶ | use constant MAJOR => 0; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 21 | ▶ | use constant MINOR => 1; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 21 | ▶ | use constant VALID => 2; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 21 | ▶ | use constant PRESENT => 3; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | # returns undef on invalid version | ||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 12 | 7 | my ($class, $ver) = @_; | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | # {=version-format} | ||||||||||||||||||||||||||||||
| 15 | 7 | my ($valid, $major, $minor) = (0, 0, 0); | |||||||||||||||||||||||||||||
| 16 | 7 | ▶ | if ($ver =~ /^(\d+)\.(\d+)$/) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 17 | 6 | $valid = 1; | |||||||||||||||||||||||||||||
| 18 | 6 | ($major, $minor) = ($1, $2); | |||||||||||||||||||||||||||||
| 19 | # {=leading-zeros-ignored} | ||||||||||||||||||||||||||||||
| 20 | 6 | $major =~ s/^0+//; | |||||||||||||||||||||||||||||
| 21 | 6 | $minor =~ s/^0+//; | |||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | 7 | ▶ | return bless [ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%4/4
$major || 0
$minor || 0
MC/DC100%1/1
$major || 0
$major
MC/DC100%1/1
$minor || 0
$minor
Truth table100%2/2
A
A= $major
Truth table100%2/2
A
A= $minor
| |||||||||||||||||||||||||||||||
| 25 | int($major || 0), | ||||||||||||||||||||||||||||||
| 26 | int($minor || 0), | ||||||||||||||||||||||||||||||
| 27 | $valid, | ||||||||||||||||||||||||||||||
| 28 | ($ver ne "" ? 1 : 0), | ||||||||||||||||||||||||||||||
| 29 | ], $class; | ||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub none { | ||||||||||||||||||||||||||||
|
Subroutine
none: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 33 | 0 | my $class = shift; | |||||||||||||||||||||||||||||
| 34 | 0 | return bless [ 0, 0, 1, 0 ], $class; | |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | # returns min of two given objects | ||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | sub min { | ||||||||||||||||||||||||||||
|
Subroutine
min: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 39 | 1 | return (sort { $a->cmp($b) } @_)[0]; | |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | sub valid { | ||||||||||||||||||||||||||||
|
Subroutine
valid: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 43 | 2 | my $self = shift; | |||||||||||||||||||||||||||||
| 44 | 2 | return $self->[VALID]; | |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | sub supports_features { | ||||||||||||||||||||||||||||
|
Subroutine
supports_features: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 48 | 2 | my $self = shift; | |||||||||||||||||||||||||||||
| 49 | 2 | return $self->at_least("1.0"); | |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | sub at_least { | ||||||||||||||||||||||||||||
|
Subroutine
at_least: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 53 | 2 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||
| 54 | 2 | my $cmp = $self->cmp($other); | |||||||||||||||||||||||||||||
| 55 | 2 | return $cmp >= 0; | |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | # {=numeric-version-compare} | ||||||||||||||||||||||||||||||
| 59 | 7 | ▶ | sub cmp { | ||||||||||||||||||||||||||||
|
Subroutine
cmp: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 60 | 7 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||
| 61 | 7 | ▶ | $other = DJabberd::StreamVersion->new($other) unless ref $other; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 62 | return | ||||||||||||||||||||||||||||||
| 63 | 7 | ▶ | ($self->[MAJOR] <=> $other->[MAJOR]) || | ||||||||||||||||||||||||||||
|
Condition66%2/3
$self->[0] <=> $other->[0] || $self->[1] <=> $other->[1]
MC/DC0%0/2
$self->[0] <=> $other->[0] || $self->[1] <=> $other->[1]
$self->[0] <=> $other->[0]
$self->[1] <=> $other->[1]
Truth table66%2/3
A || B
A= $self->[0] <=> $other->[0]B= $self->[1] <=> $other->[1]
| |||||||||||||||||||||||||||||||
| 64 | ($self->[MINOR] <=> $other->[MINOR]); | ||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | sub as_string { | ||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 68 | 1 | my $self = shift; | |||||||||||||||||||||||||||||
| 69 | 1 | return "$self->[MAJOR].$self->[MINOR]"; | |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | # returns "version='1.0'" or empty string when version is 0.0; | ||||||||||||||||||||||||||||||
| 73 | # {=no-response-version-on-zero-ver} | ||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub as_attr_string { | ||||||||||||||||||||||||||||
|
Subroutine
as_attr_string: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | return "" unless $self->[MAJOR] || $self->[MINOR]; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->[0] or $self->[1]
MC/DC0%0/2
$self->[0] or $self->[1]
$self->[0]
$self->[1]
Truth table0%0/3
A or B
A= $self->[0]B= $self->[1]
| |||||||||||||||||||||||||||||||
| 77 | 0 | return "version='" . $self->as_string . "'"; | |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||
| 80 | 21 | 1; | |||||||||||||||||||||||||||||