| 1 | package Venus::Role::Digestable; | ||||||||||||
| 2 | |||||||||||||
| 3 | 61 | ▶ | use 5.014; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 61 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 61 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 61 | ▶ | use Venus::Role 'with'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 61 | with 'Venus::Role::Dumpable'; | |||||||||||
| 11 | |||||||||||||
| 12 | # METHODS | ||||||||||||
| 13 | |||||||||||||
| 14 | sub digester { | ||||||||||||
| 15 | 360 | ▶ | my ($self, $algorithm, $method, @args) = @_; | ||||||||||
|
Subroutine
digester: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 16 | |||||||||||||
| 17 | 360 | my $result = $self->dump($method, @args); | |||||||||||
| 18 | |||||||||||||
| 19 | 360 | require Digest; | |||||||||||
| 20 | |||||||||||||
| 21 | 360 | ▶ | my $digest = Digest->new(uc($algorithm || 'sha-1')); | ||||||||||
|
Condition100%2/2
$algorithm || 'sha-1'
MC/DC100%1/1
$algorithm || 'sha-1'
$algorithm
Truth table100%2/2
A
A= $algorithm
| |||||||||||||
| 22 | |||||||||||||
| 23 | 360 | return $digest->add($result); | |||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | sub digest { | ||||||||||||
| 27 | 349 | ▶ | my ($self, $algorithm, $method, @args) = @_; | ||||||||||
|
Subroutine
digest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 28 | |||||||||||||
| 29 | 349 | return $self->hexdigest($algorithm, $method, @args); | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | sub b64digest { | ||||||||||||
| 33 | 3 | ▶ | my ($self, $algorithm, $method, @args) = @_; | ||||||||||
|
Subroutine
b64digest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 34 | |||||||||||||
| 35 | 3 | return $self->digester($algorithm, $method, @args)->b64digest; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | sub bindigest { | ||||||||||||
| 39 | 3 | ▶ | my ($self, $algorithm, $method, @args) = @_; | ||||||||||
|
Subroutine
bindigest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 40 | |||||||||||||
| 41 | 3 | return $self->digester($algorithm, $method, @args)->digest; | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | sub hexdigest { | ||||||||||||
| 45 | 352 | ▶ | my ($self, $algorithm, $method, @args) = @_; | ||||||||||
|
Subroutine
hexdigest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 46 | |||||||||||||
| 47 | 352 | return $self->digester($algorithm, $method, @args)->hexdigest; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | # EXPORTS | ||||||||||||
| 51 | |||||||||||||
| 52 | sub EXPORT { | ||||||||||||
| 53 | 62 | ▶ | ['digester', 'digest', 'dump', 'dump_pretty', 'b64digest', 'bindigest', 'hexdigest'] | ||||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 61 | 1; | |||||||||||
| 57 | |||||||||||||
| 58 | |||||||||||||
| 59 | |||||||||||||
| 60 | =head1 NAME | ||||||||||||
| 61 | |||||||||||||
| 62 | Venus::Role::Digestable - Digestable Role | ||||||||||||
| 63 | |||||||||||||
| 64 | =cut | ||||||||||||
| 65 | |||||||||||||
| 66 | =head1 ABSTRACT | ||||||||||||
| 67 | |||||||||||||
| 68 | Digestable Role for Perl 5 | ||||||||||||
| 69 | |||||||||||||
| 70 | =cut | ||||||||||||
| 71 | |||||||||||||
| 72 | =head1 SYNOPSIS | ||||||||||||
| 73 | |||||||||||||
| 74 | package Example; | ||||||||||||
| 75 | |||||||||||||
| 76 | use Venus::Class; | ||||||||||||
| 77 | |||||||||||||
| 78 | attr 'test'; | ||||||||||||
| 79 | |||||||||||||
| 80 | with 'Venus::Role::Digestable'; | ||||||||||||
| 81 | |||||||||||||
| 82 | sub execute { | ||||||||||||
| 83 | my ($self, @args) = @_; | ||||||||||||
| 84 | |||||||||||||
| 85 | return [$self->test, @args]; | ||||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | package main; | ||||||||||||
| 89 | |||||||||||||
| 90 | my $example = Example->new(test => 123); | ||||||||||||
| 91 | |||||||||||||
| 92 | # $example->digest; | ||||||||||||
| 93 | |||||||||||||
| 94 | # "a6c3d9ae59f31690eddbdd15271e856a6b6f15d5" | ||||||||||||
| 95 | |||||||||||||
| 96 | =cut | ||||||||||||
| 97 | |||||||||||||
| 98 | =head1 DESCRIPTION | ||||||||||||
| 99 | |||||||||||||
| 100 | This package modifies the consuming package and provides methods for producing | ||||||||||||
| 101 | message digests from a dump of the object or the return value of a dispatched | ||||||||||||
| 102 | method call. All algorithms supported by L<Digest> are supported, e.g. | ||||||||||||
| 103 | C<SHA-1>, C<SHA-224>, C<SHA-256>, C<SHA-384>, C<SHA-512>, C<HMAC-MD5>, | ||||||||||||
| 104 | C<HMAC-SHA-1>, etc. | ||||||||||||
| 105 | |||||||||||||
| 106 | =cut | ||||||||||||
| 107 | |||||||||||||
| 108 | =head1 METHODS | ||||||||||||
| 109 | |||||||||||||
| 110 | This package provides the following methods: | ||||||||||||
| 111 | |||||||||||||
| 112 | =cut | ||||||||||||
| 113 | |||||||||||||
| 114 | =head2 b64digest | ||||||||||||
| 115 | |||||||||||||
| 116 | b64digest(Str $algo, Str $method, Any @args) (Str) | ||||||||||||
| 117 | |||||||||||||
| 118 | The b64digest method returns a base64 formatted digest of the object or return | ||||||||||||
| 119 | value of a dispatched method call. The algorithm defaults to C<SHA-1>. This | ||||||||||||
| 120 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||||
| 121 | return value will be acted on by this method. | ||||||||||||
| 122 | |||||||||||||
| 123 | I<Since C<0.01>> | ||||||||||||
| 124 | |||||||||||||
| 125 | =over 4 | ||||||||||||
| 126 | |||||||||||||
| 127 | =item b64digest example 1 | ||||||||||||
| 128 | |||||||||||||
| 129 | package main; | ||||||||||||
| 130 | |||||||||||||
| 131 | my $example = Example->new(test => 123); | ||||||||||||
| 132 | |||||||||||||
| 133 | my $b64digest = $example->b64digest; | ||||||||||||
| 134 | |||||||||||||
| 135 | # "psPZrlnzFpDt290VJx6FamtvFdU" | ||||||||||||
| 136 | |||||||||||||
| 137 | =back | ||||||||||||
| 138 | |||||||||||||
| 139 | =over 4 | ||||||||||||
| 140 | |||||||||||||
| 141 | =item b64digest example 2 | ||||||||||||
| 142 | |||||||||||||
| 143 | package main; | ||||||||||||
| 144 | |||||||||||||
| 145 | my $example = Example->new(test => 123); | ||||||||||||
| 146 | |||||||||||||
| 147 | my $b64digest = $example->b64digest('sha-1', 'execute'); | ||||||||||||
| 148 | |||||||||||||
| 149 | # "T+raai5I0suKC3VpiZ8bqt0WXE0" | ||||||||||||
| 150 | |||||||||||||
| 151 | =back | ||||||||||||
| 152 | |||||||||||||
| 153 | =over 4 | ||||||||||||
| 154 | |||||||||||||
| 155 | =item b64digest example 3 | ||||||||||||
| 156 | |||||||||||||
| 157 | package main; | ||||||||||||
| 158 | |||||||||||||
| 159 | my $example = Example->new(test => 123); | ||||||||||||
| 160 | |||||||||||||
| 161 | my $b64digest = $example->b64digest('sha-1', 'execute', '456'); | ||||||||||||
| 162 | |||||||||||||
| 163 | # "5Vf077AO11mZZfaQknfOtzfhzPc" | ||||||||||||
| 164 | |||||||||||||
| 165 | =back | ||||||||||||
| 166 | |||||||||||||
| 167 | =cut | ||||||||||||
| 168 | |||||||||||||
| 169 | =head2 bindigest | ||||||||||||
| 170 | |||||||||||||
| 171 | bindigest(Str $algo, Str $method, Any @args) (Str) | ||||||||||||
| 172 | |||||||||||||
| 173 | The bindigest method returns a binary formatted digest of the object or return | ||||||||||||
| 174 | value of a dispatched method call. The algorithm defaults to C<SHA-1>. This | ||||||||||||
| 175 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||||
| 176 | return value will be acted on by this method. | ||||||||||||
| 177 | |||||||||||||
| 178 | I<Since C<0.01>> | ||||||||||||
| 179 | |||||||||||||
| 180 | =over 4 | ||||||||||||
| 181 | |||||||||||||
| 182 | =item bindigest example 1 | ||||||||||||
| 183 | |||||||||||||
| 184 | package main; | ||||||||||||
| 185 | |||||||||||||
| 186 | my $example = Example->new(test => 123); | ||||||||||||
| 187 | |||||||||||||
| 188 | my $bindigest = $example->bindigest; | ||||||||||||
| 189 | |||||||||||||
| 190 | # pack("H*","a6c3d9ae59f31690eddbdd15271e856a6b6f15d5") | ||||||||||||
| 191 | |||||||||||||
| 192 | =back | ||||||||||||
| 193 | |||||||||||||
| 194 | =over 4 | ||||||||||||
| 195 | |||||||||||||
| 196 | =item bindigest example 2 | ||||||||||||
| 197 | |||||||||||||
| 198 | package main; | ||||||||||||
| 199 | |||||||||||||
| 200 | my $example = Example->new(test => 123); | ||||||||||||
| 201 | |||||||||||||
| 202 | my $bindigest = $example->bindigest('sha-1', 'execute'); | ||||||||||||
| 203 | |||||||||||||
| 204 | # pack("H*","4feada6a2e48d2cb8a0b7569899f1baadd165c4d") | ||||||||||||
| 205 | |||||||||||||
| 206 | =back | ||||||||||||
| 207 | |||||||||||||
| 208 | =over 4 | ||||||||||||
| 209 | |||||||||||||
| 210 | =item bindigest example 3 | ||||||||||||
| 211 | |||||||||||||
| 212 | package main; | ||||||||||||
| 213 | |||||||||||||
| 214 | my $example = Example->new(test => 123); | ||||||||||||
| 215 | |||||||||||||
| 216 | my $bindigest = $example->bindigest('sha-1', 'execute', '456'); | ||||||||||||
| 217 | |||||||||||||
| 218 | # pack("H*","e557f4efb00ed7599965f6909277ceb737e1ccf7") | ||||||||||||
| 219 | |||||||||||||
| 220 | =back | ||||||||||||
| 221 | |||||||||||||
| 222 | =cut | ||||||||||||
| 223 | |||||||||||||
| 224 | =head2 digest | ||||||||||||
| 225 | |||||||||||||
| 226 | digest(Str $algo, Str $method, Any @args) (Str) | ||||||||||||
| 227 | |||||||||||||
| 228 | The digest method returns a hexadecimal formatted digest of a dump of the | ||||||||||||
| 229 | object or return value of a dispatched method call. The algorithm defaults to | ||||||||||||
| 230 | C<SHA-1>. This method supports dispatching, i.e. providing a method name and | ||||||||||||
| 231 | arguments whose return value will be acted on by this method. | ||||||||||||
| 232 | |||||||||||||
| 233 | I<Since C<0.01>> | ||||||||||||
| 234 | |||||||||||||
| 235 | =over 4 | ||||||||||||
| 236 | |||||||||||||
| 237 | =item digest example 1 | ||||||||||||
| 238 | |||||||||||||
| 239 | package main; | ||||||||||||
| 240 | |||||||||||||
| 241 | my $example = Example->new(test => 123); | ||||||||||||
| 242 | |||||||||||||
| 243 | my $digest = $example->digest; | ||||||||||||
| 244 | |||||||||||||
| 245 | # "a6c3d9ae59f31690eddbdd15271e856a6b6f15d5" | ||||||||||||
| 246 | |||||||||||||
| 247 | =back | ||||||||||||
| 248 | |||||||||||||
| 249 | =over 4 | ||||||||||||
| 250 | |||||||||||||
| 251 | =item digest example 2 | ||||||||||||
| 252 | |||||||||||||
| 253 | package main; | ||||||||||||
| 254 | |||||||||||||
| 255 | my $example = Example->new(test => 123); | ||||||||||||
| 256 | |||||||||||||
| 257 | my $digest = $example->digest('sha-1', 'execute'); | ||||||||||||
| 258 | |||||||||||||
| 259 | # "4feada6a2e48d2cb8a0b7569899f1baadd165c4d" | ||||||||||||
| 260 | |||||||||||||
| 261 | =back | ||||||||||||
| 262 | |||||||||||||
| 263 | =over 4 | ||||||||||||
| 264 | |||||||||||||
| 265 | =item digest example 3 | ||||||||||||
| 266 | |||||||||||||
| 267 | package main; | ||||||||||||
| 268 | |||||||||||||
| 269 | my $example = Example->new(test => 123); | ||||||||||||
| 270 | |||||||||||||
| 271 | my $digest = $example->digest('sha-1', 'execute', '456'); | ||||||||||||
| 272 | |||||||||||||
| 273 | # "e557f4efb00ed7599965f6909277ceb737e1ccf7" | ||||||||||||
| 274 | |||||||||||||
| 275 | =back | ||||||||||||
| 276 | |||||||||||||
| 277 | =cut | ||||||||||||
| 278 | |||||||||||||
| 279 | =head2 digester | ||||||||||||
| 280 | |||||||||||||
| 281 | digester(Str $algo, Str $method, Any @args) (Str) | ||||||||||||
| 282 | |||||||||||||
| 283 | The digester method returns a L<Digest> object with a dump of the object or | ||||||||||||
| 284 | return value of a dispatched method call as the message. The algorithm defaults | ||||||||||||
| 285 | to C<SHA-1>. This method supports dispatching, i.e. providing a method name and | ||||||||||||
| 286 | arguments whose return value will be acted on by this method. | ||||||||||||
| 287 | |||||||||||||
| 288 | I<Since C<0.01>> | ||||||||||||
| 289 | |||||||||||||
| 290 | =over 4 | ||||||||||||
| 291 | |||||||||||||
| 292 | =item digester example 1 | ||||||||||||
| 293 | |||||||||||||
| 294 | package main; | ||||||||||||
| 295 | |||||||||||||
| 296 | my $example = Example->new(test => 123); | ||||||||||||
| 297 | |||||||||||||
| 298 | my $digester = $example->digester; | ||||||||||||
| 299 | |||||||||||||
| 300 | # bless(..., "Digest::SHA") | ||||||||||||
| 301 | |||||||||||||
| 302 | =back | ||||||||||||
| 303 | |||||||||||||
| 304 | =over 4 | ||||||||||||
| 305 | |||||||||||||
| 306 | =item digester example 2 | ||||||||||||
| 307 | |||||||||||||
| 308 | package main; | ||||||||||||
| 309 | |||||||||||||
| 310 | my $example = Example->new(test => 123); | ||||||||||||
| 311 | |||||||||||||
| 312 | my $digester = $example->digester('md5'); | ||||||||||||
| 313 | |||||||||||||
| 314 | # bless(..., "Digest::MD5") | ||||||||||||
| 315 | |||||||||||||
| 316 | =back | ||||||||||||
| 317 | |||||||||||||
| 318 | =cut | ||||||||||||
| 319 | |||||||||||||
| 320 | =head2 hexdigest | ||||||||||||
| 321 | |||||||||||||
| 322 | hexdigest(Str $algo, Str $method, Any @args) (Str) | ||||||||||||
| 323 | |||||||||||||
| 324 | The hexdigest method returns a ... formatted digest of the object or return | ||||||||||||
| 325 | value of a dispatched method call. The algorithm defaults to C<SHA-1>. This | ||||||||||||
| 326 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||||
| 327 | return value will be acted on by this method. | ||||||||||||
| 328 | |||||||||||||
| 329 | I<Since C<0.01>> | ||||||||||||
| 330 | |||||||||||||
| 331 | =over 4 | ||||||||||||
| 332 | |||||||||||||
| 333 | =item hexdigest example 1 | ||||||||||||
| 334 | |||||||||||||
| 335 | package main; | ||||||||||||
| 336 | |||||||||||||
| 337 | my $example = Example->new(test => 123); | ||||||||||||
| 338 | |||||||||||||
| 339 | my $hexdigest = $example->hexdigest; | ||||||||||||
| 340 | |||||||||||||
| 341 | # "a6c3d9ae59f31690eddbdd15271e856a6b6f15d5" | ||||||||||||
| 342 | |||||||||||||
| 343 | =back | ||||||||||||
| 344 | |||||||||||||
| 345 | =over 4 | ||||||||||||
| 346 | |||||||||||||
| 347 | =item hexdigest example 2 | ||||||||||||
| 348 | |||||||||||||
| 349 | package main; | ||||||||||||
| 350 | |||||||||||||
| 351 | my $example = Example->new(test => 123); | ||||||||||||
| 352 | |||||||||||||
| 353 | my $hexdigest = $example->hexdigest('sha-1', 'execute'); | ||||||||||||
| 354 | |||||||||||||
| 355 | # "4feada6a2e48d2cb8a0b7569899f1baadd165c4d" | ||||||||||||
| 356 | |||||||||||||
| 357 | =back | ||||||||||||
| 358 | |||||||||||||
| 359 | =over 4 | ||||||||||||
| 360 | |||||||||||||
| 361 | =item hexdigest example 3 | ||||||||||||
| 362 | |||||||||||||
| 363 | package main; | ||||||||||||
| 364 | |||||||||||||
| 365 | my $example = Example->new(test => 123); | ||||||||||||
| 366 | |||||||||||||
| 367 | my $hexdigest = $example->hexdigest('sha-1', 'execute', '456'); | ||||||||||||
| 368 | |||||||||||||
| 369 | # "e557f4efb00ed7599965f6909277ceb737e1ccf7" | ||||||||||||
| 370 | |||||||||||||
| 371 | =back | ||||||||||||
| 372 | |||||||||||||
| 373 | =cut | ||||||||||||