Venus/Role/Mappable.pm

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