blib/lib/Venus/Role/Valuable.pm

filter: Statementstmt 100% 21 / 21 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 60.0% 3 / 5 totaltotal 94.5% 35 / 37 CC 2 SCAR 1.8
CC
2
Cov
100%
BUILD
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/Venus/Role/Mockable.pm ↑ Summary blib/lib/Venus/Code.pm »
1 package Venus::Role::Valuable;
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::Role 'attr';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ATTRIBUTES
13  
14 119 attr 'value';
15  
16 # BUILDERS
17  
18 31544 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
19 31544 my ($self, $data) = @_;
20  
21 31544 ▶ $self->value($self->default) if !exists $data->{value};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $data->{"value"} 1724 29820 31544
22 }
23  
24 # METHODS
25  
26 34 ▶sub default {
Subroutine default: called CC=1 SCAR=0.0
Pod documented
27  
28 34 return;
29 }
30  
31 41602 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
32 41602 my ($self) = @_;
33  
34 41602 return $self->value;
35 }
36  
37 136 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod documented
38 136 my ($self, $value) = @_;
39  
40 136 return $self->value($value);
41 }
42  
43 # EXPORTS
44  
45 394 ▶sub EXPORT {
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod undocumented
46 394 ['default', 'get', 'set', 'value']
47 }
48  
49 119 1;
50  
51  
52  
53 =head1 NAME
54  
55 Venus::Role::Valuable - Valuable Role
56  
57 =cut
58  
59 =head1 ABSTRACT
60  
61 Valuable Role for Perl 5
62  
63 =cut
64  
65 =head1 SYNOPSIS
66  
67 package Example;
68  
69 use Venus::Class;
70  
71 with 'Venus::Role::Valuable';
72  
73 package main;
74  
75 my $example = Example->new;
76  
77 # $example->value;
78  
79 =cut
80  
81 =head1 DESCRIPTION
82  
83 This package modifies the consuming package and provides a C<value> attribute
84 which defaults to what's returned by the C<default> method, as well as C<get>
85 and C<set> methods for modifying the value.
86  
87 =cut
88  
89 =head1 ATTRIBUTES
90  
91 This package has the following attributes:
92  
93 =cut
94  
95 =head2 value
96  
97 value(Any)
98  
99 This attribute is read-write, accepts C<(Any)> values, and is optional.
100  
101 =cut
102  
103 =head1 METHODS
104  
105 This package provides the following methods:
106  
107 =cut
108  
109 =head2 default
110  
111 default() (any)
112  
113 The default method returns the default value, i.e. C<undef>.
114  
115 I<Since C<0.01>>
116  
117 =over 4
118  
119 =item default example 1
120  
121 package main;
122  
123 my $example = Example->new;
124  
125 my $default = $example->default;
126  
127 # undef
128  
129 =back
130  
131 =cut
132  
133 =head2 get
134  
135 get() (any)
136  
137 The get method gets and returns the value.
138  
139 I<Since C<0.01>>
140  
141 =over 4
142  
143 =item get example 1
144  
145 package main;
146  
147 my $example = Example->new(value => 'hey, there');
148  
149 my $get = $example->get;
150  
151 # "hey, there"
152  
153 =back
154  
155 =cut
156  
157 =head2 set
158  
159 set(any $value) (any)
160  
161 The set method set the value and returns the value set.
162  
163 I<Since C<0.01>>
164  
165 =over 4
166  
167 =item set example 1
168  
169 package main;
170  
171 my $example = Example->new(value => 'hey, there');
172  
173 my $set = $example->set('hi, there');
174  
175 # "hi, there"
176  
177 =back
178  
179 =cut
180  
181 =head1 AUTHORS
182  
183 Awncorp, C<awncorp@cpan.org>
184  
185 =cut
186  
187 =head1 LICENSE
188  
189 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
190  
191 This program is free software, you can redistribute it and/or modify it under
192 the terms of the Apache license version 2.0.
193  
194 =cut
« blib/lib/Venus/Role/Mockable.pm ↑ Summary blib/lib/Venus/Code.pm »