Venus/Kind/Value.pm

filter: Statementstmt 93.5% 29 / 31 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 75.0% 3 / 4 totaltotal 89.1% 41 / 46 CC 2 SCAR 2.7
CC
2
Cov
91%
cast
2.0
TO_JSON
2.0
BEGIN
1.0
CRAP 1.3
« Venus/Role/Throwable.pm ↑ Summary Venus/Role/Doable.pm »
1 package Venus::Kind::Value;
2  
3 25 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 use overload (
9 25 '""' => 'explain',
10 '~~' => 'explain',
11 fallback => 1,
12 25 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 25 ▶use Venus::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 25 base 'Venus::Kind';
17  
18 25 with 'Venus::Role::Buildable';
19 25 with 'Venus::Role::Accessible';
20 25 with 'Venus::Role::Explainable';
21 25 with 'Venus::Role::Pluggable';
22 25 with 'Venus::Role::Valuable';
23  
24 # METHODS
25  
26 sub cast {
27 103 ▶ my ($self, @args) = @_;
Subroutine cast: called CC=2 SCAR=7.0
Pod documented
28  
29 103 require Venus::Type;
30  
31 103 ▶ my $value = $self->can('value') ? $self->value : $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->can('value') ? : 103 0 103
32  
33 103 return Venus::Type->new(value => $value)->cast(@args);
34 }
35  
36 sub defined {
37 2 ▶ my ($self) = @_;
Subroutine defined: called CC=1 SCAR=0.0
Pod documented
38  
39 2 return int(CORE::defined($self->get));
40 }
41  
42 sub explain {
43 285 ▶ my ($self) = @_;
Subroutine explain: called CC=1 SCAR=0.0
Pod documented
44  
45 285 return $self->get;
46 }
47  
48 sub TO_JSON {
49 0 ▶ my ($self) = @_;
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
50  
51 0 return $self->get;
52 }
53  
54 25 1;
55  
56  
57  
58 =head1 NAME
59  
60 Venus::Kind::Value - Value Base Class
61  
62 =cut
63  
64 =head1 ABSTRACT
65  
66 Value Base Class for Perl 5
67  
68 =cut
69  
70 =head1 SYNOPSIS
71  
72 package Example;
73  
74 use Venus::Class;
75  
76 base 'Venus::Kind::Value';
77  
78 package main;
79  
80 my $example = Example->new;
81  
82 # $example->defined;
83  
84 =cut
85  
86 =head1 DESCRIPTION
87  
88 This package provides identity and methods common across all L<Venus> value
89 classes.
90  
91 =cut
92  
93 =head1 INHERITS
94  
95 This package inherits behaviors from:
96  
97 L<Venus::Kind>
98  
99 =cut
100  
101 =head1 INTEGRATES
102  
103 This package integrates behaviors from:
104  
105 L<Venus::Role::Accessible>
106  
107 L<Venus::Role::Buildable>
108  
109 L<Venus::Role::Explainable>
110  
111 L<Venus::Role::Pluggable>
112  
113 L<Venus::Role::Valuable>
114  
115 =cut
116  
117 =head1 METHODS
118  
119 This package provides the following methods:
120  
121 =cut
122  
123 =head2 cast
124  
125 cast(Str $kind) (Object | Undef)
126  
127 The cast method converts L<"value"|Venus::Kind::Value> objects between
128 different I<"value"> object types, based on the name of the type provided. This
129 method will return C<undef> if the invocant is not a L<Venus::Kind::Value>.
130  
131 I<Since C<0.08>>
132  
133 =over 4
134  
135 =item cast example 1
136  
137 package main;
138  
139 my $example = Example->new;
140  
141 my $cast = $example->cast;
142  
143 # bless({value => undef}, "Venus::Undef")
144  
145 =back
146  
147 =over 4
148  
149 =item cast example 2
150  
151 package main;
152  
153 my $example = Example->new(
154 value => 123.45,
155 );
156  
157 my $cast = $example->cast('array');
158  
159 # bless({value => [123.45]}, "Venus::Array")
160  
161 =back
162  
163 =over 4
164  
165 =item cast example 3
166  
167 package main;
168  
169 my $example = Example->new(
170 value => 123.45,
171 );
172  
173 my $cast = $example->cast('hash');
174  
175 # bless({value => {'123.45' => 123.45}, "Venus::Hash")
176  
177 =back
178  
179 =cut
180  
181 =head2 defined
182  
183 defined() (Int)
184  
185 The defined method returns truthy or falsy if the underlying value is
186 L</defined>.
187  
188 I<Since C<0.01>>
189  
190 =over 4
191  
192 =item defined example 1
193  
194 package main;
195  
196 my $example = Example->new;
197  
198 my $defined = $example->defined;
199  
200 # 0
201  
202 =back
203  
204 =over 4
205  
206 =item defined example 2
207  
208 package main;
209  
210 my $example = Example->new(time);
211  
212 my $defined = $example->defined;
213  
214 # 1
215  
216 =back
217  
218 =cut
219  
220 =head2 explain
221  
222 explain() (Any)
223  
224 The explain method returns the value set and is used in stringification
225 operations.
226  
227 I<Since C<0.01>>
228  
229 =over 4
230  
231 =item explain example 1
232  
233 package main;
234  
235 my $example = Example->new('hello, there');
236  
237 my $explain = $example->explain;
238  
239 # "hello, there"
240  
241 =back
242  
243 =cut
« Venus/Role/Throwable.pm ↑ Summary Venus/Role/Doable.pm »