| 1 | package MooseX::Types::Digest; | ||||||||||
| 2 | 1 | $MooseX::Types::Digest::VERSION = '1.01'; | |||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | MooseX::Types::Digest - Digest datatypes for Moose | ||||||||||
| 9 | |||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||
| 11 | |||||||||||
| 12 | package Foo; | ||||||||||
| 13 | |||||||||||
| 14 | use Moose; | ||||||||||
| 15 | use Moose::Util::TypeConstraints; | ||||||||||
| 16 | use MooseX::Types::Digest qw( MD5 SHA1 SHA224 SHA256 SHA384 SHA512 SHA3_224, SHA3_256, SHA3_384 and SHA3_512 ); | ||||||||||
| 17 | |||||||||||
| 18 | has md5 => ( is => 'rw', isa => MD5 ); | ||||||||||
| 19 | has sha1 => ( is => 'rw', isa => SHA1 ); | ||||||||||
| 20 | |||||||||||
| 21 | Some string type constraints that match commonly used hexdigests. See L<Digest::MD5>, L<Digest::SHA1> or L<Digest::SHA3>. | ||||||||||
| 22 | |||||||||||
| 23 | =over | ||||||||||
| 24 | |||||||||||
| 25 | =item * MD5 | ||||||||||
| 26 | |||||||||||
| 27 | A Str that looks like a valid MD5 hexdigest. | ||||||||||
| 28 | |||||||||||
| 29 | =item * SHA1 | ||||||||||
| 30 | |||||||||||
| 31 | A Str that looks like a valid SHA1 hexdigest. | ||||||||||
| 32 | |||||||||||
| 33 | =back | ||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | 1 | ▶ | use MooseX::Types -declare => [qw/ MD5 SHA1 SHA224 SHA256 SHA384 SHA512 SHA3_224 SHA3_256 SHA3_384 SHA3_512 /]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | |||||||||||
| 39 | subtype MD5, | ||||||||||
| 40 | as "Str", | ||||||||||
| 41 | 0 | ▶ | where { (m/^[0-9a-f]{32}$/i) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 42 | 4 | ▶ | message {"Must be 32 chars, and contain only [0-9a-f]" }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 43 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 44 | 2 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 2 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 46 | . qq{ $_[1] =~ m/^[0-9a-f]{32}\$/i }; | ||||||||||
| 47 | } | ||||||||||
| 48 | : () | ||||||||||
| 49 | 1 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | |||||||||||
| 51 | subtype SHA1, | ||||||||||
| 52 | as "Str", | ||||||||||
| 53 | 0 | ▶ | where { (m/^[0-9a-f]{40}$/i) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 54 | 4 | ▶ | message {"Must be 40 chars, and contain only [0-9a-f]" }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 55 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 56 | 2 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 57 | 2 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 58 | . qq{ $_[1] =~ m/^[0-9a-f]{40}\$/i }; | ||||||||||
| 59 | } | ||||||||||
| 60 | : () | ||||||||||
| 61 | 1 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | |||||||||||
| 63 | subtype SHA224, | ||||||||||
| 64 | as "Str", | ||||||||||
| 65 | 0 | ▶ | where { (m/^[0-9a-f]{56}$/i) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 66 | 4 | ▶ | message {"Must be 56 chars, and contain only [0-9a-f]" }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 67 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 68 | 2 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 69 | 2 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 70 | . qq{ $_[1] =~ m/^[0-9a-f]{56}\$/i }; | ||||||||||
| 71 | } | ||||||||||
| 72 | : () | ||||||||||
| 73 | 1 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | |||||||||||
| 75 | subtype SHA256, | ||||||||||
| 76 | as "Str", | ||||||||||
| 77 | 0 | ▶ | where { (m/^[0-9a-f]{64}$/i) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 78 | 4 | ▶ | message {"Must be 64 chars, and contain only [0-9a-f]" }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 79 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 80 | 2 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 81 | 2 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 82 | . qq{ $_[1] =~ m/^[0-9a-f]{64}\$/i }; | ||||||||||
| 83 | } | ||||||||||
| 84 | : () | ||||||||||
| 85 | 1 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | |||||||||||
| 87 | subtype SHA384, | ||||||||||
| 88 | as "Str", | ||||||||||
| 89 | 0 | ▶ | where { (m/^[0-9a-f]{96}$/i) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 90 | 4 | ▶ | message {"Must be 96 chars, and contain only [0-9a-f]" }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 91 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 92 | 2 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 93 | 2 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 94 | . qq{ $_[1] =~ m/^[0-9a-f]{96}\$/i }; | ||||||||||
| 95 | } | ||||||||||
| 96 | : () | ||||||||||
| 97 | 1 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | |||||||||||
| 99 | subtype SHA512, | ||||||||||
| 100 | as "Str", | ||||||||||
| 101 | 0 | ▶ | where { (m/^[0-9a-f]{128}$/i) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 102 | 4 | ▶ | message {"Must be 128 chars, and contain only [0-9a-f]" }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 103 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 104 | 2 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 105 | 2 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 106 | . qq{ $_[1] =~ m/^[0-9a-f]{128}\$/i }; | ||||||||||
| 107 | } | ||||||||||
| 108 | : () | ||||||||||
| 109 | 1 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | |||||||||||
| 111 | #3333333333333333333333333333333333333333 | ||||||||||
| 112 | |||||||||||
| 113 | subtype SHA3_224, | ||||||||||
| 114 | as "Str", | ||||||||||
| 115 | 0 | ▶ | where { (m/^[0-9a-f]{56}$/i) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 116 | 4 | ▶ | message {"Must be 56 chars, and contain only [0-9a-f]" }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 117 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 118 | 2 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 119 | 2 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 120 | . qq{ $_[1] =~ m/^[0-9a-f]{56}\$/i }; | ||||||||||
| 121 | } | ||||||||||
| 122 | : () | ||||||||||
| 123 | 1 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | |||||||||||
| 125 | subtype SHA3_256, | ||||||||||
| 126 | as "Str", | ||||||||||
| 127 | 0 | ▶ | where { (m/^[0-9a-f]{64}$/i) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 128 | 4 | ▶ | message {"Must be 64 chars, and contain only [0-9a-f]" }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 129 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 130 | 2 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 131 | 2 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 132 | . qq{ $_[1] =~ m/^[0-9a-f]{64}\$/i }; | ||||||||||
| 133 | } | ||||||||||
| 134 | : () | ||||||||||
| 135 | 1 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | |||||||||||
| 137 | subtype SHA3_384, | ||||||||||
| 138 | as "Str", | ||||||||||
| 139 | 0 | ▶ | where { (m/^[0-9a-f]{96}$/i) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 140 | 4 | ▶ | message {"Must be 96 chars, and contain only [0-9a-f]" }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 141 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 142 | 2 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 143 | 2 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 144 | . qq{ $_[1] =~ m/^[0-9a-f]{96}\$/i }; | ||||||||||
| 145 | } | ||||||||||
| 146 | : () | ||||||||||
| 147 | 1 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | |||||||||||
| 149 | subtype SHA3_512, | ||||||||||
| 150 | as "Str", | ||||||||||
| 151 | 0 | ▶ | where { (m/^[0-9a-f]{128}$/i) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 152 | 4 | ▶ | message {"Must be 128 chars, and contain only [0-9a-f]" }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 153 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 154 | 2 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 155 | 2 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 156 | . qq{ $_[1] =~ m/^[0-9a-f]{128}\$/i }; | ||||||||||
| 157 | } | ||||||||||
| 158 | : () | ||||||||||
| 159 | 1 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 160 | |||||||||||
| 161 | #3333333333333333333333333333333333333 | ||||||||||
| 162 | |||||||||||
| 163 | =head1 AUTHORS | ||||||||||
| 164 | |||||||||||
| 165 | Michael Langner, C<< <mila at cpan.org> >> | ||||||||||
| 166 | Stevan Little, C<< <stevan.little at iinteractive.com> >> | ||||||||||
| 167 | Gregory Oschwald, C<< <oschwald at gmail.com > >> | ||||||||||
| 168 | |||||||||||
| 169 | =head1 BUGS | ||||||||||
| 170 | |||||||||||
| 171 | Please report any bugs or feature requests to | ||||||||||
| 172 | C<bug-moosex-types-digest at rt.cpan.org>, | ||||||||||
| 173 | or through the web interface at | ||||||||||
| 174 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Types-Digest>. | ||||||||||
| 175 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||
| 176 | your bug as I make changes. | ||||||||||
| 177 | |||||||||||
| 178 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 179 | |||||||||||
| 180 | Copyright 2014 Michael Langner, all rights reserved. | ||||||||||
| 181 | |||||||||||
| 182 | This program is free software; you can redistribute it and/or modify it under the | ||||||||||
| 183 | same terms as Perl itself. | ||||||||||
| 184 | |||||||||||
| 185 | =cut | ||||||||||
| 186 | |||||||||||
| 187 | 1 | 1; # track-id: 3a59124cfcc7ce26274174c962094a20 | |||||||||