blib/lib/Venus/Role/Mappable.pm

filter: Statementstmt 64.7% 33 / 51 Branchbran 50.0% 18 / 36 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 58.1% 57 / 98 SCAR 39.1
CC
20
Cov
58%
AUDIT
66.3
BEGIN
1.0
BEGIN
1.0
CRAP 50.1
« blib/lib/Venus/Prototype.pm ↑ Summary blib/lib/Venus/Os.pm »
1 package Venus::Role::Mappable;
2  
3 21 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 21 ▶use Venus::Role 'fault';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # AUDIT
11  
12 sub AUDIT {
13 35 ▶ my ($self, $from) = @_;
Subroutine AUDIT: called CC=20 SCAR=41.9
Pod undocumented
14  
15 35 ▶ my $name = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
0350
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
16  
17 35 ▶ if (!$from->can('all')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("all")) 0 35 35
18 0 fault "${from} requires 'all' to consume ${name}";
19 }
20  
21 35 ▶ if (!$from->can('any')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("any")) 0 35 35
22 0 fault "${from} requires 'any' to consume ${name}";
23 }
24  
25 35 ▶ if (!$from->can('call')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("call")) 0 35 35
26 0 fault "${from} requires 'call' to consume ${name}";
27 }
28  
29 35 ▶ if (!$from->can('count')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("count")) 0 35 35
30 0 fault "${from} requires 'count' to consume ${name}";
31 }
32  
33 35 ▶ if (!$from->can('delete')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("delete")) 0 35 35
34 0 fault "${from} requires 'delete' to consume ${name}";
35 }
36  
37 35 ▶ if (!$from->can('each')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("each")) 0 35 35
38 0 fault "${from} requires 'each' to consume ${name}";
39 }
40  
41 35 ▶ if (!$from->can('empty')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("empty")) 0 35 35
42 0 fault "${from} requires 'empty' to consume ${name}";
43 }
44  
45 35 ▶ if (!$from->can('exists')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("exists")) 0 35 35
46 0 fault "${from} requires 'exists' to consume ${name}";
47 }
48  
49 35 ▶ if (!$from->can('grep')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("grep")) 0 35 35
50 0 fault "${from} requires 'grep' to consume ${name}";
51 }
52  
53 35 ▶ if (!$from->can('iterator')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("iterator")) 0 35 35
54 0 fault "${from} requires 'iterator' to consume ${name}";
55 }
56  
57 35 ▶ if (!$from->can('keys')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("keys")) 0 35 35
58 0 fault "${from} requires 'keys' to consume ${name}";
59 }
60  
61 35 ▶ if (!$from->can('map')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("map")) 0 35 35
62 0 fault "${from} requires 'map' to consume ${name}";
63 }
64  
65 35 ▶ if (!$from->can('none')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("none")) 0 35 35
66 0 fault "${from} requires 'none' to consume ${name}";
67 }
68  
69 35 ▶ if (!$from->can('one')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("one")) 0 35 35
70 0 fault "${from} requires 'one' to consume ${name}";
71 }
72  
73 35 ▶ if (!$from->can('pairs')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("pairs")) 0 35 35
74 0 fault "${from} requires 'pairs' to consume ${name}";
75 }
76  
77 35 ▶ if (!$from->can('random')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("random")) 0 35 35
78 0 fault "${from} requires 'random' to consume ${name}";
79 }
80  
81 35 ▶ if (!$from->can('reverse')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("reverse")) 0 35 35
82 0 fault "${from} requires 'reverse' to consume ${name}";
83 }
84  
85 35 ▶ if (!$from->can('slice')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->can("slice")) 0 35 35
86 0 fault "${from} requires 'slice' to consume ${name}";
87 }
88  
89 35 return $self;
90 }
91  
92 21 1;
93  
94  
95  
96 =head1 NAME
97  
98 Venus::Role::Mappable - Mappable Role
99  
100 =cut
101  
102 =head1 ABSTRACT
103  
104 Mappable Role for Perl 5
105  
106 =cut
107  
108 =head1 SYNOPSIS
109  
110 package Example;
111  
112 use Venus::Class;
113  
114 with 'Venus::Role::Mappable';
115  
116 sub all;
117 sub any;
118 sub call;
119 sub count;
120 sub delete;
121 sub each;
122 sub empty;
123 sub exists;
124 sub grep;
125 sub iterator;
126 sub keys;
127 sub map;
128 sub none;
129 sub one;
130 sub pairs;
131 sub random;
132 sub reverse;
133 sub slice;
134  
135 package main;
136  
137 my $example = Example->new;
138  
139 # $example->random;
140  
141 =cut
142  
143 =head1 DESCRIPTION
144  
145 This package provides a specification for the consuming package to implement
146 methods that makes the object mappable. See L<Venus::Array> and L<Venus::Hash>
147 as other examples of mappable classes.
148  
149 =cut
150  
151 =head1 METHODS
152  
153 This package provides the following methods:
154  
155 =cut
156  
157 =head2 all
158  
159 all(coderef $code) (boolean)
160  
161 The all method should return true if the callback returns true for all of the
162 elements provided.
163  
164 I<Since C<0.01>>
165  
166 =over 4
167  
168 =item all example 1
169  
170 # given: synopsis;
171  
172 my $all = $example->all(sub {
173 # ...
174 });
175  
176 =back
177  
178 =cut
179  
180 =head2 any
181  
182 any(coderef $code) (boolean)
183  
184 The any method should return true if the callback returns true for any of the
185 elements provided.
186  
187  
188  
189  
190 I<Since C<0.01>>
191  
192 =over 4
193  
194 =item any example 1
195  
196 # given: synopsis;
197  
198 my $any = $example->any(sub {
199 # ...
200 });
201  
202 =back
203  
204 =cut
205  
206 =head2 count
207  
208 count() (number)
209  
210 The count method should return the number of top-level element in the data
211 structure.
212  
213  
214  
215  
216 I<Since C<0.01>>
217  
218 =over 4
219  
220 =item count example 1
221  
222 # given: synopsis;
223  
224 my $count = $example->count;
225  
226 =back
227  
228 =cut
229  
230 =head2 delete
231  
232 delete(string $key) (any)
233  
234 The delete method returns should remove the item in the data structure based on
235 the key provided, returning the item.
236  
237  
238  
239  
240 I<Since C<0.01>>
241  
242 =over 4
243  
244 =item delete example 1
245  
246 # given: synopsis;
247  
248 my $delete = $example->delete(...);
249  
250 =back
251  
252 =cut
253  
254 =head2 each
255  
256 each(coderef $code) (arrayref)
257  
258 The each method should execute the callback for each item in the data structure
259 passing the key and value as arguments.
260  
261  
262  
263  
264 I<Since C<0.01>>
265  
266 =over 4
267  
268 =item each example 1
269  
270 # given: synopsis;
271  
272 my $results = $example->each(sub {
273 # ...
274 });
275  
276 =back
277  
278 =cut
279  
280 =head2 empty
281  
282 empty() (Value)
283  
284 The empty method should drop all items from the data structure.
285  
286  
287  
288  
289 I<Since C<0.01>>
290  
291 =over 4
292  
293 =item empty example 1
294  
295 # given: synopsis;
296  
297 my $empty = $example->empty;
298  
299 =back
300  
301 =cut
302  
303 =head2 exists
304  
305 exists(string $key) (boolean)
306  
307 The exists method should return true if the item at the key specified exists,
308 otherwise it returns false.
309  
310  
311  
312  
313 I<Since C<0.01>>
314  
315 =over 4
316  
317 =item exists example 1
318  
319 # given: synopsis;
320  
321 my $exists = $example->exists(...);
322  
323 =back
324  
325 =cut
326  
327 =head2 grep
328  
329 grep(coderef $code) (arrayref)
330  
331 The grep method should execute a callback for each item in the array, passing
332 the value as an argument, returning a value containing the items for which the
333 returned true.
334  
335  
336  
337  
338 I<Since C<0.01>>
339  
340 =over 4
341  
342 =item grep example 1
343  
344 # given: synopsis;
345  
346 my $results = $example->grep(sub {
347 # ...
348 });
349  
350 =back
351  
352 =cut
353  
354 =head2 iterator
355  
356 iterator() (coderef)
357  
358 The iterator method should return a code reference which can be used to iterate
359 over the data structure. Each time the iterator is executed it will return the
360 next item in the data structure until all items have been seen, at which point
361 the iterator will return an undefined value.
362  
363  
364  
365  
366 I<Since C<0.01>>
367  
368 =over 4
369  
370 =item iterator example 1
371  
372 # given: synopsis;
373  
374 my $iterator = $example->iterator;
375  
376 =back
377  
378 =cut
379  
380 =head2 keys
381  
382 keys() (arrayref)
383  
384 The keys method should return an array reference consisting of the keys of the
385 data structure.
386  
387  
388  
389  
390 I<Since C<0.01>>
391  
392 =over 4
393  
394 =item keys example 1
395  
396 # given: synopsis;
397  
398 my $keys = $example->keys;
399  
400 =back
401  
402 =cut
403  
404 =head2 map
405  
406 map(coderef $code) (arrayref)
407  
408 The map method should iterate over each item in the data structure, executing
409 the code reference supplied in the argument, passing the routine the value at
410 the current position in the loop and returning an array reference containing
411 the items for which the argument returns a value or non-empty list.
412  
413  
414  
415  
416 I<Since C<0.01>>
417  
418 =over 4
419  
420 =item map example 1
421  
422 # given: synopsis;
423  
424 my $results = $example->map(sub {
425 # ...
426 });
427  
428 =back
429  
430 =cut
431  
432 =head2 none
433  
434 none(coderef $code) (boolean)
435  
436 The none method should return true if none of the items in the data structure
437 meet the criteria set by the operand and rvalue.
438  
439  
440  
441  
442 I<Since C<0.01>>
443  
444 =over 4
445  
446 =item none example 1
447  
448 # given: synopsis;
449  
450 my $none = $example->none(sub {
451 # ...
452 });
453  
454 =back
455  
456 =cut
457  
458 =head2 one
459  
460 one(coderef $code) (boolean)
461  
462 The one method should return true if only one of the items in the data
463 structure meet the criteria set by the operand and rvalue.
464  
465  
466  
467  
468 I<Since C<0.01>>
469  
470 =over 4
471  
472 =item one example 1
473  
474 # given: synopsis;
475  
476 my $one = $example->one(sub {
477 # ...
478 });
479  
480 =back
481  
482 =cut
483  
484 =head2 pairs
485  
486 pairs(coderef $code) (tuple[arrayref, arrayref])
487  
488 The pairs method should return an array reference of tuples where each tuple is
489 an array reference having two items corresponding to the key and value for each
490 item in the data structure.
491  
492  
493  
494  
495 I<Since C<0.01>>
496  
497 =over 4
498  
499 =item pairs example 1
500  
501 # given: synopsis;
502  
503 my $pairs = $example->pairs(sub {
504 # ...
505 });
506  
507 =back
508  
509 =cut
510  
511 =head2 random
512  
513 random() (any)
514  
515 The random method should return a random item from the data structure.
516  
517  
518  
519  
520 I<Since C<0.01>>
521  
522 =over 4
523  
524 =item random example 1
525  
526 # given: synopsis;
527  
528 my $random = $example->random;
529  
530 =back
531  
532 =cut
533  
534 =head2 reverse
535  
536 reverse() (arrayref)
537  
538 The reverse method should returns an array reference containing the items in
539 the data structure in reverse order if the items in the data structure are
540 ordered.
541  
542  
543  
544  
545 I<Since C<0.01>>
546  
547 =over 4
548  
549 =item reverse example 1
550  
551 # given: synopsis;
552  
553 my $reverse = $example->reverse;
554  
555 =back
556  
557 =cut
558  
559 =head2 slice
560  
561 slice(string @keys) (arrayref)
562  
563 The slice method should return a new data structure containing the elements in
564 the invocant at the key(s) specified in the arguments.
565  
566  
567  
568  
569 I<Since C<0.01>>
570  
571 =over 4
572  
573 =item slice example 1
574  
575 # given: synopsis;
576  
577 my $slice = $example->slice(...);
578  
579 =back
580  
581 =cut
582  
583 =head1 AUTHORS
584  
585 Awncorp, C<awncorp@cpan.org>
586  
587 =cut
588  
589 =head1 LICENSE
590  
591 Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>.
592  
593 This program is free software, you can redistribute it and/or modify it under
594 the terms of the Apache license version 2.0.
595  
596 =cut
« blib/lib/Venus/Prototype.pm ↑ Summary blib/lib/Venus/Os.pm »