File Coverage

blib/lib/Kelp/Module/Bcrypt.pm
Criterion Covered Total %
statement 14 16 87.5
branch n/a
condition 2 8 25.0
subroutine 3 4 75.0
pod 1 1 100.0
total 20 29 68.9


line stmt bran cond sub pod time code
1             package Kelp::Module::Bcrypt;
2              
3 1     1   38485 use Kelp::Base 'Kelp::Module';
  1         3  
  1         7  
4 1     1   1043 use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
  1         10141  
  1         356  
5              
6             our $VERSION = 0.1;
7              
8             sub build {
9 1     1 1 168 my ( $self, %args ) = @_;
10              
11 1   50     11 my $cost = sprintf( '%02d', $args{cost} // 6 );
12 1   33     6 my $salt = $args{salt} // do {
13 1         2 my $num = 999999;
14 1         1039 my $rnd = crypt( rand($num), rand($num) ) . crypt( rand($num), rand($num) );
15 1         7 en_base64( substr( $rnd, 4, 16 ) );
16             };
17 1         23 my $_set = join( '$', '$2a', $cost, $salt );
18              
19             $self->register(
20             bcrypt => sub {
21 0     0     my ( $app, $text, $settings ) = @_;
22 0   0       return bcrypt( $text, $settings // $_set );
23             }
24 1         19 );
25             }
26              
27             1;
28              
29             __END__