Plagger/Crypt.pm untested

filter: Statementstmt 0.0% 0 / 19 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 32 CC 2 SCAR 12.8
CC
2
Cov
0%
decrypt
6.0
encrypt
2.0
BEGIN
2.0
CRAP 3.6
1 package Plagger::Crypt;
2 use strict;
3 use Module::Pluggable::Fast
4 search => [ qw/Plagger::Crypt/ ],
5 require => 1;
6  
7 my %handlers = map { $_->id => $_ } __PACKAGE__->plugins;
8 my $re = "^(" . join("|", map $_->id, __PACKAGE__->plugins) . ")::";
9  
10 sub decrypt {
11 my($class, $ciphertext, @args) = @_;
12  
13 if ($ciphertext =~ s!$re!!) {
14 my $handler = $handlers{$1};
15 my @param = split /::/, $ciphertext;
16 return $handler->decrypt(@param, @args);
17 }
18  
19 return $ciphertext; # just plain text
20 }
21  
22 sub encrypt {
23 my($class, $plaintext, $driver, @param) = @_;
24 my $handler = $handlers{$driver}
25 or Plagger->context->error("No crypt handler for $driver");
26 join '::', $driver, $handler->encrypt($plaintext, @param);
27 }
28  
29 1;