blib/lib/Venus/Dump.pm

filter: Statementstmt 100% 105 / 105 Branchbran 100% 10 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 29 / 29 Podpod 22.2% 2 / 9 totaltotal 95.5% 151 / 158 CC 11 SCAR 5.1
CC
11
Cov
100%
FROM_BOOL
5.0
TO_BOOL
5.0
build_args
3.0
CRAP 1.7
« blib/lib/Venus/Name.pm ↑ Summary blib/lib/Venus/Text/Tag.pm »
1 package Venus::Dump;
2  
3 18 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 14 ▶use Venus::Class 'attr', 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INHERITS
13  
14 10 base 'Venus::Kind::Utility';
15  
16 # INTEGRATES
17  
18 10 with 'Venus::Role::Valuable';
19 10 with 'Venus::Role::Buildable';
20 10 with 'Venus::Role::Accessible';
21 10 with 'Venus::Role::Explainable';
22  
23 # OVERLOADS
24  
25 13 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
26 13 '""' => 'explain',
27 '~~' => 'explain',
28 fallback => 1,
29 14 );
30  
31 # ATTRIBUTES
32  
33 10 attr 'decoder';
34 10 attr 'encoder';
35  
36 # BUILDERS
37  
38 16 ▶sub build_arg {
Subroutine build_arg: called CC=1 SCAR=0.0
Pod undocumented
39 16 my ($self, $data) = @_;
40  
41 return {
42 16 value => $data
43 };
44 }
45  
46 181 ▶sub build_args {
Subroutine build_args: called CC=3 SCAR=11.0
Pod undocumented
47 181 my ($self, $data) = @_;
48  
49 181 ▶ if (keys %$data == 1 && exists $data->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$data == 1 and exists $data->{"value"}) 19 160 179
Condition100%3/3
keys %$data == 1 and exists $data->{"value"}
!ll&&!rl&&r
1411919
MC/DC100%2/2
keys %$data == 1 and exists $data->{"value"}
keys %$data == 1 exists $data->{"value"}
Truth table100%3/3
A and B
A= keys %$data == 1B= exists $data->{"value"}
ABresult
0X0
100
111
50 21 return $data;
51 }
52 return {
53 162 value => $data
54 };
55 }
56  
57 2 ▶sub build_nil {
Subroutine build_nil: called CC=1 SCAR=0.0
Pod undocumented
58 2 my ($self, $data) = @_;
59  
60 return {
61 2 value => $data
62 };
63 }
64  
65 181 ▶sub build_self {
Subroutine build_self: called CC=1 SCAR=0.0
Pod undocumented
66 181 my ($self, $data) = @_;
67  
68 69 ▶ $self->encoder(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
69 69 my ($data) = @_;
70 69 require Data::Dumper;
71 13 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
72 69 local $Data::Dumper::Indent = 1;
73 69 local $Data::Dumper::Purity = 1;
74 69 local $Data::Dumper::Quotekeys = 0;
75 69 local $Data::Dumper::Deepcopy = 1;
76 69 local $Data::Dumper::Deparse = 1;
77 69 local $Data::Dumper::Sortkeys = 1;
78 69 local $Data::Dumper::Terse = 1;
79 69 local $Data::Dumper::Useqq = 1;
80 69 Data::Dumper->Dump([$data])
81 181 });
82  
83 115 ▶ $self->decoder(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
84 115 my ($text) = @_;
85 115 require Symbol;
86 115 my $name = join '::', __PACKAGE__, join '_', 'Eval', rand =~ s/\D//gr;
87 11 ▶ my $data = eval "package $name; no warnings; return $text";
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
88 115 Symbol::delete_package($name);
89 115 return $data;
90 181 });
91  
92 181 return $self;
93 }
94  
95 # METHODS
96  
97 115 ▶sub decode {
Subroutine decode: called CC=1 SCAR=0.0
Pod documented
98 115 my ($self, $data) = @_;
99  
100 # double-traversing the data structure due to lack of boolean support
101 115 return $self->set(FROM_BOOL($self->decoder->($data)));
102 }
103  
104 69 ▶sub encode {
Subroutine encode: called CC=1 SCAR=0.0
Pod documented
105 69 my ($self) = @_;
106  
107 # double-traversing the data structure due to lack of boolean support
108 69 return $self->encoder->(TO_BOOL($self->get));
109 }
110  
111 8 ▶sub explain {
Subroutine explain: called CC=1 SCAR=0.0
Pod undocumented
112 8 my ($self) = @_;
113  
114 8 return $self->encode;
115 }
116  
117 2208 ▶sub FROM_BOOL {
Subroutine FROM_BOOL: called CC=5 SCAR=16.1
Pod undocumented
118 2208 my ($value) = @_;
119  
120 2208 require Venus::Boolean;
121  
122 2208 ▶ if (ref($value) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "HASH") 421 1785 2206
123 423 for my $key (keys %$value) {
124 1792 $value->{$key} = FROM_BOOL($value->{$key});
125 }
126 423 return $value;
127 }
128  
129 1787 ▶ if (ref($value) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 127 1658 1785
130 129 for my $key (keys @$value) {
131 305 $value->[$key] = FROM_BOOL($value->[$key]);
132 }
133 129 return $value;
134 }
135  
136 1660 return Venus::Boolean::TO_BOOL(Venus::Boolean::FROM_BOOL($value));
137 }
138  
139 330 ▶sub TO_BOOL {
Subroutine TO_BOOL: called CC=5 SCAR=16.1
Pod undocumented
140 330 my ($value) = @_;
141  
142 330 require Venus::Boolean;
143  
144 330 ▶ if (ref($value) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "HASH") 83 245 328
145 83 $value = {
146 %$value
147 };
148 83 for my $key (keys %$value) {
149 224 $value->{$key} = TO_BOOL($value->{$key});
150 }
151 83 return $value;
152 }
153  
154 245 ▶ if (ref($value) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 17 228 245
155 17 $value = [
156 @$value
157 ];
158 17 for my $key (keys @$value) {
159 37 $value->[$key] = TO_BOOL($value->[$key]);
160 }
161 17 return $value;
162 }
163  
164 228 return Venus::Boolean::TO_BOOL_TFO($value);
165 }
166  
167 10 1;
168  
169  
170  
171 =head1 NAME
172  
173 Venus::Dump - Dump Class
174  
175 =cut
176  
177 =head1 ABSTRACT
178  
179 Dump Class for Perl 5
180  
181 =cut
182  
183 =head1 SYNOPSIS
184  
185 package main;
186  
187 use Venus::Dump;
188  
189 my $dump = Venus::Dump->new(
190 value => { name => ['Ready', 'Robot'], version => 0.12, stable => !!1, }
191 );
192  
193 # $dump->encode;
194  
195 =cut
196  
197 =head1 DESCRIPTION
198  
199 This package provides methods for reading and writing dumped (i.e.
200 stringified) Perl data.
201  
202 =cut
203  
204 =head1 ATTRIBUTES
205  
206 This package has the following attributes:
207  
208 =cut
209  
210 =head2 decoder
211  
212 decoder(CodeRef)
213  
214 This attribute is read-write, accepts C<(CodeRef)> values, and is optional.
215  
216 =cut
217  
218 =head2 encoder
219  
220 encoder(CodeRef)
221  
222 This attribute is read-write, accepts C<(CodeRef)> values, and is optional.
223  
224 =cut
225  
226 =head1 INHERITS
227  
228 This package inherits behaviors from:
229  
230 L<Venus::Kind::Utility>
231  
232 =cut
233  
234 =head1 INTEGRATES
235  
236 This package integrates behaviors from:
237  
238 L<Venus::Role::Accessible>
239  
240 L<Venus::Role::Buildable>
241  
242 L<Venus::Role::Explainable>
243  
244 L<Venus::Role::Valuable>
245  
246 =cut
247  
248 =head1 METHODS
249  
250 This package provides the following methods:
251  
252 =cut
253  
254 =head2 decode
255  
256 decode(string $text) (any)
257  
258 The decode method decodes the Perl string, sets the object value, and returns
259 the decoded value.
260  
261 I<Since C<0.01>>
262  
263 =over 4
264  
265 =item decode example 1
266  
267 # given: synopsis;
268  
269 my $decode = $dump->decode('{codename=>["Ready","Robot"],stable=>!!1}');
270  
271 # { codename => ["Ready", "Robot"], stable => 1 }
272  
273 =back
274  
275 =cut
276  
277 =head2 encode
278  
279 encode() (string)
280  
281 The encode method encodes the objects value as a Perl string and returns the
282 encoded string.
283  
284 I<Since C<0.01>>
285  
286 =over 4
287  
288 =item encode example 1
289  
290 # given: synopsis;
291  
292 my $encode = $dump->encode;
293  
294 # '{name => ["Ready","Robot"], stable => !!1, version => "0.12"}'
295  
296 =back
297  
298 =cut
299  
300 =head2 new
301  
302 new(any @args) (Venus::Dump)
303  
304 The new method constructs an instance of the package.
305  
306 I<Since C<4.15>>
307  
308 =over 4
309  
310 =item new example 1
311  
312 package main;
313  
314 use Venus::Dump;
315  
316 my $new = Venus::Dump->new;
317  
318 # bless(..., "Venus::Dump")
319  
320 =back
321  
322 =over 4
323  
324 =item new example 2
325  
326 package main;
327  
328 use Venus::Dump;
329  
330 my $new = Venus::Dump->new({password => 'secret'});
331  
332 # bless(..., "Venus::Dump")
333  
334 =back
335  
336 =over 4
337  
338 =item new example 3
339  
340 package main;
341  
342 use Venus::Dump;
343  
344 my $new = Venus::Dump->new(value => {password => 'secret'});
345  
346 # bless(..., "Venus::Dump")
347  
348 =back
349  
350 =cut
351  
352 =head1 AUTHORS
353  
354 Awncorp, C<awncorp@cpan.org>
355  
356 =cut
357  
358 =head1 LICENSE
359  
360 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
361  
362 This program is free software, you can redistribute it and/or modify it under
363 the terms of the Apache license version 2.0.
364  
365 =cut
« blib/lib/Venus/Name.pm ↑ Summary blib/lib/Venus/Text/Tag.pm »