blib/lib/Yukki/Model/User.pm

filter: Statementstmt 84.6% 55 / 65 Branchbran 50.0% 4 / 8 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 14 / 16 Podpod 100% 5 / 5 totaltotal 77.8% 81 / 104 CC 7 SCAR 8.2
CC
7
Cov
78%
delete
6.0
save
4.2
find
2.1
CRAP 2.3
« blib/lib/Yukki/Types.pm ↑ Summary blib/lib/Yukki/Model/FilePreview.pm »
1 package Yukki::Model::User;
2 5 $Yukki::Model::User::VERSION = '0.991_007'; # TRIAL
3 5 $Yukki::Model::User::VERSION = '0.991007';
4 5 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 extends 'Yukki::Model';
9  
10 5 ▶use Yukki::Types qw( LoginName );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Yukki::TextUtil qw( load_file );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use Type::Params qw( validate );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Type::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Types::Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Types::Standard qw( slurpy Dict );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 ▶use Yukki::User;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # ABSTRACT: lookup users
23  
24  
25 4 ▶sub set_password {
Subroutine set_password: called CC=2 SCAR=7.0
Pod documented
26 4 my ($self, $user, $clear_password) = @_;
27 4 ▶ $clear_password //= $user->password;
Condition66%2/3
$clear_password //= $user->password
l!l&&r!l&&!r
130
MC/DC0%0/2
$clear_password //= $user->password
$clear_password $user->password
Truth table66%2/3
A //= B
A= $clear_passwordB= $user->password
ABresult
1X1
011
000
28  
29 4 my $digest = $self->app->hasher;
30 4 $digest->add($clear_password);
31 4 $user->password($digest->generate);
32  
33 4 return;
34 }
35  
36  
37 4 ▶sub save {
Subroutine save: called CC=4 SCAR=14.5
Pod documented
38 4 my ($self, $user, %opt) = @_;
39  
40 4 my $user_file = $self->locate('user_path', $user->login_name);
41  
42 4 ▶ if ($opt{create_only} && $user_file->exists) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"create_only"} and $user_file->exists) 0 4 4
Condition33%1/3
$opt{"create_only"} and $user_file->exists
!ll&&!rl&&r
400
MC/DC0%0/2
$opt{"create_only"} and $user_file->exists
$opt{"create_only"} $user_file->exists
Truth table33%1/3
A and B
A= $opt{"create_only"}B= $user_file->exists
ABresult
0X0
100
111
43 0 die "User ", $user->login_name, " already exists.";
44 }
45  
46 4 $user_file->parent->mkpath;
47 4 ▶ $user_file->chmod(0600) if $user_file->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $user_file->exists 1 3 4
48 4 $user_file->spew_utf8($user->dump_yaml);
49 4 $user_file->chmod(0400);
50  
51 4 return;
52 }
53  
54  
55 0 ▶sub delete {
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
56 0 my ($self, $user) = @_;
57  
58 0 my $user_file = $self->locate('user_path', $user->login_name);
59 0 ▶ $user_file->remove if $user_file->is_file;
Branch: 1 branch
BranchTrueFalseTotal
if $user_file->is_file 0 0 0
60  
61 0 return;
62 }
63  
64  
65 1 ▶sub find {
Subroutine find: called CC=2 SCAR=7.2
Pod documented
66 1 my ($self, $opt)
67 = validate(\@_, class_type(__PACKAGE__),
68 slurpy Dict[
69 login_name => LoginName
70 ],
71 );
72 1 my $login_name = $opt->{login_name};
73  
74 1 my $user_file = $self->locate('user_path', $login_name);
75 1 ▶ if ($user_file->exists) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user_file->exists) 1 0 1
76 1 return Yukki::User->load_yaml($user_file->slurp_utf8);
77 }
78  
79 0 return;
80 }
81  
82  
83 0 ▶sub list {
Subroutine list: not called CC=1 SCAR=6.9
Pod documented
84 0 my $self = shift;
85  
86 0 my $user_dir = $self->locate('user_path');
87 0 return map { $_->basename } $user_dir->children;
88 }
89  
90 5 1;
91  
92 __END__
« blib/lib/Yukki/Types.pm ↑ Summary blib/lib/Yukki/Model/FilePreview.pm »