blib/lib/Venus/Box.pm

filter: Statementstmt 91.3% 42 / 46 Branchbran 55.5% 10 / 18 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 4 totaltotal 77.0% 67 / 87 CC 12 SCAR 12.1
CC
12
Cov
80%
build_proxy
6.2
__ANON__
4.9
build_args
3.0
CRAP 3.4
« blib/lib/Venus/Task/Venus.pm ↑ Summary blib/lib/Venus/Role/Proxyable.pm »
1 package Venus::Box;
2  
3 3 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 3 ▶use Venus::Class 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INTEGRATES
13  
14 3 with 'Venus::Role::Buildable';
15 3 with 'Venus::Role::Proxyable';
16  
17 # BUILDERS
18  
19 2 ▶sub build_arg {
Subroutine build_arg: called CC=1 SCAR=0.0
Pod undocumented
20 2 my ($self, $data) = @_;
21  
22 return {
23 2 value => $data,
24 };
25 }
26  
27 17 ▶sub build_args {
Subroutine build_args: called CC=3 SCAR=11.0
Pod undocumented
28 17 my ($self, $data) = @_;
29  
30 17 ▶ if (keys %$data == 1 && exists $data->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$data == 1 and exists $data->{"value"}) 15 2 17
Condition66%2/3
keys %$data == 1 and exists $data->{"value"}
!ll&&!rl&&r
2015
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
31 15 return $data;
32 }
33 return {
34 2 value => $data,
35 };
36 }
37  
38 17 ▶sub build_self {
Subroutine build_self: called CC=2 SCAR=7.0
Pod undocumented
39 17 my ($self, $data) = @_;
40  
41 17 require Venus::What;
42  
43 17 ▶ $data //= {};
Condition50%1/2
$data //= {}
l!l
170
MC/DC0%0/1
$data //= {}
$data
Truth table50%1/2
A
A= $data
Aresult
11
00
44  
45 17 $self->{value} = Venus::What->new(value => $data->{value})->deduce;
46  
47 17 return $self;
48 }
49  
50 14 ▶sub build_proxy {
Subroutine build_proxy: called CC=5 SCAR=18.2
Pod undocumented
51 14 my ($self, $package, $method, @args) = @_;
52  
53 14 require Scalar::Util;
54  
55 14 my $value = $self->{value};
56  
57 14 ▶ if (not(Scalar::Util::blessed($value))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($value)) 0 14 14
58 0 require Venus::Error;
59 0 return Venus::Error->throw(
60 "$package can only operate on objects, not $value"
61 );
62 }
63 14 ▶ if (!$value->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value->can($method)) 10 4 14
64 10 ▶ if (my $handler = $self->can("__handle__${method}")) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $handler = $self->can("__handle__$method")) { } 10 0 10
elsif (not $value->can('AUTOLOAD')) { } 0 0 0
65 10 ▶ return sub {$self->$handler(@args)};
Subroutine __ANON__: called CC=1 SCAR=0.0
66 }
67 elsif (!$value->can('AUTOLOAD')) {
68 0 return undef;
69 }
70 }
71 4 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=15.9
72 4 local $_ = $value;
73 4 my $result = [
74 $value->$method(@args)
75 ];
76 4 ▶ $result = $result->[0] if @$result == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$result == 1 4 0 4
77 4 ▶ if (Scalar::Util::blessed($result)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($result)) { } 0 4 4
78 0 ▶ return not(UNIVERSAL::isa($result, 'Venus::Box'))
Branch: 1 branch
BranchTrueFalseTotal
!UNIVERSAL::isa($result, 'Venus::Box') ? : 0 0 0
79 ? ref($self)->new(value => $result)
80 : $result;
81 }
82 else {
83 4 require Venus::What;
84 4 return ref($self)->new(
85 value => Venus::What->new(value => $result)->deduce
86 );
87 }
88 4 };
89 }
90  
91 # METHODS
92  
93 10 ▶sub __handle__unbox {
Subroutine __handle__unbox: called CC=2 SCAR=6.9
94 10 my ($self, $code, @args) = @_;
95 10 ▶ return $code ? $self->$code(@args)->{value} : $self->{value};
Branch: 1 branch
BranchTrueFalseTotal
$code ? : 1 9 10
96 }
97  
98 3 1;
99  
100  
101  
102 =head1 NAME
103  
104 Venus::Box - Box Class
105  
106 =cut
107  
108 =head1 ABSTRACT
109  
110 Box Class for Perl 5
111  
112 =cut
113  
114 =head1 SYNOPSIS
115  
116 package main;
117  
118 use Venus::Box;
119  
120 my $box = Venus::Box->new(
121 value => {},
122 );
123  
124 # $box->keys->count->unbox;
125  
126 =cut
127  
128 =head1 DESCRIPTION
129  
130 This package provides a pure Perl boxing mechanism for wrapping objects and
131 values, and chaining method calls across all objects.
132  
133 =cut
134  
135 =head1 INTEGRATES
136  
137 This package integrates behaviors from:
138  
139 L<Venus::Role::Buildable>
140  
141 L<Venus::Role::Proxyable>
142  
143 =cut
144  
145 =head1 METHODS
146  
147 This package provides the following methods:
148  
149 =cut
150  
151 =head2 new
152  
153 new(any @args) (Venus::Box)
154  
155 The new method constructs an instance of the package.
156  
157 I<Since C<4.15>>
158  
159 =over 4
160  
161 =item new example 1
162  
163 package main;
164  
165 use Venus::Box;
166  
167 my $new = Venus::Box->new;
168  
169 # bless(..., "Venus::Box")
170  
171 =back
172  
173 =over 4
174  
175 =item new example 2
176  
177 package main;
178  
179 use Venus::Box;
180  
181 my $new = Venus::Box->new('hello');
182  
183 # bless(..., "Venus::Box")
184  
185 =back
186  
187 =over 4
188  
189 =item new example 3
190  
191 package main;
192  
193 use Venus::Box;
194  
195 my $new = Venus::Box->new(value => 'hello');
196  
197 # bless(..., "Venus::Box")
198  
199 =back
200  
201 =cut
202  
203 =head2 unbox
204  
205 unbox(string $method, any @args) (any)
206  
207 The unbox method returns the un-boxed underlying object. This is a virtual
208 method that dispatches to C<__handle__unbox>. This method supports dispatching,
209 i.e. providing a method name and arguments whose return value will be acted on
210 by this method.
211  
212 I<Since C<0.01>>
213  
214 =over 4
215  
216 =item unbox example 1
217  
218 # given: synopsis;
219  
220 my $unbox = $box->unbox;
221  
222 # bless({ value => {} }, "Venus::Hash")
223  
224 =back
225  
226 =over 4
227  
228 =item unbox example 2
229  
230 # given: synopsis;
231  
232 my $unbox = $box->unbox('count');
233  
234 # 0
235  
236 =back
237  
238 =cut
239  
240 =head1 AUTHORS
241  
242 Awncorp, C<awncorp@cpan.org>
243  
244 =cut
245  
246 =head1 LICENSE
247  
248 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
249  
250 This program is free software, you can redistribute it and/or modify it under
251 the terms of the Apache license version 2.0.
252  
253 =cut
« blib/lib/Venus/Task/Venus.pm ↑ Summary blib/lib/Venus/Role/Proxyable.pm »