Authentication/Model/Db.pm

filter: Statementstmt 100% 45 / 45 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 96.8% 62 / 64 CC 4 SCAR 3.4
CC
4
Cov
96%
_select
2.0
create
2.0
save_user
2.0
CRAP 1.4
« Authentication/Model/SAML2/Db.pm ↑ Summary Authentication/Model/Role/MojoDbWrap.pm »
1 package MojoX::Authentication::Model::Db;
2 4 { our $VERSION = '0.099001' }
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 Ouch qw< :trytiny_var >;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use constant DEFAULT_FOR => {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 name => 'dby',
11 table => 'account',
12 username_column => 'username',
13 4 };
14  
15 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 with 'MojoX::Authentication::Model::Role::Creator';
18 4 with 'MojoX::Authentication::Model::Role::Local';
19 4 with 'MojoX::Authentication::Model::Role::MojoDbWrap';
20 4 with 'MojoX::Authentication::Model::Role::Remap';
21  
22 4 has name => (is => 'rw', default => DEFAULT_FOR->{name});
23 has username_column
24 4 => (is => 'ro', default => DEFAULT_FOR->{username_column});
25 2 ▶has remaps => (is => 'ro', default => sub { return [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
26 4 has table => (is => 'ro', default => DEFAULT_FOR->{table});
27  
28 1 ▶sub create ($class, $config, %args) {
Subroutine create: called CC=2 SCAR=7.0
Pod documented
29 1 %args = $class->_create_args(DEFAULT_FOR->{name}, $config, %args);
30 1 ▶ ouch 404, 'missing argument for wmdb' unless defined($args{wmdb});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"wmdb"} 0 1 1
31 1 my $self = $class->new(%args);
32 # FIXME possibly address stuff like creating the table, ecc.
33 1 return $self;
34 }
35  
36 11 ▶sub load_user ($self, $ignored, $uid) {
Subroutine load_user: called CC=1 SCAR=0.0
Pod documented
37 11 return $self->_select($self->username_column, $uid);
38 }
39  
40 # this method is required for compositing
41 # MojoX::Authentication::Model::Role::Local
42 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
43 4 *{load_user_by_username} = \&load_user;
44 }
45  
46 5 ▶sub save_user ($self, $user, $is_secret_cleartext = 0) {
Subroutine save_user: called CC=2 SCAR=6.9
Pod documented
47 5 my $u = $self->user_for_save($user, $is_secret_cleartext);
48 5 my $data = $self->remap($u, $self->remaps, 'backwards');
49  
50 5 my $table = $self->table;
51 5 my $id_column = $self->username_column;
52  
53 5 $self->wmdb->upsert($table, $data, { conflicting => $id_column });
54  
55 5 return $self;
56 }
57  
58 11 ▶sub _select ($self, %condition) {
Subroutine _select: called CC=2 SCAR=7.1
59 11 my $r = $self->wmdb->db->select($self->table, '*', \%condition)->hash;
60 11 ▶ return unless defined($r);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r 0 11 11
61 11 return $self->remap($r, $self->remaps);
62 }
63  
64 4 1;
« Authentication/Model/SAML2/Db.pm ↑ Summary Authentication/Model/Role/MojoDbWrap.pm »