Hash::SharedMem::Handle - handle for efficient shared mutable hash
use Hash::SharedMem::Handle; $shash = Hash::SharedMem::Handle->open($filename, "rwc"); if($shash->is_readable) { ... if($shash->is_writable) { ... $mode = $shash->mode; if($shash->getd($key)) { ... $value = $shash->get($key); $shash->set($key, $newvalue); $oldvalue = $shash->gset($key, $newvalue); if($shash->cset($key, $chkvalue, $newvalue)) { ... $snap_shash = $shash->snapshot; if($shash->is_snapshot) { ... tie %shash, "Hash::SharedMem::Handle", $shash; tie %shash, "Hash::SharedMem::Handle", $filename, "rwc"; if(exists($shash{$key})) { ... $value = $shash{$key}; $shash{$key} = $newvalue; $oldvalue = delete($shash{$key});
An object of this class is a handle referring to a memory-mapped shared hash object of the kind described in Hash::SharedMem. It can be passed to the functions of that module, or the same operations can be performed by calling the methods described below. Uses of the function and method interfaces may be intermixed arbitrarily; they are completely equivalent in function. They are not equivalent in performance, however, with the method interface being somewhat slower.
This class also supplies a tied-hash interface to shared hashes. As seen through the tied interface, the values in a shared hash can only be octet (Latin-1) strings. The tied interface is much slower than the function and method interfaces.
Opens and return a handle referring to a shared hash object, or dies if the shared hash can't be opened as specified. See "shash_open" in Hash::SharedMem for details.
die
These methods are each equivalent to the corresponding "shash_"-prefixed function in Hash::SharedMem. See that document for details.
shash_
VARIABLE must be a hash variable, and SHASH must be a handle referring to a shared hash object. The call binds the variable to the shared hash, so that the variable provides a view of the shared hash that resembles an ordinary Perl hash. The shared hash handle is returned.
VARIABLE must be a hash variable. The call opens a handle referring to a shared hash object, as described in "shash_open" in Hash::SharedMem, and binds the variable to the shared hash, so that the variable provides a view of the shared hash that resembles an ordinary Perl hash. The shared hash handle is returned.
Returns a truth value indicating whether the specified key is currently present in the shared hash.
Returns the value currently referenced by the specified key in the shared hash, or undef if the key is absent.
undef
Modifies the shared hash so that the specified key henceforth references the specified value. The new value must be a string.
Modifies the shared hash so that the specified key is henceforth absent, and returns the value that the key previously referenced, or undef if the key was already absent. This swap is performed atomically.
Setting the entire contents of the shared hash (throwing away the previous contents) is not supported.
Iteration over, or enumeration of, the shared hash's contents is not supported.
Checking whether the shared hash is occupied is not supported.
Due to details of the Perl implementation, this object-oriented interface to the shared hash mechanism is somewhat slower than the function interface, and the tied interface is much slower. The functions in Hash::SharedMem are the recommended interface.
Hash::SharedMem
Andrew Main (Zefram) <zefram@fysh.org>
Copyright (C) 2014 PhotoBox Ltd
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Hash::SharedMem, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hash::SharedMem
CPAN shell
perl -MCPAN -e shell install Hash::SharedMem
For more information on module installation, please visit the detailed CPAN module installation guide.