File Coverage

blib/lib/DBIx/Class/InflateColumn/Authen/Passphrase.pm
Criterion Covered Total %
statement 21 21 100.0
branch 3 4 75.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 1 1 100.0
total 34 36 94.4


line stmt bran cond sub pod time code
1 1     1   226245 use strict;
  1         9  
  1         54  
2 1     1   6 use warnings;
  1         2  
  1         50  
3              
4             package DBIx::Class::InflateColumn::Authen::Passphrase; # git description: v0.02-2-gdc402d1
5             # ABSTRACT: Inflate/deflate columns to Authen::Passphrase instances
6              
7             our $VERSION = '0.03';
8              
9 1     1   510 use Authen::Passphrase;
  1         2588  
  1         33  
10 1     1   7 use parent 'DBIx::Class';
  1         2  
  1         6  
11              
12             #pod =head1 SYNOPSIS
13             #pod
14             #pod __PACKAGE__->load_components(qw(InflateColumn::Authen::Passphrase));
15             #pod
16             #pod __PACKAGE__->add_columns(
17             #pod id => {
18             #pod data_type => 'integer',
19             #pod is_auto_increment => 1,
20             #pod },
21             #pod passphrase_rfc2307 => {
22             #pod data_type => 'text',
23             #pod inflate_passphrase => 'rfc2307',
24             #pod },
25             #pod passphrase_crypt => {
26             #pod data_type => 'text',
27             #pod inflate_passphrase => 'crypt',
28             #pod },
29             #pod );
30             #pod
31             #pod __PACKAGE__->set_primary_key('id');
32             #pod
33             #pod
34             #pod # in application code
35             #pod $rs->create({ passphrase_rfc2307 => Authen::Passphrase::RejectAll->new });
36             #pod
37             #pod my $row = $rs->find({ id => $id });
38             #pod if ($row->passphrase_rfc2307->match($input)) { ...
39             #pod
40             #pod =head1 DESCRIPTION
41             #pod
42             #pod Provides inflation and deflation for Authen::Passphrase instances from and to
43             #pod either RFC 2307 or crypt encoding.
44             #pod
45             #pod To enable both inflating and deflating, C must be set to a
46             #pod valid passphrase encoding. Currently the only supported encodings are C
47             #pod and C. The specified encoding will be used both when storing
48             #pod C instances in columns, and when creating
49             #pod C instances from columns. See L for
50             #pod details on passphrase encodings.
51             #pod
52             #pod Note that not all passphrase schemes supported by C can be
53             #pod represented in either RFC 2307 or crypt encoding. Chose the kind of passphrase
54             #pod encoding you're using based on the encoding supported by the passphrase algorithms
55             #pod you're using.
56             #pod
57             #pod When trying to encode a passphrase instance with an encoding that doesn't
58             #pod support it, an exception will be thrown. Similarly, when trying to load a
59             #pod passphrase instance from a faulty or unknown encoded representation, an
60             #pod exception will be thrown.
61             #pod
62             #pod =method register_column
63             #pod
64             #pod Chains with the C method in C, and sets up
65             #pod passphrase columns appropriately. This would not normally be directly called by
66             #pod end users.
67             #pod
68             #pod =cut
69              
70             sub register_column {
71 3     3 1 3535 my ($self, $column, $info, @rest) = @_;
72              
73 3         15 $self->next::method($column, $info, @rest);
74 3 100       1387 return unless my $encoding = $info->{inflate_passphrase};
75              
76 2 50 66     15 $self->throw_exception(q['rfc2307' and 'crypt' are the only supported types of passphrase columns])
77             unless $encoding eq 'rfc2307' || $encoding eq 'crypt';
78              
79             $self->inflate_column(
80             $column => {
81 2     2   22876 inflate => sub { Authen::Passphrase->${\"from_${encoding}"}(shift) },
  2         22  
82 2     2   158713 deflate => sub { shift->${\"as_${encoding}"} },
  2         15  
83             },
84 2         32 );
85             }
86              
87             1;
88              
89             __END__