DJabberd/StreamVersion.pm

filter: Statementstmt 87.5% 35 / 40 Branchbran 75.0% 6 / 8 Conditioncond 60.0% 6 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 9 totaltotal 69.7% 60 / 86 CC 9 SCAR 13.5
CC
9
Cov
81%
as_attr_string
12.0
new
5.0
cmp
3.0
CRAP 3.9
« DJabberd/Component.pm ↑ Summary DJabberd/Queue/ServerOut.pm »
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
BranchTrueFalseTotal
if ($ver =~ /^(\d+)\.(\d+)$/) 6 1 7
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
BranchTrueFalseTotal
$ver ne '' ? : 6 1 7
Condition100%4/4
$major || 0
l!l
52
$minor || 0
l!l
34
MC/DC100%1/1
$major || 0
$major
MC/DC100%1/1
$minor || 0
$minor
Truth table100%2/2
A
A= $major
Aresult
11
00
Truth table100%2/2
A
A= $minor
Aresult
11
00
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
BranchTrueFalseTotal
unless ref $other 2 5 7
62 return
63 7 ▶ ($self->[MAJOR] <=> $other->[MAJOR]) ||
Condition66%2/3
$self->[0] <=> $other->[0] || $self->[1] <=> $other->[1]
l!l&&r!l&&!r
340
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]
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $self->[0] or $self->[1] 0 0 0
Condition0%0/3
$self->[0] or $self->[1]
l!l&&r!l&&!r
000
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]
ABresult
1X1
011
000
77 0 return "version='" . $self->as_string . "'";
78 }
79  
80 21 1;
« DJabberd/Component.pm ↑ Summary DJabberd/Queue/ServerOut.pm »