File Coverage

blib/lib/Mail/BIMI/Role/CacheBackend.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Mail::BIMI::Role::CacheBackend;
2             # ABSTRACT: Cache handling backend
3             our $VERSION = '3.20210301'; # VERSION
4 30     30   21462 use 5.20.0;
  30         131  
5 30     30   209 use Moose::Role;
  30         72  
  30         1870  
6 30     30   151174 use Mail::BIMI::Prelude;
  30         85  
  30         307  
7 30     30   25323 use Digest::SHA;
  30         80702  
  30         6178  
8              
9             has parent => ( is => 'ro', required => 1, weak_ref => 1,
10             documentation => 'Parent class for cacheing' );
11             has _cache_hash => ( is => 'ro', lazy => 1, builder => '_build_cache_hash' );
12             requires 'get_from_cache';
13             requires 'put_to_cache';
14             requires 'delete_cache';
15              
16              
17 30     30   53 sub _build_cache_hash($self) {
  30         46  
  30         53  
18 30         258 my $context = Digest::SHA->new;
19             ## TODO make sure there are no wide characters present in cache key
20 30         1185 $context->add($self->parent->_cache_key);
21 29         207 my $hash = $context->hexdigest;
22 29         96 $hash =~ s/ //g;
23 29         832 return $hash;
24             }
25              
26             1;
27              
28             __END__
29              
30             =pod
31              
32             =encoding UTF-8
33              
34             =head1 NAME
35              
36             Mail::BIMI::Role::CacheBackend - Cache handling backend
37              
38             =head1 VERSION
39              
40             version 3.20210301
41              
42             =head1 DESCRIPTION
43              
44             Role for implementing a cache backend
45              
46             =head1 REQUIRES
47              
48             =over 4
49              
50             =item * L<Digest::SHA|Digest::SHA>
51              
52             =item * L<Mail::BIMI::Prelude|Mail::BIMI::Prelude>
53              
54             =item * L<Moose::Role|Moose::Role>
55              
56             =back
57              
58             =head1 AUTHOR
59              
60             Marc Bradshaw <marc@marcbradshaw.net>
61              
62             =head1 COPYRIGHT AND LICENSE
63              
64             This software is copyright (c) 2020 by Marc Bradshaw.
65              
66             This is free software; you can redistribute it and/or modify it under
67             the same terms as the Perl 5 programming language system itself.
68              
69             =cut