Client/KeyContainer.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 12 / 12 Conditioncond 81.8% 9 / 11 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 88.2% 75 / 85 CC 12 SCAR 14.4
CC
12
Cov
97%
new
7.0
get_active_site_key
5.0
is_valid
2.0
CRAP 4.2
« Client.pm ↑ Summary Client/Key.pm »
1 package UID2::Client::KeyContainer;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use List::MoreUtils qw(upper_bound);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use UID2::Client::Timestamp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 99 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod undocumented
9 99 my ($class, @keys) = @_;
10 99 my $latest_expires = 0;
11 99 my (%keys, %keys_by_site);
12 99 for my $key (@keys) {
13 251 $keys{$key->id} = $key;
14 251 ▶ if ($key->site_id > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key->site_id > 0) 205 46 251
15 205 ▶ push @{$keys_by_site{$key->site_id} //= []}, $key;
Condition100%2/2
$keys_by_site{$key->site_id} //= []
l!l
10996
MC/DC100%1/1
$keys_by_site{$key->site_id} //= []
$keys_by_site{$key->site_id}
Truth table100%2/2
A
A= $keys_by_site{$key->site_id}
Aresult
11
00
16 }
17 251 ▶ if (!$latest_expires or $key->expires > $latest_expires) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $latest_expires or $key->expires > $latest_expires) 101 150 251
Condition100%3/3
not $latest_expires or $key->expires > $latest_expires
l!l&&r!l&&!r
992150
MC/DC100%2/2
not $latest_expires or $key->expires > $latest_expires
not $latest_expires $key->expires > $latest_expires
Truth table100%3/3
not(A) or B
A= not $latest_expiresB= $key->expires > $latest_expires
ABresult
1X1
011
000
18 101 $latest_expires = $key->expires;
19 }
20 }
21 99 ▶ while (my ($site_id, $keys) = each %keys_by_site) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %keys_by_site) 96 99 195
22 96 $keys_by_site{$site_id} = [sort { $a->activates <=> $b->activates } @$keys];
23 }
24 bless {
25 99 keys => \%keys,
26 keys_by_site => \%keys_by_site,
27 latest_expires => $latest_expires,
28 }, $class;
29 }
30  
31 87 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
32 87 my ($self, $id) = @_;
33 87 $self->{keys}->{$id};
34 }
35  
36 73 ▶sub is_valid {
Subroutine is_valid: called CC=2 SCAR=7.0
Pod undocumented
37 73 my ($self, $now) = @_;
38 73 ▶ $now //= UID2::Client::Timestamp->now;
Condition66%2/3
$now //= "UID2::Client::Timestamp"->now
l!l&&r!l&&!r
7120
MC/DC0%0/2
$now //= "UID2::Client::Timestamp"->now
$now "UID2::Client::Timestamp"->now
Truth table66%2/3
A //= B
A= $nowB= "UID2::Client::Timestamp"->now
ABresult
1X1
011
000
39 73 $self->{latest_expires} > $now->get_epoch_second;
40 }
41  
42 37 ▶sub get_active_site_key {
Subroutine get_active_site_key: called CC=5 SCAR=16.1
Pod undocumented
43 37 my ($self, $site_id, $now) = @_;
44 37 ▶ my $keys = $self->{keys_by_site}->{$site_id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $keys = $self->{"keys_by_site"}{$site_id} or return 35 2 37
45 35 ▶ $now //= UID2::Client::Timestamp->now;
Condition66%2/3
$now //= "UID2::Client::Timestamp"->now
l!l&&r!l&&!r
3410
MC/DC0%0/2
$now //= "UID2::Client::Timestamp"->now
$now "UID2::Client::Timestamp"->now
Truth table66%2/3
A //= B
A= $nowB= "UID2::Client::Timestamp"->now
ABresult
1X1
011
000
46 35 my $second = $now->get_epoch_second;
47 35 ▶ my $i = upper_bound { $_->activates <=> $second } @$keys;
Subroutine __ANON__: called CC=1 SCAR=0.0
48 35 ▶ while ($i > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 34 8 42
49 34 $i--;
50 34 ▶ return $keys->[$i] if $keys->[$i]->is_active($now);
Branch: 1 branch
BranchTrueFalseTotal
if $keys->[$i]->is_active($now) 27 7 34
51 }
52 8 return;
53 }
54  
55 5 1;
56 __END__
« Client.pm ↑ Summary Client/Key.pm »