File: Crypt.pm

package info (click to toggle)
libdbix-class-encodedcolumn-perl 0.00020-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 236 kB
  • sloc: perl: 616; sql: 48; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package DBIx::Class::EncodedColumn::Crypt;

use strict;
use warnings;

our $VERSION = '0.01';

sub make_encode_sub {
    my ($class, $col, $args) = @_;
    my $gen_salt_meth = $args->{'salt'};
    die "Valid 'salt' is a coderef which returns the salt string."
        unless ref $gen_salt_meth eq 'CODE';

    return sub {
        my ($plain_text, $salt) = @_;
        $salt ||= $gen_salt_meth->();
        return crypt($plain_text, $salt);
    };
}

sub make_check_sub {
    my($class, $col, $args) = @_;
    #fast fast fast
    return eval qq^ sub {
        my \$col_v = \$_[0]->get_column('${col}');
        \$_[0]->_column_encoders->{${col}}->(\$_[1], \$col_v) eq \$col_v;
    } ^ || die($@);
}

1;

__END__;

=head1 NAME

DBIx::Class::EncodedColumn::Crypt - Encrypt columns using crypt()

=head1 SEE ALSO

L<crypt|http://perldoc.perl.org/functions/crypt.html>

=head1 AUTHOR

wreis: Wallace reis <wreis@cpan.org>

=head1 LICENSE

This library is free software, you can redistribute it and/or modify it under
the same terms as Perl itself.

=cut