SPVM::Hash(3)
π Name π
Okay bestie, meet SPVM::Hash β literally the Hash (Associative Array) class in SPVM. This is the SPVM::Hash(3) manual page from the User Contributed Perl Documentation, and it's giving "key-value pairs but make it SPVM" π
.
π Description π
The Hash class in SPVM represents hashes(associative arrays). You got keys, you got values, they're associated β iconic behavior honestly.
ποΈ Usage ποΈ
Here's the whole demo, copied exactly with no edits, because we respect the code:
use Hash;
my $book = Hash->new;
my $book = Hash->new({id => 4, name => "Perl", price => 3000.0});
$book->set(id => 4);
$book->set(name => "Perl");
$book->set(price => 3000.0);
$book->set(point => Point->new(1, 2));
my $id = $book->get("id")->(int);
my $name = $book->get("name")->(string);
my $price = $book->get("price")->(double);
my $point = $book->get("point")->(Point);
if ($hash->exists("id")) {
}
# Use hash access syntax
$book->{"id"} = 4;
$book->{"name"} = "Perl";
$book->{"price"} = 3000.0;
$book->{"point"} = Point->new(1, 2);
my $id = $book->{"id"}->(int);
my $name = $book->{"name"}->(string);
my $price = $book->{"price"}->(double);
my $point = $book->{"point"}->(Point);
π Details π
The hash function is "siphash-1-3". Periodt.
π§© Interfaces π§©
Cloneable
ποΈ Fields ποΈ
keys_length
has keys_length : ro int;
This is the length of the keys in the hash.
β¨ Class Methods β¨
new
static method new : Hash ($key_values : object[] = undef);
Creates a new Hash object given key-value pairs $key_values.
Examples:
my $book = Hash->new;
my $book = Hash->new({});
my $book = Hash->new({id => 4, name => "Perl"});
new_from_keys
static method new_from_keys : void ($keys : string[], $value : object);
Creates a new hash with the keys $keys and the value $value shared by all keys, and returns the new hash.
Exceptions:
The keys $keys must be defined. Otherwise an exception is thrown.
π¦ Instance Methods π¦
copy
method copy : Hash ();
Creates a new Hash object, and copies the keys and values of the current hash to the new hash, and returns it.
This is not deep copy. The keys are got by keys method. The values are got by get method.
clone
method clone : Hash ();
The alias for copy method.
delete
method delete : element ($key : string);
Deletes the key and value given by the key $key.
The deleted value is returned.
Exceptions:
The key $key must be defined. Otherwise, an exception is thrown.
exists
method exists : int ($key : string);
Checks if the value specified by the key $key exists. If it exists, returns 1. Otherwise returns 0.
keys
method keys : string[] ();
Gets the keys in the hash. This method does not copy the strings.
values
method values : object[] ();
Gets all the values in the hash.
get
method get : element ($key : string);
Gets the value specified by the key $key, and returns it.
If the value does not exist, returns undef.
Exceptions:
The key $key must be defined. Otherwise, an exception is thrown.
weaken
method weaken : void ($key : string));
Enables a weaken reference of the field that stores the value specified by the key $key if the value exists.
Exceptions:
The key $key must be defined. Otherwise, an exception is thrown.
unweaken
method unweaken : void ($key : string);
Disables a weaken reference of the field that stores the value specified by the key $key if the value exists.
Exceptions:
The key $key must be defined. Otherwise, an exception is thrown.
isweak
method isweak : int ($key : string)
If the field that stores the value specified by the key $key is weakened, returns 1, otherwise returns 0.
Exceptions:
The key $key must be defined. Otherwise, an exception is thrown.
set
method set : void ($key : string, $value : object);
Sets $value to the hash by the key $key.
Exceptions:
The key $key must be defined. Otherwise, an exception is thrown.
to_array
method to_array : object[] ($sort : int = 0);
Converts all the key-value pairs in the hash to an array, and returns it.
If the option $sort is a positive value, the keys are sorted by ascendant order.
If the option $sort is a negative value, the keys are sorted by decendant order.
to_options
method to_options : object[] ($sort : int = 0);
Same as to_array method, but enables options flag using enable_options operator.
get_or_default
method get_or_default : element ($key : string, $default : object;
If the value specified by the key $key exists, this method calls get method, and returns the return value of get method.
If the value specified by the key $key does not exists, returns the default value $default.
merge
method merge : void ($hash : Hash);
Merges the hash $hash into the current hash.
merge_options
method merge_options : void ($options : object[]);
Merges the options $options into the current hash.
π Copyright & License π
Copyright (c) 2023 Yuki Kimoto
MIT License
And that's the whole manual, bestie. This page is from perl v5.42.2, dated 2026-02-03, and yes β it's literally SPVM::Hash(3). Periodt. π
β¨π«Ά
π¦ where this page comes from
- alpine 3.24: spvm-doc 0.990125-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms