Authentication/Model/SAML2/Db.pm

filter: Statementstmt 94.4% 34 / 36 Branchbran 50.0% 1 / 2 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 94.3% 50 / 53 CC 3 SCAR 4.9
CC
3
Cov
92%
get
3.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« Authentication/Model/SAML2/Hash.pm ↑ Summary Authentication/Model/Db.pm »
1 package MojoX::Authentication::Model::SAML2::Db;
2 4 { our $VERSION = '0.100' }
3  
4 4 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use experimental qw< signatures >;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use JSON::PP qw< encode_json decode_json >;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use constant DEFAULT_TABLE => 'logged_in';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 with 'MojoX::Authentication::Model::Role::MojoDbWrap';
12  
13 4 has table => (is => 'ro', default => DEFAULT_TABLE);
14  
15 15 ▶sub get ($self, $key) {
Subroutine get: called CC=3 SCAR=12.0
Pod documented
16 15 my $res = $self->wmdb->db->select($self->table, '*', { k => $key });
17 15 ▶ my $record = $res->hash // return;
Condition100%2/2
$res->hash // (return)
l!l
114
MC/DC100%1/1
$res->hash // (return)
$res->hash
Truth table100%2/2
A
A= $res->hash
Aresult
11
00
18 11 ▶ return decode_json($record->{data}) if $record->{expire} > time();
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"expire"} > time 11 0 11
19 0 $self->wipe($key);
20 0 return;
21 }
22  
23 11 ▶sub set ($self, $data, $key, $expire) {
Subroutine set: called CC=1 SCAR=0.0
Pod documented
24 11 $self->wipe($key);
25 11 my $db = $self->wmdb->db;
26 11 my $table = $self->table;
27 11 my $now = time();
28 11 $db->delete($table, { expire => { '<=', $now } });
29 11 $db->insert($table,
30 {
31 k => $key,
32 expire => $expire,
33 data => encode_json($data)
34 }
35 );
36 11 return $self;
37 }
38  
39 14 ▶sub wipe ($self, $key) {
Subroutine wipe: called CC=1 SCAR=0.0
Pod documented
40 14 $self->wmdb->db->delete($self->table, { k => $key });
41 14 return $self;
42 }
43  
44 4 1;
« Authentication/Model/SAML2/Hash.pm ↑ Summary Authentication/Model/Db.pm »