| 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 | 3 | ▶ | use Venus::Class; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | with 'Venus::Role::Buildable'; | |||||||||||||||||||||||||||
| 11 | 3 | 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 | 9 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_args: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 9 | ▶ | if (keys %$data == 1 && exists $data->{value}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
keys %$data == 1 and exists $data->{"value"}
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"}
| |||||||||||||||||||||||||||||
| 27 | 8 | return $data; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | return { | ||||||||||||||||||||||||||||
| 30 | 1 | value => $data, | |||||||||||||||||||||||||||
| 31 | }; | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub build_self { | ||||||||||||||||||||||||||||
| 35 | 9 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_self: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 9 | require Venus::Type; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 9 | ▶ | $data //= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$data //= {}
MC/DC0%0/1
$data //= {}
$data
Truth table50%1/2
A
A= $data
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 9 | $self->{value} = Venus::Type->new(value => $data->{value})->deduce; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 9 | return $self; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub build_proxy { | ||||||||||||||||||||||||||||
| 47 | 5 | ▶ | my ($self, $package, $method, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_proxy: called CC=5 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 5 | require Scalar::Util; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 5 | my $value = $self->{value}; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 5 | ▶ | if (not(Scalar::Util::blessed($value))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | require Venus::Error; | |||||||||||||||||||||||||||
| 55 | 0 | return Venus::Error->throw( | |||||||||||||||||||||||||||
| 56 | "$package can only operate on objects, not $value" | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 5 | ▶ | if (!$value->can($method)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 2 | ▶ | if (lc($method) eq 'unbox') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 61 | return sub { | ||||||||||||||||||||||||||||
| 62 | $self->{value} | ||||||||||||||||||||||||||||
| 63 | 2 | ▶ | }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | elsif (!$value->can('AUTOLOAD')) { | ||||||||||||||||||||||||||||
| 66 | 0 | return undef; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | return sub { | ||||||||||||||||||||||||||||
| 70 | 3 | ▶ | my $result = [ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.4
| |||||||||||||||||||||||||||||
| 71 | $value->$method(@args) | ||||||||||||||||||||||||||||
| 72 | ]; | ||||||||||||||||||||||||||||
| 73 | 3 | ▶ | $result = $result->[0] if @$result == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 3 | ▶ | if (Scalar::Util::blessed($result)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return not(UNIVERSAL::isa($result, 'Venus::Box')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | ? ref($self)->new(value => $result) | ||||||||||||||||||||||||||||
| 77 | : $result; | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||
| 80 | 3 | require Venus::Type; | |||||||||||||||||||||||||||
| 81 | 3 | return ref($self)->new( | |||||||||||||||||||||||||||
| 82 | value => Venus::Type->new(value => $result)->deduce | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 3 | }; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 3 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 NAME | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Venus::Box - Box Class | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 ABSTRACT | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Box Class for Perl 5 | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | package main; | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | use Venus::Box; | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | my $box = Venus::Box->new( | ||||||||||||||||||||||||||||
| 111 | value => {}, | ||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # $box->keys->count->unbox; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | This package provides a pure Perl boxing mechanism for wrapping objects and | ||||||||||||||||||||||||||||
| 121 | values, and chaining method calls across all objects. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =head1 INTEGRATES | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | This package integrates behaviors from: | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | L<Venus::Role::Buildable> | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | L<Venus::Role::Proxyable> | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =cut | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head1 METHODS | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | This package provides the following methods: | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head2 unbox | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | unbox() (Any) | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | The unbox method returns the un-boxed underlying object. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | I<Since C<0.01>> | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =over 4 | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item unbox example 1 | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # given: synopsis; | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | my $unbox = $box->unbox; | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | # bless({ value => {} }, "Venus::Hash") | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =back | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||||||||||