| 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
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | my $defaults = $self->defaults; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | return $self if !$defaults; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | for my $name (@{$self->META->attrs}) { | |||||||||||||||||||||||||||
| 24 | 2 | ▶ | if (exists $defaults->{$name} && !exists $self->{$name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $defaults->{$name} and not exists $self->{$name}
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}
| |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||