blib/lib/Venus/Box.pm

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