blib/lib/Venus/Kind/Value.pm

filter: Statementstmt 94.4% 34 / 36 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 66.6% 4 / 6 totaltotal 89.4% 51 / 57 SCAR 11.0
CC
3
Cov
92%
cast
2.0
defined
2.0
TO_JSON
2.0
CRAP 3.0
« blib/lib/Venus/Role/Unacceptable.pm ↑ Summary blib/lib/Venus/Role/Deferrable.pm »
1 package Venus::Kind::Value;
2  
3 33 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 use overload (
9 33 '""' => 'explain',
10 '~~' => 'explain',
11 fallback => 1,
12 33 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 33 ▶use Venus::Class 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 33 base 'Venus::Kind';
17  
18 33 with 'Venus::Role::Valuable';
19 33 with 'Venus::Role::Buildable';
20 33 with 'Venus::Role::Accessible';
21 33 with 'Venus::Role::Explainable';
22 33 with 'Venus::Role::Proxyable';
23 33 with 'Venus::Role::Pluggable';
24  
25 # BUILDERS
26  
27 sub build_arg {
28 722 ▶ my ($self, $data) = @_;
Subroutine build_arg: called CC=1 SCAR=0.0
Pod undocumented
29  
30 return {
31 722 value => $data,
32 };
33 }
34  
35 # METHODS
36  
37 sub cast {
38 103 ▶ my ($self, @args) = @_;
Subroutine cast: called CC=2 SCAR=7.0
Pod documented
39  
40 103 require Venus::Type;
41  
42 103 ▶ my $value = $self->can('value') ? $self->value : $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->can('value') ? : 103 0 103
43  
44 103 return Venus::Type->new(value => $value)->cast(@args);
45 }
46  
47 sub defined {
48 2 ▶ my ($self) = @_;
Subroutine defined: called CC=2 SCAR=6.9
Pod documented
49  
50 2 ▶ return CORE::defined($self->get) ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->get ? : 1 1 2
51 }
52  
53 sub explain {
54 506 ▶ my ($self) = @_;
Subroutine explain: called CC=1 SCAR=0.0
Pod documented
55  
56 506 return $self->get;
57 }
58  
59 sub mutate {
60 2 ▶ my ($self, $code, @args) = @_;
Subroutine mutate: called CC=1 SCAR=0.0
Pod documented
61  
62 2 return $self->set($self->$code(@args));
63 }
64  
65 sub TO_JSON {
66 0 ▶ my ($self) = @_;
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
67  
68 0 return $self->get;
69 }
70  
71 33 1;
72  
73  
74  
75 =head1 NAME
76  
77 Venus::Kind::Value - Value Base Class
78  
79 =cut
80  
81 =head1 ABSTRACT
82  
83 Value Base Class for Perl 5
84  
85 =cut
86  
87 =head1 SYNOPSIS
88  
89 package Example;
90  
91 use Venus::Class;
92  
93 base 'Venus::Kind::Value';
94  
95 sub test {
96 $_[0]->get + 1
97 }
98  
99 package main;
100  
101 my $example = Example->new(1);
102  
103 # $example->defined;
104  
105 =cut
106  
107 =head1 DESCRIPTION
108  
109 This package provides identity and methods common across all L<Venus> value
110 classes.
111  
112 =cut
113  
114 =head1 INHERITS
115  
116 This package inherits behaviors from:
117  
118 L<Venus::Kind>
119  
120 =cut
121  
122 =head1 INTEGRATES
123  
124 This package integrates behaviors from:
125  
126 L<Venus::Role::Accessible>
127  
128 L<Venus::Role::Buildable>
129  
130 L<Venus::Role::Explainable>
131  
132 L<Venus::Role::Pluggable>
133  
134 L<Venus::Role::Proxyable>
135  
136 L<Venus::Role::Valuable>
137  
138 =cut
139  
140 =head1 METHODS
141  
142 This package provides the following methods:
143  
144 =cut
145  
146 =head2 cast
147  
148 cast(string $kind) (object | undef)
149  
150 The cast method converts L<"value"|Venus::Kind::Value> objects between
151 different I<"value"> object types, based on the name of the type provided. This
152 method will return C<undef> if the invocant is not a L<Venus::Kind::Value>.
153  
154 I<Since C<0.08>>
155  
156 =over 4
157  
158 =item cast example 1
159  
160 package main;
161  
162 my $example = Example->new;
163  
164 my $cast = $example->cast;
165  
166 # bless({value => undef}, "Venus::Undef")
167  
168 =back
169  
170 =over 4
171  
172 =item cast example 2
173  
174 package main;
175  
176 my $example = Example->new(
177 value => 123.45,
178 );
179  
180 my $cast = $example->cast('array');
181  
182 # bless({value => [123.45]}, "Venus::Array")
183  
184 =back
185  
186 =over 4
187  
188 =item cast example 3
189  
190 package main;
191  
192 my $example = Example->new(
193 value => 123.45,
194 );
195  
196 my $cast = $example->cast('hash');
197  
198 # bless({value => {'123.45' => 123.45}, "Venus::Hash")
199  
200 =back
201  
202 =cut
203  
204 =head2 defined
205  
206 defined() (number)
207  
208 The defined method returns truthy or falsy if the underlying value is
209 L</defined>.
210  
211 I<Since C<0.01>>
212  
213 =over 4
214  
215 =item defined example 1
216  
217 package main;
218  
219 my $example = Example->new;
220  
221 my $defined = $example->defined;
222  
223 # 0
224  
225 =back
226  
227 =over 4
228  
229 =item defined example 2
230  
231 package main;
232  
233 my $example = Example->new(time);
234  
235 my $defined = $example->defined;
236  
237 # 1
238  
239 =back
240  
241 =cut
242  
243 =head2 explain
244  
245 explain() (any)
246  
247 The explain method returns the value set and is used in stringification
248 operations.
249  
250 I<Since C<0.01>>
251  
252 =over 4
253  
254 =item explain example 1
255  
256 package main;
257  
258 my $example = Example->new('hello, there');
259  
260 my $explain = $example->explain;
261  
262 # "hello, there"
263  
264 =back
265  
266 =cut
267  
268 =head2 mutate
269  
270 mutate(string | coderef $code, any @args) (object)
271  
272 The mutate method dispatches the method call or executes the callback and
273 returns the result, which if is of the same type as the invocant's underlying
274 data type will update the object's internal state or will throw an exception.
275  
276 I<Since C<1.23>>
277  
278 =over 4
279  
280 =item mutate example 1
281  
282 # given: synopsis
283  
284 package main;
285  
286 $example->mutate('test');
287  
288 $example;
289  
290 # bless({value => 2}, "Example")
291  
292 =back
293  
294 =cut
295  
296 =head1 AUTHORS
297  
298 Awncorp, C<awncorp@cpan.org>
299  
300 =cut
301  
302 =head1 LICENSE
303  
304 Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>.
305  
306 This program is free software, you can redistribute it and/or modify it under
307 the terms of the Apache license version 2.0.
308  
309 =cut
« blib/lib/Venus/Role/Unacceptable.pm ↑ Summary blib/lib/Venus/Role/Deferrable.pm »