blib/lib/SPVM/BlessedObject/Array.pm

filter: Statementstmt 71.6% 48 / 67 Branchbran 10.0% 1 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 14 / 16 Podpod 85.7% 6 / 7 totaltotal 69.0% 69 / 100 CC 6 SCAR 7.5
CC
6
Cov
64%
get
6.0
to_bin
4.7
set
2.5
CRAP 2.1
« blib/lib/SPVM/Builder/Config/Util.pm ↑ Summary blib/lib/SPVM/Builder/Accessor.pm »
1 package SPVM::BlessedObject::Array;
2  
3 1226 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 613 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 613 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 613 ▶use base 'SPVM::BlessedObject';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 613 ▶use overload '@{}' => sub {
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine __ANON__: not called CC=1 SCAR=0.4
10 66 ▶ my ($array) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.4
11
12 0 my $elems = $array->to_elems;
13
14 0 return $elems;
15 613 };
16  
17 613 ▶use overload fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 613 ▶use SPVM::ExchangeAPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 66 ▶sub length { my $ret; eval { $ret = shift->_xs_length(@_) }; if ($@) { confess($@) } $ret; }
Subroutine length: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
22  
23 66 ▶sub to_elems { my $ret; eval { $ret = shift->_xs_to_elems(@_) }; if ($@) { confess($@) } $ret; }
Subroutine to_elems: called CC=2 SCAR=7.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
24  
25 sub to_strings {
26 66 ▶ my $self = shift;
Subroutine to_strings: called CC=1 SCAR=0.0
Pod documented
27
28 66 my $elems = $self->to_elems;
29
30 66 my $strings = [map { $_->to_string } @$elems];
31
32 66 return $strings;
33 }
34  
35 sub to_bins {
36 66 ▶ my $self = shift;
Subroutine to_bins: called CC=1 SCAR=4.1
Pod documented
37
38 0 my $elems = $self->to_elems;
39
40 0 my $binaries = [map { $_->to_bin } @$elems];
41
42 0 return $binaries;
43 }
44  
45 0 ▶sub to_bin { my $ret; eval { $ret = shift->_xs_to_bin(@_) }; if ($@) { confess($@) } $ret; }
Subroutine to_bin: called CC=2 SCAR=15.4
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
46  
47 0 ▶sub set { my $ret; eval { $ret = shift->_xs_set(@_) }; if ($@) { confess($@) } $ret; }
Subroutine set: called CC=2 SCAR=9.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
48  
49 0 ▶sub get { my $ret; eval { $ret = shift->_xs_get(@_) }; if ($@) { confess($@) } $ret; }
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
50  
51 1;
52  
53 =head1 Name
54  
55 SPVM::BlessedObject::Array - SPVM Array
56  
57 =head2 DESCRIPTION
58  
59 The object of C<SPVM::BlessedObject::Array> class holds an SPVM array.
60  
61 =head1 Usage
62  
63 # Gets an element of the array
64 my $elem = $blessed_object_array->get(2);
65
66 # Sets an element of the array
67 $blessed_object_array->set(2 => 5);
68
69 # Converts an SPVM array to a Perl array reference
70 my $elems = $blessed_object_array->to_elems;
71
72 # Converts an SPVM array to a binary
73 my $binary = $blessed_object_array->to_bin;
74  
75 =head1 Methods
76  
77 =head2 get
78  
79 my $elem = $blessed_object_array->get($index);
80  
81 Returns an element of the array with the index.
82  
83 =head2 set
84  
85 $blessed_object_array->set($index, $elem);
86  
87 Sets an element of the array with the index.
88  
89 If $elem cannnot be assigned to the element of the array, an exception is thrown.
90  
91 =head2 to_elems
92  
93 my $elems = $blessed_object_array->to_elems;
94  
95 Converts an SPVM array to a Perl array reference and returns it.
96  
97 =head2 to_bin
98  
99 my $binary = $blessed_object_array->to_bin;
100  
101 Converts an SPVM array to a binary and returns it.
102  
103 This binary is unpacked by L<unpack|https://perldoc.perl.org/functions/unpack> function.
104  
105 If the array is an object array, an excetion is thrown.
106  
107 Examples:
108  
109 # byte[]
110 my @elems = unpack 'c*', $binary;
111
112 # short[]
113 my @elems = unpack 's*', $binary;
114
115 # int[]
116 my @elems = unpack 'l*', $binary;
117  
118 # long[]
119 my @elems = unpack 'q*', $binary;
120  
121 # float[]
122 my @elems = unpack 'f*', $binary;
123  
124 # double[]
125 my @elems = unpack 'd*', $binary;
126  
127 =head2 to_strings
128  
129 my $elems = $blessed_object_array->to_strings;
130  
131 Converts an SPVM string array to a Perl array reference and returns it.
132  
133 Each element calls L<to_string|SPVM::BlessedObject::String/"to_string"> method.
134  
135 =head2 to_bins
136  
137 my $elems = $blessed_object_array->to_bins;
138  
139 Converts an SPVM string array to Perl array reference and returns it.
140  
141 Each element calls L<to_bin|SPVM::BlessedObject::String/"to_bin"> method.
142  
143 =head1 Operators
144  
145 Overloads the following operators.
146  
147 =head2 array dereference
148
149 my @elems = @$array;
150  
151 This is the same as the following operation.
152  
153 my @elems = @{$array->to_elems};
154  
155 =head1 Copyright & License
156  
157 Copyright (c) 2023 Yuki Kimoto
158  
159 MIT License
« blib/lib/SPVM/Builder/Config/Util.pm ↑ Summary blib/lib/SPVM/Builder/Accessor.pm »