blib/lib/Venus/Atom.pm

filter: Statementstmt 94.4% 34 / 36 Branchbran 75.0% 3 / 4 Conditioncond 50.0% 7 / 14 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 1 totaltotal 77.3% 58 / 75 CC 9 SCAR 11.3
CC
9
Cov
81%
__set
6.6
__ANON__
6.0
__ANON__
2.1
CRAP 3.1
« blib/lib/Venus/Opts.pm ↑ Summary blib/lib/Venus/Role/Testable.pm »
1 package Venus::Atom;
2  
3 2 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 2 ▶use Venus::Class 'base';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INHERITS
13  
14 2 base 'Venus::Sealed';
15  
16 # OVERLOADS
17  
18 2 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.1
19 8 ▶ '""' => sub{$_[0]->get // ''},
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->get // ""
l!l
44
MC/DC100%1/1
$_[0]->get // ""
$_[0]->get
Truth table100%2/2
A
A= $_[0]->get
Aresult
11
00
20 0 ▶ '~~' => sub{$_[0]->get // ''},
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]->get // ""
l!l
00
MC/DC0%0/1
$_[0]->get // ""
$_[0]->get
Truth table0%0/2
A
A= $_[0]->get
Aresult
11
00
21 2 ▶ 'eq' => sub{($_[0]->get // '') eq "$_[1]"},
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]->get // ""
l!l
02
MC/DC0%0/1
$_[0]->get // ""
$_[0]->get
Truth table50%1/2
A
A= $_[0]->get
Aresult
11
00
22 2 ▶ 'ne' => sub{($_[0]->get // '') ne "$_[1]"},
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->get // ""
l!l
11
MC/DC100%1/1
$_[0]->get // ""
$_[0]->get
Truth table100%2/2
A
A= $_[0]->get
Aresult
11
00
23 1 ▶ 'qr' => sub{qr/@{[quotemeta($_[0])]}/},
Subroutine __ANON__: called CC=1 SCAR=0.0
24 2 fallback => 1,
25 2 );
26  
27 # METHODS
28  
29 15 ▶sub __get {
Subroutine __get: called CC=1 SCAR=0.0
30 15 my ($self, $init, $data) = @_;
31  
32 15 return $init->{value};
33 }
34  
35 6 ▶sub __set {
Subroutine __set: called CC=5 SCAR=18.9
36 6 my ($self, $init, $data, $value) = @_;
37  
38 6 ▶ if (ref $value || !defined $value || $value eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value or not defined $value or $value eq "") 0 6 6
Condition33%2/6
ref $value or not defined $value or $value eq ""
l!l&&r!l&&!r
006
ref $value or not defined $value
l!l&&r!l&&!r
006
MC/DC0%0/3
ref $value or not defined $value or $value eq ""
ref $value not defined $value $value eq ""
Truth table25%1/4
A or not(B) or C
A= ref $valueB= not defined $valueC= $value eq ""
ABCresult
1XX1
01X1
0011
0000
39 0 return undef;
40 }
41  
42 6 ▶ return $init->{value} = $value if !exists $init->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $init->{"value"} 5 1 6
43  
44 1 return $self->error_on_set->throw;
45 }
46  
47 # ERRORS
48  
49 1 ▶sub error_on_set {
Subroutine error_on_set: called CC=1 SCAR=0.0
Pod undocumented
50 1 my ($self) = @_;
51  
52 1 my $error = $self->error->sysinfo;
53  
54 1 $error->name('on.set');
55 1 $error->message('Can\'t re-set atom value');
56 1 $error->offset(1);
57 1 $error->reset;
58  
59 1 return $error;
60 }
61  
62 2 1;
63  
64  
65  
66 =head1 NAME
67  
68 Venus::Atom - Atom Class
69  
70 =cut
71  
72 =head1 ABSTRACT
73  
74 Atom Class for Perl 5
75  
76 =cut
77  
78 =head1 SYNOPSIS
79  
80 package main;
81  
82 use Venus::Atom;
83  
84 my $atom = Venus::Atom->new;
85  
86 # $atom->get;
87  
88 # undef
89  
90 =cut
91  
92 =head1 DESCRIPTION
93  
94 This package provides a write-once object representing a constant value.
95  
96 =cut
97  
98 =head1 INHERITS
99  
100 This package inherits behaviors from:
101  
102 L<Venus::Sealed>
103  
104 =cut
105  
106 =head1 METHODS
107  
108 This package provides the following methods:
109  
110 =cut
111  
112 =head2 get
113  
114 get() (any)
115  
116 The get method can be used to get the underlying constant value set during
117 instantiation.
118  
119 I<Since C<3.55>>
120  
121 =over 4
122  
123 =item get example 1
124  
125 # given: synopsis
126  
127 package main;
128  
129 my $get = $atom->get;
130  
131 # undef
132  
133 =back
134  
135 =over 4
136  
137 =item get example 2
138  
139 # given: synopsis
140  
141 package main;
142  
143 $atom->set("hello");
144  
145 my $get = $atom->get;
146  
147 # "hello"
148  
149 =back
150  
151 =cut
152  
153 =head2 new
154  
155 new(any @args) (Venus::Atom)
156  
157 The new method constructs an instance of the package.
158  
159 I<Since C<4.15>>
160  
161 =over 4
162  
163 =item new example 1
164  
165 package main;
166  
167 use Venus::Atom;
168  
169 my $new = Venus::Atom->new;
170  
171 # bless(..., "Venus::Atom")
172  
173 =back
174  
175 =over 4
176  
177 =item new example 2
178  
179 package main;
180  
181 use Venus::Atom;
182  
183 my $new = Venus::Atom->new('Important');
184  
185 # bless(..., "Venus::Atom")
186  
187 =back
188  
189 =over 4
190  
191 =item new example 3
192  
193 package main;
194  
195 use Venus::Atom;
196  
197 my $new = Venus::Atom->new(value => 'Important');
198  
199 # bless(..., "Venus::Atom")
200  
201 =back
202  
203 =cut
204  
205 =head2 set
206  
207 set(any $data) (any)
208  
209 The set method can be used to set the underlying constant value set during
210 instantiation or via this method. An atom can only be set once, either at
211 instantiation of via this method. Any attempt to re-set the atom will result in
212 an error.
213  
214 I<Since C<3.55>>
215  
216 =over 4
217  
218 =item set example 1
219  
220 # given: synopsis
221  
222 package main;
223  
224 my $set = $atom->set("hello");
225  
226 # "hello"
227  
228 =back
229  
230 =over 4
231  
232 =item B<may raise> L<Venus::Atom::Error> C<on.set>
233  
234 # given: synopsis
235  
236 package main;
237  
238 my $set = $atom->set("hello");
239  
240 $atom->set("hello");
241  
242 # Error! (on.set)
243  
244 =back
245  
246 =cut
247  
248 =head1 OPERATORS
249  
250 This package overloads the following operators:
251  
252 =cut
253  
254 =over 4
255  
256 =item operation: C<("")>
257  
258 This package overloads the C<""> operator.
259  
260 B<example 1>
261  
262 # given: synopsis;
263  
264 my $result = "$atom";
265  
266 # ""
267  
268 B<example 2>
269  
270 # given: synopsis;
271  
272 $atom->set("hello");
273  
274 my $result = "$atom";
275  
276 # "hello"
277  
278 =back
279  
280 =over 4
281  
282 =item operation: C<(eq)>
283  
284 This package overloads the C<eq> operator.
285  
286 B<example 1>
287  
288 # given: synopsis;
289  
290 my $result = $atom eq "";
291  
292 # 1
293  
294 B<example 2>
295  
296 # given: synopsis;
297  
298 $atom->set("hello");
299  
300 my $result = $atom eq "hello";
301  
302 # 1
303  
304 =back
305  
306 =over 4
307  
308 =item operation: C<(ne)>
309  
310 This package overloads the C<ne> operator.
311  
312 B<example 1>
313  
314 # given: synopsis;
315  
316 my $result = $atom ne "";
317  
318 # 0
319  
320 B<example 2>
321  
322 # given: synopsis;
323  
324 $atom->set("hello");
325  
326 my $result = $atom ne "";
327  
328 # 1
329  
330 =back
331  
332 =over 4
333  
334 =item operation: C<(qr)>
335  
336 This package overloads the C<qr> operator.
337  
338 B<example 1>
339  
340 # given: synopsis;
341  
342 my $test = 'hello' =~ qr/$atom/;
343  
344 # 1
345  
346 =back
347  
348 =head1 AUTHORS
349  
350 Awncorp, C<awncorp@cpan.org>
351  
352 =cut
353  
354 =head1 LICENSE
355  
356 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
357  
358 This program is free software, you can redistribute it and/or modify it under
359 the terms of the Apache license version 2.0.
360  
361 =cut
« blib/lib/Venus/Opts.pm ↑ Summary blib/lib/Venus/Role/Testable.pm »