File Coverage

blib/lib/Digest/Oplop.pm
Criterion Covered Total %
statement 29 29 100.0
branch 4 4 100.0
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 42 42 100.0


line stmt bran cond sub pod time code
1             package Digest::Oplop;
2              
3 1     1   42665 use strict;
  1         2  
  1         32  
4 1     1   4 use warnings;
  1         2  
  1         28  
5 1     1   4 use Digest::MD5 qw(md5_base64);
  1         6  
  1         44  
6 1     1   849 use Encode qw(encode_utf8);
  1         10695  
  1         68  
7 1     1   826 use English '-no_match_vars';
  1         4933  
  1         7  
8              
9 1     1   503 use constant PASSWORD_LENGTH => 8;
  1         2  
  1         63  
10              
11 1     1   6 use base 'Exporter';
  1         1  
  1         349  
12             our @EXPORT_OK = qw(oplop);
13              
14             our $VERSION = '0.01';
15              
16             sub oplop {
17 7     7 1 3718 my ( $master_password, $label ) = @_;
18 7         31 my $password = md5_base64( encode_utf8( $master_password . $label ) );
19              
20             ## DIgest::MD5 has no alternative to base64.urlsafe_b64encode, but
21             ## this statement realize their implemention description
22              
23 7         59 $password =~ tr[+/][-_];
24              
25 7 100       30 if ( $password =~ /(\d+)/ ) {
26 6 100       26 if ( $LAST_MATCH_START[0] > PASSWORD_LENGTH - 1 ) {
27 3         8 $password = $1 . $password;
28             }
29             }
30             else {
31 1         3 $password = "1$password";
32             }
33 7         38 return substr $password, 0, PASSWORD_LENGTH;
34             }
35             1;
36              
37             __END__