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 SCAR 18.0
CC
6
Cov
90%
BUILD
6.2
BEGIN
1.0
BEGIN
1.0
CRAP 6.0
« blib/lib/Venus/Role/Proxyable.pm ↑ Summary blib/lib/Venus/Regexp.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 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
BranchTrueFalseTotal
unless $self->can("defaults") 0 2 2
16  
17 2 my $defaults = $self->defaults;
18  
19 2 ▶ return $self if !$defaults;
Branch: 1 branch
BranchTrueFalseTotal
unless $defaults 0 2 2
20  
21 2 for my $name (@{$self->META->attrs}) {
22 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
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
« blib/lib/Venus/Role/Proxyable.pm ↑ Summary blib/lib/Venus/Regexp.pm »