File Coverage

blib/lib/Types/Digest.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 27 27 100.0


line stmt bran cond sub pod time code
1             package Types::Digest;
2 2     2   24408 use strict;
  2         4  
  2         55  
3 2     2   7 use warnings;
  2         3  
  2         87  
4              
5             our $VERSION = '0.1.1';
6              
7 2     2   812 use Type::Library -base, -declare => qw(Md5 Sha1 Sha224 Sha256 Sha384 Sha512);
  2         30192  
  2         20  
8 2     2   3812 use Types::Standard qw(Str);
  2         57899  
  2         14  
9 2     2   1886 use Type::Utils;
  2         6233  
  2         15  
10              
11             =head1 NAME
12              
13             Types::Digest - digests types for Moose and Moo
14              
15             =head1 SYNOPSIS
16              
17             package Foo;
18            
19             use Moose;
20             use Types::Digest qw/Sha256/;
21            
22             has md5 => (
23             is => 'ro',
24             isa => Md5,
25             );
26              
27             has sha256 => (
28             is => 'ro',
29             isa => Sha256,
30             );
31              
32            
33             =head1 DESCRIPTION
34              
35             This module provides common digests types for Moose, Moo, etc.
36              
37             =head1 SUBTYPES
38              
39             =head2 Md5
40              
41             L
42              
43             =head2 Sha1
44              
45             L
46              
47             =head2 Sha224
48              
49             L
50              
51             =head2 Sha256
52              
53             L
54              
55             =head2 Sha384
56              
57             L
58              
59             =head2 Sha512
60              
61             L
62              
63             =cut
64              
65             _declare_digest('Md5', 32);
66             _declare_digest('Sha1', 40);
67             _declare_digest('Sha224', 56);
68             _declare_digest('Sha256', 64);
69             _declare_digest('Sha384', 96);
70             _declare_digest('Sha512', 128);
71              
72             sub _declare_digest {
73 12     12   16 my ($name, $len) = @_;
74              
75             declare $name,
76 36     36   17192 as Str, where { /[a-f0-9]{$len}/i },
77 12     12   26 message { "Must be $len chars, and contain only [0-9a-fA-F]" };
  12         2406  
78             }
79              
80             =head1 SEE ALSO
81              
82             this module is inspired by L
83              
84             =head1 LICENSE
85              
86             Copyright (C) Avast Software.
87              
88             This library is free software; you can redistribute it and/or modify
89             it under the same terms as Perl itself.
90              
91             =head1 AUTHOR
92              
93             Jan Seidl Eseidl@avast.comE
94              
95             =cut
96              
97             1;