CryptColumn.pm

filter: Statementstmt 85.9% 61 / 71 Branchbran 55.5% 10 / 18 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 82.3% 14 / 17 Podpod 100% 4 / 4 totaltotal 75.0% 90 / 120 SCAR 27.3
CC
13
Cov
76%
register_column
8.6
__ANON__
5.3
verify_and_rehash_password
5.3
CRAP 15.4
↑ Summary InflateColumn/Crypt/Passphrase.pm »
1 package DBIx::Class::CryptColumn;
2 2 $DBIx::Class::CryptColumn::VERSION = '0.007';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Sub::Util 1.40 'set_subname';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use parent 'DBIx::Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 __PACKAGE__->load_components(qw(InflateColumn::Crypt::Passphrase));
12  
13 sub new {
14 1 ▶ my ($self, $attr, @rest) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
15  
16 1 for my $col (grep { !/^-/ } keys %{ $attr }) {
17 1 ▶ next unless my $inflate = $self->column_info($col)->{inflate_passphrase};
Branch: 1 branch
BranchTrueFalseTotal
unless my $inflate = $self->column_info($col)->{"inflate_passphrase"} 0 1 1
18 1 $attr->{$col} = $inflate->hash_password($attr->{$col});
19 }
20  
21 1 return $self->next::method($attr, @rest);
22 }
23  
24 sub _export_sub {
25 3 ▶ my ($self, $name, $sub) = @_;
Subroutine _export_sub: called CC=1 SCAR=0.0
26 3 my $full_name = $self->result_class . "::$name";
27 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 *$full_name = set_subname $full_name => $sub;
29 }
30  
31 sub register_column {
32 2 ▶ my ($self, $column, $info, @rest) = @_;
Subroutine register_column: called CC=6 SCAR=21.5
Pod documented
33  
34 2 ▶ if (my $args = $info->{inflate_passphrase}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $args = $info->{"inflate_passphrase"}) 1 1 2
35 1 ▶ $self->throw_exception(q['inflate_passphrase' must be a hash reference]) unless ref $args eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "HASH" 0 1 1
36  
37 1 my $crypt_passphrase = Crypt::Passphrase->new(%{$args});
38  
39 1 ▶ if (defined(my $name = $args->{verify_method})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $args->{"verify_method"})) 1 0 1
40 $self->_export_sub($name, sub {
41 0 ▶ my ($row, $password) = @_;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine verify_passphrase: called CC=1 SCAR=1.2
42 0 return $crypt_passphrase->verify_password($password, $row->get_column($column));
43 1 });
44 }
45  
46 1 ▶ if (defined(my $name = $args->{rehash_method})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $args->{"rehash_method"})) 1 0 1
47 $self->_export_sub($name, sub {
48 0 ▶ my $row = shift;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine passphrase_needs_rehash: called CC=1 SCAR=1.2
49 0 return $crypt_passphrase->needs_rehash($row->get_column($column));
50 1 });
51 }
52  
53 1 ▶ if (defined(my $name = $args->{verify_and_rehash_method})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $args->{"verify_and_rehash_method"})) 1 0 1
54 $self->_export_sub($name, sub {
55 0 ▶ my ($row, $password) = @_;
Subroutine __ANON__: not called CC=3 SCAR=16.7
Subroutine verify_and_rehash_password: called CC=3 SCAR=16.7
56  
57 0 my $hash = $row->get_column($column);
58 0 my $result = $crypt_passphrase->verify_password($password, $hash);
59 0 ▶ if ($result && $crypt_passphrase->needs_rehash($hash)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result and $crypt_passphrase->needs_rehash($hash)) 0 0 0
if ($result and $crypt_passphrase->needs_rehash($hash)) 1 0 1
Condition16%1/6
$result and $crypt_passphrase->needs_rehash($hash)
!ll&&!rl&&r
000
$result and $crypt_passphrase->needs_rehash($hash)
!ll&&!rl&&r
001
MC/DC0%0/2
$result and $crypt_passphrase->needs_rehash($hash)
$result $crypt_passphrase->needs_rehash($hash)
MC/DC0%0/2
$result and $crypt_passphrase->needs_rehash($hash)
$result $crypt_passphrase->needs_rehash($hash)
Truth table0%0/3
A and B
A= $resultB= $crypt_passphrase->needs_rehash($hash)
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $resultB= $crypt_passphrase->needs_rehash($hash)
ABresult
0X0
100
111
60 0 $row->update({ $column => $password })->discard_changes;
61 }
62  
63 0 return $result;
64 1 });
65 }
66  
67 1 $info->{inflate_passphrase} = $crypt_passphrase;
68 }
69  
70 2 $self->next::method($column, $info, @rest);
71 }
72  
73 sub set_column {
74 3 ▶ my ($self, $col, $val, @rest) = @_;
Subroutine set_column: called CC=2 SCAR=6.9
Pod documented
75  
76 3 my $inflate = $self->column_info($col)->{inflate_passphrase};
77 3 ▶ $val = $inflate->hash_password($val) if $inflate;
Branch: 1 branch
BranchTrueFalseTotal
if $inflate 2 1 3
78  
79 3 return $self->next::method($col, $val, @rest);
80 }
81  
82 sub set_inflated_column {
83 1 ▶ my ($self, $col, $val, @rest) = @_;
Subroutine set_inflated_column: called CC=1 SCAR=0.0
Pod documented
84 1 local $self->column_info($col)->{inflate_passphrase};
85 1 $self->next::method($col, $val, @rest);
86 }
87  
88 2 1;
89  
90 # ABSTRACT: Automatically hash password/passphrase columns
91  
92 __END__
↑ Summary InflateColumn/Crypt/Passphrase.pm »