Venus/Kind.pm

filter: Statementstmt 98.5% 68 / 69 Branchbran 65.0% 13 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 17 / 17 Podpod 88.8% 8 / 9 totaltotal 89.1% 107 / 120 CC 12 SCAR 8.5
CC
12
Cov
89%
comparer
4.0
trap
4.0
type
3.1
CRAP 2.3
« Venus/Vars.pm ↑ Summary Venus/Args.pm »
1 package Venus::Kind;
2  
3 61 ▶use 5.018;
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::Class 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 61 with 'Venus::Role::Boxable';
11 61 with 'Venus::Role::Catchable';
12 61 with 'Venus::Role::Comparable';
13 61 with 'Venus::Role::Digestable';
14 61 with 'Venus::Role::Doable';
15 61 with 'Venus::Role::Dumpable';
16 61 with 'Venus::Role::Matchable';
17 61 with 'Venus::Role::Printable';
18 61 with 'Venus::Role::Testable';
19 61 with 'Venus::Role::Throwable';
20  
21 # METHODS
22  
23 sub class {
24 305 ▶ my ($self) = @_;
Subroutine class: called CC=2 SCAR=8.1
Pod documented
25  
26 305 ▶ return ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
30500
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
27 }
28  
29 sub checksum {
30 346 ▶ my ($self) = @_;
Subroutine checksum: called CC=1 SCAR=0.0
Pod documented
31  
32 346 return $self->digest('md5', 'stringified');
33 }
34  
35 sub comparer {
36 797 ▶ my ($self, $operation) = @_;
Subroutine comparer: called CC=4 SCAR=14.0
Pod undocumented
37  
38 797 ▶ if (lc($operation) eq 'eq') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $operation eq "eq") 516 281 797
39 516 return 'checksum';
40 }
41 281 ▶ if (lc($operation) eq 'gt') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $operation eq "gt") 155 126 281
42 155 return 'numified';
43 }
44 126 ▶ if (lc($operation) eq 'lt') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $operation eq 'lt') { } 126 0 126
45 126 return 'numified';
46 }
47 else {
48 0 return 'stringified';
49 }
50 }
51  
52 sub numified {
53 663 ▶ my ($self) = @_;
Subroutine numified: called CC=1 SCAR=0.0
Pod documented
54  
55 663 return CORE::length($self->stringified);
56 }
57  
58 sub safe {
59 4 ▶ my ($self, $method, @args) = @_;
Subroutine safe: called CC=2 SCAR=7.1
Pod documented
60  
61 4 my $result = $self->trap($method, @args);
62  
63 4 ▶ return(wantarray ? (@$result) : $result->[0]);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
64 }
65  
66 sub space {
67 1 ▶ my ($self) = @_;
Subroutine space: called CC=1 SCAR=0.0
Pod documented
68  
69 1 require Venus::Space;
70  
71 1 return Venus::Space->new($self->class);
72 }
73  
74 sub stringified {
75 1342 ▶ my ($self) = @_;
Subroutine stringified: called CC=2 SCAR=6.9
Pod documented
76  
77 1342 ▶ return $self->dump($self->can('value') ? 'value' : ());
Branch: 1 branch
BranchTrueFalseTotal
$self->can('value') ? : 1328 14 1342
78 }
79  
80 sub trap {
81 10 ▶ my ($self, $method, @args) = @_;
Subroutine trap: called CC=4 SCAR=13.9
Pod documented
82  
83 61 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 61 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 10 my $result = [[],[],[]];
87  
88 10 ▶ return(wantarray ? (@$result) : $result->[0]) if !$method;
Branch: 2 branches
BranchTrueFalseTotal
unless $method 0 10 10
wantarray ? : 0 0 0
89  
90 10 local ($!, $?, $@, $^E);
91  
92 local $SIG{__DIE__} = sub{
93 5 ▶ push @{$result->[2]}, @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
94 10 };
95  
96 local $SIG{__WARN__} = sub{
97 3 ▶ push @{$result->[1]}, @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
98 10 };
99  
100 10 push @{$result->[0]}, eval {
101 10 local $_ = $self;
102 10 $self->$method(@args);
103 };
104  
105 10 ▶ return(wantarray ? (@$result) : $result->[0]);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 7 10
106 }
107  
108 sub type {
109 1 ▶ my ($self, $method, @args) = @_;
Subroutine type: called CC=3 SCAR=11.4
Pod documented
110  
111 1 require Venus::Type;
112  
113 1 ▶ my $value = $method
Branch: 2 branches
BranchTrueFalseTotal
$method ? : 0 1 1
$self->can('value') ? : 0 1 1
114 ? $self->$method(@args) : $self->can('value') ? $self->value : $self;
115  
116 1 return Venus::Type->new(value => $value);
117 }
118  
119 61 1;
120  
121  
122  
123 =head1 NAME
124  
125 Venus::Kind - Kind Base Class
126  
127 =cut
128  
129 =head1 ABSTRACT
130  
131 Kind Base Class for Perl 5
132  
133 =cut
134  
135 =head1 SYNOPSIS
136  
137 package Example;
138  
139 use Venus::Class;
140  
141 base 'Venus::Kind';
142  
143 package main;
144  
145 my $example = Example->new;
146  
147 =cut
148  
149 =head1 DESCRIPTION
150  
151 This package provides identity and methods common across all L<Venus> classes.
152  
153 =cut
154  
155 =head1 INTEGRATES
156  
157 This package integrates behaviors from:
158  
159 L<Venus::Role::Boxable>
160  
161 L<Venus::Role::Catchable>
162  
163 L<Venus::Role::Comparable>
164  
165 L<Venus::Role::Digestable>
166  
167 L<Venus::Role::Doable>
168  
169 L<Venus::Role::Dumpable>
170  
171 L<Venus::Role::Matchable>
172  
173 L<Venus::Role::Printable>
174  
175 L<Venus::Role::Testable>
176  
177 L<Venus::Role::Throwable>
178  
179 =cut
180  
181 =head1 METHODS
182  
183 This package provides the following methods:
184  
185 =cut
186  
187 =head2 checksum
188  
189 checksum() (Str)
190  
191 The checksum method returns an md5 hash string representing the stringified
192 object value (or the object itself).
193  
194 I<Since C<0.08>>
195  
196 =over 4
197  
198 =item checksum example 1
199  
200 # given: synopsis;
201  
202 my $checksum = $example->checksum;
203  
204 # "859a86eed4b2d97eb7b830b02f06de32"
205  
206 =back
207  
208 =over 4
209  
210 =item checksum example 2
211  
212 package Checksum::Example;
213  
214 use Venus::Class;
215  
216 base 'Venus::Kind';
217  
218 attr 'value';
219  
220 package main;
221  
222 my $example = Checksum::Example->new(value => 'example');
223  
224 my $checksum = $example->checksum;
225  
226 # "1a79a4d60de6718e8e5b326e338ae533"
227  
228 =back
229  
230 =cut
231  
232 =head2 class
233  
234 class() (Str)
235  
236 The class method returns the class name for the given class or object.
237  
238 I<Since C<0.01>>
239  
240 =over 4
241  
242 =item class example 1
243  
244 # given: synopsis;
245  
246 my $class = $example->class;
247  
248 # "Example"
249  
250 =back
251  
252 =cut
253  
254 =head2 numified
255  
256 numified() (Int)
257  
258 The numified method returns the numerical representation of the object which is
259 typically the length (or character count) of the stringified object.
260  
261 I<Since C<0.08>>
262  
263 =over 4
264  
265 =item numified example 1
266  
267 # given: synopsis;
268  
269 my $numified = $example->numified;
270  
271 # 22
272  
273 =back
274  
275 =over 4
276  
277 =item numified example 2
278  
279 package Numified::Example;
280  
281 use Venus::Class;
282  
283 base 'Venus::Kind';
284  
285 attr 'value';
286  
287 package main;
288  
289 my $example = Numified::Example->new(value => 'example');
290  
291 my $numified = $example->numified;
292  
293 # 7
294  
295 =back
296  
297 =cut
298  
299 =head2 safe
300  
301 safe(Str | CodeRef $code, Any @args) (Any)
302  
303 The safe method dispatches the method call or executes the callback and returns
304 the result, supressing warnings and exceptions. If an exception is thrown this
305 method will return C<undef>. This method supports dispatching, i.e. providing a
306 method name and arguments whose return value will be acted on by this method.
307  
308 I<Since C<0.08>>
309  
310 =over 4
311  
312 =item safe example 1
313  
314 # given: synopsis;
315  
316 my $safe = $example->safe('class');
317  
318 # "Example"
319  
320 =back
321  
322 =over 4
323  
324 =item safe example 2
325  
326 # given: synopsis;
327  
328 my $safe = $example->safe(sub {
329 ${_}->class / 2
330 });
331  
332 # '0'
333  
334 =back
335  
336 =over 4
337  
338 =item safe example 3
339  
340 # given: synopsis;
341  
342 my $safe = $example->safe(sub {
343 die;
344 });
345  
346 # undef
347  
348 =back
349  
350 =cut
351  
352 =head2 space
353  
354 space() (Space)
355  
356 The space method returns a L<Venus::Space> object for the given object.
357  
358 I<Since C<0.01>>
359  
360 =over 4
361  
362 =item space example 1
363  
364 # given: synopsis;
365  
366 my $space = $example->space;
367  
368 # bless({ value => "Example" }, "Venus::Space")
369  
370 =back
371  
372 =cut
373  
374 =head2 stringified
375  
376 stringified() (Str)
377  
378 The stringified method returns the object, stringified (i.e. a dump of the
379 object's value).
380  
381 I<Since C<0.08>>
382  
383 =over 4
384  
385 =item stringified example 1
386  
387 # given: synopsis;
388  
389 my $stringified = $example->stringified;
390  
391 # bless({}, 'Example')
392  
393  
394  
395  
396 =back
397  
398 =over 4
399  
400 =item stringified example 2
401  
402 package Stringified::Example;
403  
404 use Venus::Class;
405  
406 base 'Venus::Kind';
407  
408 attr 'value';
409  
410 package main;
411  
412 my $example = Stringified::Example->new(value => 'example');
413  
414 my $stringified = $example->stringified;
415  
416 # "example"
417  
418 =back
419  
420 =cut
421  
422 =head2 trap
423  
424 trap(Str | CodeRef $code, Any @args) (Tuple[ArrayRef, ArrayRef, ArrayRef])
425  
426 The trap method dispatches the method call or executes the callback and returns
427 a tuple (i.e. a 3-element arrayref) with the results, warnings, and exceptions
428 from the code execution. If an exception is thrown, the results (i.e. the
429 1st-element) will be an empty arrayref. This method supports dispatching, i.e.
430 providing a method name and arguments whose return value will be acted on by
431 this method.
432  
433 I<Since C<0.08>>
434  
435 =over 4
436  
437 =item trap example 1
438  
439 # given: synopsis;
440  
441 my $result = $example->trap('class');
442  
443 # ["Example"]
444  
445 =back
446  
447 =over 4
448  
449 =item trap example 2
450  
451 # given: synopsis;
452  
453 my ($results, $warnings, $errors) = $example->trap('class');
454  
455 # (["Example"], [], [])
456  
457 =back
458  
459 =over 4
460  
461 =item trap example 3
462  
463 # given: synopsis;
464  
465 my $trap = $example->trap(sub {
466 ${_}->class / 2
467 });
468  
469 # ["0"]
470  
471 =back
472  
473 =over 4
474  
475 =item trap example 4
476  
477 # given: synopsis;
478  
479 my ($results, $warnings, $errors) = $example->trap(sub {
480 ${_}->class / 2
481 });
482  
483 # (["0"], ["Argument ... isn't numeric in division ..."], [])
484  
485 =back
486  
487 =over 4
488  
489 =item trap example 5
490  
491 # given: synopsis;
492  
493 my $trap = $example->trap(sub {
494 die;
495 });
496  
497 # []
498  
499 =back
500  
501 =over 4
502  
503 =item trap example 6
504  
505 # given: synopsis;
506  
507 my ($results, $warnings, $errors) = $example->trap(sub {
508 die;
509 });
510  
511 # ([], [], ["Died..."])
512  
513 =back
514  
515 =cut
516  
517 =head2 type
518  
519 type() (Type)
520  
521 The type method returns a L<Venus::Type> object for the given object.
522  
523 I<Since C<0.01>>
524  
525 =over 4
526  
527 =item type example 1
528  
529 # given: synopsis;
530  
531 my $type = $example->type;
532  
533 # bless({ value => bless({}, "Example") }, "Venus::Type")
534  
535 =back
536  
537 =cut
« Venus/Vars.pm ↑ Summary Venus/Args.pm »