MCE::Sh...::Scalar(3)
β¨ NAME β¨
okay so this is the MCE::Sh...::Scalar(3) page from the User Contributed Perl Documentation, and itβs literally all about MCE::Shared::Scalar β a scalar helper class for use as a standalone or managed by MCE::Shared. Thatβs the vibe, bestie. π
πΈ VERSION πΈ
This document describes MCE::Shared::Scalar version 1.893. Write it down, no cap. π«Ά
π¦ DESCRIPTION π¦
A scalar helper class for use as a standalone or managed by MCE::Shared. Itβs giving exactly what it says on the tin, and honestly? Iconic. β¨
π SYNOPSIS π
bestie, here are the literal moves: non-shared or local construction for a single process, construction for sharing with other threads and processes, scalar-like dereferencing, the OO interface, and the included sugar methods. π
# non-shared or local construction for use by a single process
use MCE::Shared::Scalar;
my $var = MCE::Shared::Scalar->new( $val );
# construction for sharing with other threads and processes
use MCE::Shared;
my $var = MCE::Shared->scalar( $val );
# scalar-like dereferencing
my $val = ${ $var };
${ $var } = $val;
# OO interface
$val = $var->set( $val );
$val = $var->get();
$len = $var->len();
# included, sugar methods without having to call set/get explicitly
$val = $var->append( $string ); # $val .= $string
$val = $var->decr(); # --$val
$val = $var->decrby( $number ); # $val -= $number
$val = $var->getdecr(); # $val--
$val = $var->getincr(); # $val++
$val = $var->incr(); # ++$val
$val = $var->incrby( $number ); # $val += $number
$old = $var->getset( $new ); # $o = $v, $v = $n, $o
For normal scalar behavior, the TIE interface is supported. That part is important, bestie. π«Ά
# non-shared or local construction for use by a single process
use MCE::Shared::Scalar;
tie my $var, "MCE::Shared::Scalar";
# construction for sharing with other threads and processes
use MCE::Shared;
tie my $var, "MCE::Shared";
# usage
$var = 0;
tied($var)->incrby(20);
π API DOCUMENTATION π
This module may involve TIE when accessing the object via scalar dereferencing. Only shared instances are impacted if doing so. Although likely fast enough for many use cases, the OO interface is recommended for best performance. Periodt. π
π«Ά MCE::Shared::Scalar->new ( [ value ] )
π«Ά MCE::Shared->scalar ( [ value ] )
Constructs a new object. Its value is undefined when value is not specified. No value? No drama β itβs just undefined. π
# non-shared or local construction for use by a single process
use MCE::Shared::Scalar;
$var = MCE::Shared::Scalar->new( "foo" );
$var = MCE::Shared::Scalar->new;
# construction for sharing with other threads and processes
use MCE::Shared;
$var = MCE::Shared->scalar( "bar" );
$var = MCE::Shared->scalar;
π set ( value )
Preferably, set the value via the OO interface. Otherwise, TIE is activated on-demand for setting the value. The new value is returned in scalar context. β¨
$val = $var->set( "baz" );
$var->set( "baz" );
${$var} = "baz";
π¦ get
Likewise, obtain the value via the OO interface. TIE is utilized for retrieving the value otherwise. Got it? Get it? Slay. π
$val = $var->get;
$val = ${$var};
πΈ len
Returns the length of the value. It returns the undef value if the value is not defined. Length check, bestie. π
$len = $var->len;
length ${$var};
π SUGAR METHODS π
This module is equipped with sugar methods to not have to call set and get explicitly. In shared context, the benefit is atomicity and reduction in inter-process communication. The API resembles a subset of the Redis primitives at https://redis.io/commands#strings without the key argument. Itβs giving convenient, lowkey powerful, and highkey adorable. ππ₯
π§ append ( value )
Appends a value at the end of the current value and returns its new length. π
$len = $var->append( "foo" );
π§ decr
Decrements the value by one and returns its new value. π
$num = $var->decr;
π§ decrby ( number )
Decrements the value by the given number and returns its new value. π
$num = $var->decrby( 2 );
π§ getdecr
Decrements the value by one and returns its old value. Old value mains, honestly. β
$old = $var->getdecr;
π§ getincr
Increments the value by one and returns its old value. π¦
$old = $var->getincr;
π§ getset ( value )
Sets the value and returns its old value. Swap energy. π
$old = $var->getset( "baz" );
π§ incr
Increments the value by one and returns its new value. π₯
$num = $var->incr;
π§ incrby ( number )
Increments the value by the given number and returns its new value. β¨
$num = $var->incrby( 2 );
π CREDITS π
The implementation is inspired by Tie::StdScalar. Credit where credit is due, bestie. π
π INDEX π
MCE, MCE::Hobo, MCE::Shared. Index drip check: passed. β
π AUTHOR π
Mario E. Roy, <marioeroy AT gmail DOT com>. Author icon behavior. ππ
okay bestie, thatβs the whole page. Footer vibe check: perl v5.40.0, dated 2024-09-10, and the page tag is MCE::Sh...::Scalar(3). Stay slay and may your scalar helper class always be exactly as standalone or shared as you need it to be. π
β¨π
π¦ where this page comes from
- epel 10: perl-MCE-Shared 1.893-1.el10_0 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms