| 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 | 1 | ▶ | use Venus::Role 'with'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # BUILDERS | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | sub BUILD { | ||||||||||||||||||||||||||||
| 13 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | return $self if !$self->can('defaults'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | my $defaults = $self->defaults; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | return $self if !$defaults; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | for my $name (@{$self->META->attrs}) { | |||||||||||||||||||||||||||
| 22 | 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}
| |||||||||||||||||||||||||||||
| 23 | 1 | $self->{$name} = $defaults->{$name}; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | return $self; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | 1; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 NAME | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | Venus::Role::Defaultable - Defaultable Role | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 ABSTRACT | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Defaultable Role for Perl 5 | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | package Example; | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | use Venus::Class 'attr', 'with'; | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | with 'Venus::Role::Defaultable'; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | attr 'name'; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub defaults { | ||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||
| 58 | name => 'example', | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | package main; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | my $example = Example->new; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # bless({name => 'example'}, "Example") | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | This package provides a mechanism for setting default values for missing | ||||||||||||||||||||||||||||
| 73 | constructor arguments. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Awncorp, C<awncorp@cpan.org> | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 88 | the terms of the Apache license version 2.0. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||