blib/lib/Venus/Kind.pm

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