| 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)
MC/DC100%1/1
$res->hash // (return)
$res->hash
Truth table100%2/2
A
A= $res->hash
| |||||||||||||
| 18 | 11 | ▶ | return decode_json($record->{data}) if $record->{expire} > time(); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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; | |||||||||||