my
(
$array
) =
@_
;
my
$elems
=
$array
->to_elems;
return
$elems
;
};
sub
length
{
my
$ret
;
eval
{
$ret
=
shift
->_xs_length(
@_
) };
if
($@) { confess($@) }
$ret
; }
sub
to_elems {
my
$ret
;
eval
{
$ret
=
shift
->_xs_to_elems(
@_
) };
if
($@) { confess($@) }
$ret
; }
sub
to_strings {
my
$self
=
shift
;
my
$elems
=
$self
->to_elems;
my
$strings
= [
map
{
$_
->to_string }
@$elems
];
return
$strings
;
}
sub
to_bins {
my
$self
=
shift
;
my
$elems
=
$self
->to_elems;
my
$binaries
= [
map
{
$_
->to_bin }
@$elems
];
return
$binaries
;
}
sub
to_bin {
my
$ret
;
eval
{
$ret
=
shift
->_xs_to_bin(
@_
) };
if
($@) { confess($@) }
$ret
; }
sub
set {
my
$ret
;
eval
{
$ret
=
shift
->_xs_set(
@_
) };
if
($@) { confess($@) }
$ret
; }
sub
get {
my
$ret
;
eval
{
$ret
=
shift
->_xs_get(
@_
) };
if
($@) { confess($@) }
$ret
; }
1;
=head1 Name
SPVM::BlessedObject::Array - SPVM Array
=head2 DESCRIPTION
The object of C<SPVM::BlessedObject::Array> class holds an SPVM array.
=head1 Usage
my
$elem
=
$blessed_object_array
->get(2);
$blessed_object_array
->set(
2
=> 5);
my
$elems
=
$blessed_object_array
->to_elems;
my
$binary
=
$blessed_object_array
->to_bin;
=head1 Methods
=head2 get
my
$elem
=
$blessed_object_array
->get(
$index
);
Returns an element of the array
with
the
index
.
=head2 set
$blessed_object_array
->set(
$index
,
$elem
);
Sets an element of the array
with
the
index
.
If
$elem
cannnot be assigned to the element of the array, an exception is thrown.
=head2 to_elems
my
$elems
=
$blessed_object_array
->to_elems;
Converts an SPVM array to a Perl array reference and returns it.
=head2 to_bin
my
$binary
=
$blessed_object_array
->to_bin;
Converts an SPVM array to a binary and returns it.
If the array is an object array, an excetion is thrown.
Examples:
my
@elems
=
unpack
'c*'
,
$binary
;
my
@elems
=
unpack
's*'
,
$binary
;
my
@elems
=
unpack
'l*'
,
$binary
;
my
@elems
=
unpack
'q*'
,
$binary
;
my
@elems
=
unpack
'f*'
,
$binary
;
my
@elems
=
unpack
'd*'
,
$binary
;
=head2 to_strings
my
$elems
=
$blessed_object_array
->to_strings;
Converts an SPVM string array to a Perl array reference and returns it.
Each element calls L<to_string|SPVM::BlessedObject::String/
"to_string"
> method.
=head2 to_bins
my
$elems
=
$blessed_object_array
->to_bins;
Converts an SPVM string array to Perl array reference and returns it.
Each element calls L<to_bin|SPVM::BlessedObject::String/
"to_bin"
> method.
=head1 Operators
Overloads the following operators.
=head2 array dereference
my
@elems
=
@$array
;
This is the same as the following operation.
my
@elems
= @{
$array
->to_elems};
=head1 Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License