blib/lib/SPVM/BlessedObject/Array.pm

filter: Statementstmt 70.5% 48 / 68 Branchbran 10.0% 1 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 14 / 16 Podpod 85.7% 6 / 7 totaltotal 68.3% 69 / 101 CC 6 SCAR 6.9
CC
6
Cov
63%
length
6.0
to_elems
2.1
to_bin
2.1
CRAP 2.0
« blib/lib/SPVM/Builder/Accessor.pm ↑ Summary blib/lib/SPVM/Builder/Resource.pm »
1 package SPVM::BlessedObject::Array;
2  
3 606 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 606 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 606 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 606 ▶use base 'SPVM::BlessedObject';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 606 ▶use overload '@{}' => sub {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine __ANON__: not called CC=1 SCAR=6.9
10 0 ▶ my ($array) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
11
12 0 my $elems = $array->to_elems;
13
14 0 return $elems;
15 606 };
16  
17 606 ▶use overload fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 606 ▶use SPVM::ExchangeAPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 0 ▶sub length { my $ret; eval { $ret = shift->_xs_length(@_) }; if ($@) { confess($@) } $ret; }
Subroutine length: called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
22  
23 0 ▶sub to_elems { my $ret; eval { $ret = shift->_xs_to_elems(@_) }; if ($@) { confess($@) } $ret; }
Subroutine to_elems: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
24  
25 158 ▶sub to_strings {
Subroutine to_strings: called CC=1 SCAR=6.9
Pod documented
26 0 my $self = shift;
27
28 0 my $elems = $self->to_elems;
29
30 0 my $strings = [map { $_->to_string } @$elems];
31
32 0 return $strings;
33 }
34  
35 158 ▶sub to_bins {
Subroutine to_bins: called CC=1 SCAR=0.6
Pod documented
36 0 my $self = shift;
37
38 0 my $elems = $self->to_elems;
39
40 316 my $binaries = [map { $_->to_bin } @$elems];
41
42 158 return $binaries;
43 }
44  
45 158 ▶sub to_bin { my $ret; eval { $ret = shift->_xs_to_bin(@_) }; if ($@) { confess($@) } $ret; }
Subroutine to_bin: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
46  
47 158 ▶sub set { my $ret; eval { $ret = shift->_xs_set(@_) }; if ($@) { confess($@) } $ret; }
Subroutine set: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
48  
49 158 ▶sub get { my $ret; eval { $ret = shift->_xs_get(@_) }; if ($@) { confess($@) } $ret; }
Subroutine get: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
50  
51 606 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/Accessor.pm ↑ Summary blib/lib/SPVM/Builder/Resource.pm »