blib/lib/Venus/Role/Digestable.pm

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