blib/lib/Data/Password/passwdqc.pm

filter: Statementstmt 94.8% 73 / 77 Branchbran 68.7% 11 / 16 Conditioncond 36.3% 4 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 85.7% 24 / 28 Podpod n/a totaltotal 81.1% 112 / 138 CC 12 SCAR 6.9
CC
12
Cov
85%
__ANON__
4.5
__ANON__
3.3
__ANON__
3.1
CRAP 2.0
↑ Summary passwdqc.xs »
1 package Data::Password::passwdqc;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use POSIX qw(INT_MAX);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use List::MoreUtils qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 our $VERSION = '0.09';
14  
15 6 require XSLoader;
16 6 XSLoader::load('Data::Password::passwdqc', $VERSION);
17  
18  
19 subtype 'Data::Password::passwdqc::ArrayRefOfInts',
20 as 'ArrayRef[Int]',
21 11 ▶ where {
Subroutine __ANON__: called CC=3 SCAR=11.4
22 11 my @min = @{ $_ };
23 11 ▶ @min == 5 && none(sub { $_ > INT_MAX }, @min) && none (sub { $_ && $min[$_] > $min[$_ - 1] }, 0 .. $#min);
Subroutine __ANON__: called CC=1 SCAR=0.3
Subroutine __ANON__: called CC=2 SCAR=7.5
Branch: 2 branches
BranchTrueFalseTotal
@min == 5 and &none(sub { $_ > 2147483647; } , @min) and &none(sub { $_ and $min[$_] > $min[$_ - 1]; } , 0 .. $#min) 11 0 11
$_ and $min[$_] > $min[$_ - 1] 44 11 55
Condition33%1/3
@min == 5 and &none(sub { $_ > 2147483647; } , @min)
!ll&&!rl&&r
0011
MC/DC0%0/2
@min == 5 and &none(sub { $_ > 2147483647; } , @min)
@min == 5 &none(sub { $_ > 2147483647; } , @min)
Truth table33%1/3
A and B
A= @min == 5B= &none(sub { $_ > 2147483647; } , @min)
ABresult
0X0
100
111
24 6 };
25  
26 coerce 'Data::Password::passwdqc::ArrayRefOfInts',
27 from 'ArrayRef[Int|Undef]',
28 5 ▶ via { [ map { defined() ? $_ : INT_MAX } @{ $_ } ] };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 15 10 25
29  
30 6 enum 'Data::Password::passwdqc::OneOrZero', [ 1, 0 ];
31  
32 coerce 'Data::Password::passwdqc::OneOrZero',
33 from 'Bool',
34 2 ▶ via { $_ && 1 || 0 };
Subroutine __ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
$_ and 1 or 0 0 2 2
Condition50%1/2
$_ and 1
!ll
20
MC/DC0%0/1
$_ and 1
$_
Truth table50%1/2
A
A= $_
Aresult
00
11
35  
36 has 'min' => (
37 is => 'rw',
38 isa => 'Data::Password::passwdqc::ArrayRefOfInts',
39 3 ▶ default => sub { [INT_MAX, 24, 11, 8, 7] },
Subroutine __ANON__: called CC=1 SCAR=0.0
40 5 ▶ trigger => sub { $_[0]->_clear_params },
Subroutine __ANON__: called CC=1 SCAR=0.0
41 6 coerce => 1,
42 );
43  
44 has 'max' => (
45 is => 'rw',
46 5 ▶ isa => subtype( 'Int' => where { $_ >= 8 && $_ <= INT_MAX } ),
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 8 and $_ <= 2147483647 5 0 5
47 default => 40,
48 0 ▶ trigger => sub { $_[0]->_clear_params },
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 6 );
50  
51 has 'passphrase_words' => (
52 is => 'rw',
53 5 ▶ isa => subtype( 'Int' => where { $_ <= INT_MAX } ),
Subroutine __ANON__: called CC=1 SCAR=0.0
54 default => 3,
55 0 ▶ trigger => sub { $_[0]->_clear_params },
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 6 );
57  
58 has 'match_length' => (
59 is => 'rw',
60 5 ▶ isa => subtype( 'Int' => where { $_ <= INT_MAX } ),
Subroutine __ANON__: called CC=1 SCAR=0.0
61 default => 4,
62 0 ▶ trigger => sub { $_[0]->_clear_params },
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 6 );
64  
65 has 'similar_deny' => (
66 is => 'rw',
67 isa => 'Data::Password::passwdqc::OneOrZero',
68 default => 1,
69 3 ▶ trigger => sub { $_[0]->_clear_params },
Subroutine __ANON__: called CC=1 SCAR=0.0
70 6 coerce => 1,
71 );
72  
73 has 'random_bits' => (
74 is => 'rw',
75 5 ▶ isa => subtype( 'Int' => where { $_ == 0 || $_ >= 24 && $_ <= 85 } ),
Subroutine __ANON__: called CC=3 SCAR=15.1
Branch: 1 branch
BranchTrueFalseTotal
$_ == 0 or $_ >= 24 and $_ <= 85 0 5 5
Condition33%2/6
$_ == 0 || $_ >= 24 && $_ <= 85
l!l&&r!l&&!r
050
$_ >= 24 and $_ <= 85
!ll&&!rl&&r
005
MC/DC0%0/3
$_ == 0 || $_ >= 24 && $_ <= 85
$_ == 0 $_ >= 24 $_ <= 85
Truth table25%1/4
A || B and C
A= $_ == 0B= $_ >= 24C= $_ <= 85
ABCresult
1XX1
0111
00X0
0100
76 default => 47,
77 0 ▶ trigger => sub { $_[0]->_clear_params },
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 6 );
79  
80 6 has '_params' => (
81 is => 'rw',
82 clearer => '_clear_params',
83 lazy => 1,
84 builder => '_build_params',
85 init_arg => undef,
86 );
87  
88 6 has 'reason' => (
89 is => 'rw',
90 clearer => '_clear_reason',
91 init_arg => undef,
92 );
93  
94  
95 3 ▶sub _build_params {
Subroutine _build_params: called CC=1 SCAR=0.0
96 3 my $self = shift;
97
98 3 my $params = pack 'i*', @{ $self->min }, $self->max,
99 $self->passphrase_words, $self->match_length,
100 $self->similar_deny, $self->random_bits;
101 3 return $params;
102 }
103  
104  
105 26 ▶sub validate_password {
Subroutine validate_password: called CC=2 SCAR=6.9
106 26 my $self = shift;
107  
108 26 my $reason = password_check($self->_params, @_);
109  
110 26 ▶ if ($reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reason) 18 8 26
111 18 $self->reason($reason);
112 18 return !1;
113 }
114  
115 8 return !0;
116 }
117  
118 3 ▶sub generate_password {
Subroutine generate_password: called CC=2 SCAR=7.0
119 3 my $self = shift;
120  
121 3 my $pass = password_generate($self->_params);
122 3 ▶ croak 'Failed to generate password' unless defined $pass;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pass 0 3 3
123  
124 3 return $pass;
125 }
126  
127 29 ▶before [ qw(validate_password generate_password) ] => sub { $_[0]->_clear_reason };
Subroutine __ANON__: called CC=1 SCAR=0.0
128  
129 6 __PACKAGE__->meta->make_immutable;
130  
131 6 1;
132  
133 __END__
↑ Summary passwdqc.xs »