The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

SPVM::BlessedObject::Array - SPVM Array

DESCRIPTION

The object of the SPVM::BlessedObject::Array class holds a SPVM array.

Usage

# Gets an element of the array
my $elem = $blessed_object_array->get(2);

# Sets an element of the array
$blessed_object_array->set(2 => 5);

# Converts a SPVM array to a Perl array reference
my $elems = $blessed_object_array->to_elems;

# Converts a SPVM array to a binary
my $binary = $blessed_object_array->to_bin;

Methods

get

my $elem = $blessed_object_array->get($index);

Returns an element of the array with the index.

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.

to_elems

my $elems = $blessed_object_array->to_elems;

Converts a SPVM array to a Perl array reference and returns it.

to_bin

my $binary = $blessed_object_array->to_bin;

Converts a SPVM array to a binary and returns it.

This binary is unpacked by unpack function.

If the array is an object array, an excetion is thrown.

Examples:

# byte[]
my @elems = unpack 'c*', $binary;

# short[]
my @elems = unpack 's*', $binary;

# int[]
my @elems = unpack 'l*', $binary;

# long[]
my @elems = unpack 'q*', $binary;

# float[]
my @elems = unpack 'f*', $binary;

# double[]
my @elems = unpack 'd*', $binary;

to_strings

my $elems = $blessed_object_array->to_strings;

Converts a SPVM string array to a Perl array reference and returns it.

Each element calls to_string method.

to_bins

my $elems = $blessed_object_array->to_bins;

Converts a SPVM string array to Perl array reference and returns it.

Each element calls to_bin method.

Operators

Overloads the following operators.

array dereference

my @elems = @$array;

This is the same as the following operation.

my @elems = @{$array->to_elems};

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License