blib/lib/Venus/Sealed.pm

filter: Statementstmt 97.7% 44 / 45 Branchbran 66.6% 8 / 12 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 4 totaltotal 81.9% 68 / 83 CC 9 SCAR 9.9
CC
9
Cov
87%
build_args
5.1
build_proxy
3.4
__ANON__
3.1
CRAP 2.7
« blib/lib/Venus/Fault.pm ↑ Summary blib/lib/Venus/Vars.pm »
1 package Venus::Sealed;
2  
3 4 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 4 ▶use Venus::Class 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INTEGRATES
13  
14 4 with 'Venus::Role::Buildable';
15 4 with 'Venus::Role::Proxyable';
16 4 with 'Venus::Role::Tryable';
17 4 with 'Venus::Role::Throwable';
18 4 with 'Venus::Role::Catchable';
19  
20 # BUILDERS
21  
22 8 ▶sub build_arg {
Subroutine build_arg: called CC=1 SCAR=0.0
Pod undocumented
23 8 my ($self, $data) = @_;
24  
25 return {
26 8 value => $data,
27 };
28 }
29  
30 66 ▶sub build_args {
Subroutine build_args: called CC=5 SCAR=16.3
Pod undocumented
31 66 my ($self, $data) = @_;
32  
33 66 ▶ if (not(keys %$data == 1 && exists $data->{value})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %$data == 1 and exists $data->{"value"}) 14 52 66
Condition66%2/3
keys %$data == 1 and exists $data->{"value"}
!ll&&!rl&&r
14052
MC/DC50%1/2
keys %$data == 1 and exists $data->{"value"}
keys %$data == 1 exists $data->{"value"}
Truth table66%2/3
A and B
A= keys %$data == 1B= exists $data->{"value"}
ABresult
0X0
100
111
34 14 ▶ $data = (exists $data->{value}) ? {value => $data->{value}} : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $data->{'value'} ? : 0 14 14
35 }
36  
37 66 require Storable;
38  
39 66 $data = Storable::dclone($data);
40  
41 my $state = {
42 66 ▶ (exists $data->{value} ? (value => $data->{value}) : ())
Branch: 1 branch
BranchTrueFalseTotal
exists $data->{'value'} ? : 52 14 66
43 };
44  
45 66 my $subs = {
46 map +($_, $self->can($_)), grep /^__\w+$/, $self->meta->subs,
47 };
48  
49 87 ▶ my $scope = sub {
Subroutine __ANON__: called CC=3 SCAR=11.3
50 87 my ($self, $name, @args) = @_;
51  
52 87 ▶ return if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 87 87
53  
54 87 my $method = "__$name";
55  
56 87 ▶ return if !$subs->{$method};
Branch: 1 branch
BranchTrueFalseTotal
unless $subs->{$method} 0 87 87
57  
58 87 return $subs->{$method}->($self, $data, $state, @args);
59 66 };
60  
61 return {
62 66 scope => $scope,
63 };
64 }
65  
66 66 ▶sub build_self {
Subroutine build_self: called CC=1 SCAR=0.0
Pod undocumented
67 66 my ($self, $data) = @_;
68  
69 66 return $self;
70 }
71  
72 87 ▶sub build_proxy {
Subroutine build_proxy: called CC=3 SCAR=12.3
Pod undocumented
73 87 my ($self, $package, $name, @args) = @_;
74  
75 87 my $method = $self->can("__$name");
76  
77 87 ▶ if (!$method && ref $method ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $method and ref $method ne "CODE") 0 87 87
Condition33%1/3
not $method and ref $method ne "CODE"
!ll&&!rl&&r
8700
MC/DC0%0/2
not $method and ref $method ne "CODE"
not $method ref $method ne "CODE"
Truth table33%1/3
not(A) and B
A= not $methodB= ref $method ne "CODE"
ABresult
0X0
100
111
78 0 return undef;
79 }
80  
81 87 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
82 87 return $self->{scope}->($self, $name, @args);
83 87 };
84 }
85  
86 # METHODS
87  
88 1 ▶sub __get {
Subroutine __get: called CC=1 SCAR=0.0
89 1 my ($self, $init, $data) = @_;
90  
91 1 return $data->{value};
92 }
93  
94 1 ▶sub __set {
Subroutine __set: called CC=1 SCAR=0.0
95 1 my ($self, $init, $data, $value) = @_;
96  
97 1 return $data->{value} = $value;
98 }
99  
100 4 1;
101  
102  
103  
104 =head1 NAME
105  
106 Venus::Sealed - Sealed Class
107  
108 =cut
109  
110 =head1 ABSTRACT
111  
112 Sealed Class for Perl 5
113  
114 =cut
115  
116 =head1 SYNOPSIS
117  
118 package main;
119  
120 use Venus::Sealed;
121  
122 my $sealed = Venus::Sealed->new('012345');
123  
124 # $sealed->get;
125  
126 # '012345'
127  
128 =cut
129  
130 =head1 DESCRIPTION
131  
132 This package provides a mechanism for sealing object and restricting and/or
133 preventing access to the underlying data structures. This package can be used
134 directly but is meant to be subclassed.
135  
136 =cut
137  
138 =head1 INTEGRATES
139  
140 This package integrates behaviors from:
141  
142 L<Venus::Role::Buildable>
143  
144 L<Venus::Role::Catchable>
145  
146 L<Venus::Role::Proxyable>
147  
148 L<Venus::Role::Throwable>
149  
150 L<Venus::Role::Tryable>
151  
152 =cut
153  
154 =head1 METHODS
155  
156 This package provides the following methods:
157  
158 =cut
159  
160 =head2 get
161  
162 get(any @args) (any)
163  
164 The get method can be used directly to get the sealed value set during
165 instantiation, but is meant to be overridden in a subclass to further control
166 access to the underlying data.
167  
168 I<Since C<3.55>>
169  
170 =over 4
171  
172 =item get example 1
173  
174 # given: synopsis
175  
176 package main;
177  
178 my $get = $sealed->get;
179  
180 # "012345"
181  
182 =back
183  
184 =over 4
185  
186 =item get example 2
187  
188 package Example;
189  
190 use Venus::Class;
191  
192 base 'Venus::Sealed';
193  
194 sub __get {
195 my ($self, $init, $data) = @_;
196  
197 return $data->{value};
198 }
199  
200 sub __set {
201 my ($self, $init, $data, $value) = @_;
202  
203 return $data->{value} = $value;
204 }
205  
206 package main;
207  
208 my $sealed = Example->new("012345");
209  
210 my $get = $sealed->get;
211  
212 # "012345"
213  
214 =back
215  
216 =cut
217  
218 =head2 new
219  
220 new(any @args) (Venus::Sealed)
221  
222 The new method constructs an instance of the package.
223  
224 I<Since C<4.15>>
225  
226 =over 4
227  
228 =item new example 1
229  
230 package main;
231  
232 use Venus::Sealed;
233  
234 my $new = Venus::Sealed->new;
235  
236 # bless(..., "Venus::Sealed")
237  
238 =back
239  
240 =over 4
241  
242 =item new example 2
243  
244 package main;
245  
246 use Venus::Sealed;
247  
248 my $new = Venus::Sealed->new('012345');
249  
250 # bless(..., "Venus::Sealed")
251  
252 =back
253  
254 =over 4
255  
256 =item new example 3
257  
258 package main;
259  
260 use Venus::Sealed;
261  
262 my $new = Venus::Sealed->new(value => '012345');
263  
264 # bless(..., "Venus::Sealed")
265  
266 =back
267  
268 =cut
269  
270 =head2 set
271  
272 set(any @args) (any)
273  
274 The set method can be used directly to set the sealed value set during
275 instantiation, but is meant to be overridden in a subclass to further control
276 access to the underlying data.
277  
278 I<Since C<3.55>>
279  
280 =over 4
281  
282 =item set example 1
283  
284 # given: synopsis
285  
286 package main;
287  
288 my $set = $sealed->set("098765");
289  
290 # "098765"
291  
292 =back
293  
294 =over 4
295  
296 =item set example 2
297  
298 package Example;
299  
300 use Venus::Class;
301  
302 base 'Venus::Sealed';
303  
304 sub __get {
305 my ($self, $init, $data) = @_;
306  
307 return $data->{value};
308 }
309  
310 sub __set {
311 my ($self, $init, $data, $value) = @_;
312  
313 return $data->{value} = $value;
314 }
315  
316 package main;
317  
318 my $sealed = Example->new("012345");
319  
320 my $set = $sealed->set("098765");
321  
322 # "098765"
323  
324 =back
325  
326 =cut
327  
328 =head1 AUTHORS
329  
330 Awncorp, C<awncorp@cpan.org>
331  
332 =cut
333  
334 =head1 LICENSE
335  
336 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
337  
338 This program is free software, you can redistribute it and/or modify it under
339 the terms of the Apache license version 2.0.
340  
341 =cut
« blib/lib/Venus/Fault.pm ↑ Summary blib/lib/Venus/Vars.pm »