blib/lib/Venus/Role/Defaultable.pm

filter: Statementstmt 100% 21 / 21 Branchbran 66.6% 4 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 86.8% 33 / 38 CC 6 SCAR 14.1
CC
6
Cov
90%
BUILD
6.2
BEGIN
1.0
BEGIN
1.0
CRAP 4.1
« blib/lib/Venus/Try.pm ↑ Summary blib/lib/Venus/String.pm »
1 package Venus::Role::Defaultable;
2  
3 1 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 1 ▶use Venus::Role 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # BUILDERS
13  
14 2 ▶sub BUILD {
Subroutine BUILD: called CC=6 SCAR=18.2
Pod undocumented
15 2 my ($self) = @_;
16  
17 2 ▶ return $self if !$self->can('defaults');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can("defaults") 0 2 2
18  
19 2 my $defaults = $self->defaults;
20  
21 2 ▶ return $self if !$defaults;
Branch: 1 branch
BranchTrueFalseTotal
unless $defaults 0 2 2
22  
23 2 for my $name (@{$self->META->attrs}) {
24 2 ▶ if (exists $defaults->{$name} && !exists $self->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $defaults->{$name} and not exists $self->{$name}) 1 1 2
Condition66%2/3
exists $defaults->{$name} and not exists $self->{$name}
!ll&&!rl&&r
011
MC/DC50%1/2
exists $defaults->{$name} and not exists $self->{$name}
exists $defaults->{$name} not exists $self->{$name}
Truth table66%2/3
A and not(B)
A= exists $defaults->{$name}B= not exists $self->{$name}
ABresult
0X0
100
111
25 1 $self->{$name} = $defaults->{$name};
26 }
27 }
28  
29 2 return $self;
30 }
31  
32 1 1;
33  
34  
35  
36 =head1 NAME
37  
38 Venus::Role::Defaultable - Defaultable Role
39  
40 =cut
41  
42 =head1 ABSTRACT
43  
44 Defaultable Role for Perl 5
45  
46 =cut
47  
48 =head1 SYNOPSIS
49  
50 package Example;
51  
52 use Venus::Class 'attr', 'with';
53  
54 with 'Venus::Role::Defaultable';
55  
56 attr 'name';
57  
58 sub defaults {
59 {
60 name => 'example',
61 }
62 }
63  
64 package main;
65  
66 my $example = Example->new;
67  
68 # bless({name => 'example'}, "Example")
69  
70 =cut
71  
72 =head1 DESCRIPTION
73  
74 This package provides a mechanism for setting default values for missing
75 constructor arguments.
76  
77 =cut
78  
79 =head1 AUTHORS
80  
81 Awncorp, C<awncorp@cpan.org>
82  
83 =cut
84  
85 =head1 LICENSE
86  
87 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
88  
89 This program is free software, you can redistribute it and/or modify it under
90 the terms of the Apache license version 2.0.
91  
92 =cut
« blib/lib/Venus/Try.pm ↑ Summary blib/lib/Venus/String.pm »