MCE::Shared::Scalar - Scalar helper class
This document describes MCE::Shared::Scalar version 1.699_012
# non-shared use MCE::Shared::Scalar; my $var = MCE::Shared::Scalar->new( $val ); # shared use MCE::Shared; my $var = MCE::Shared->scalar( $val ); # oo interface $val = $var->set( $val ); $val = $var->get(); $len = $var->len(); # 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
Helper class for MCE::Shared.
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, use the OO interface if better performance is desired.
Constructs a new object. Its value is undefined when value is not specified.
value
# non-shared use MCE::Shared::Scalar; $var = MCE::Shared::Scalar->new( "foo" ); $var = MCE::Shared::Scalar->new; # shared use MCE::Shared; $var = MCE::Shared->scalar( "bar" ); $var = MCE::Shared->scalar;
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.
TIE
$val = $var->set( "baz" ); $var->set( "baz" ); ${$var} = "baz";
Likewise, obtain the value via the OO interface. TIE is utilized for retrieving the value otherwise.
$val = $var->get; $val = ${$var};
Returns the length of the value. It returns the undef value if the value is not defined.
undef
$len = $var->len; length ${$var};
This module is equipped with sugar methods to not have to call set and get explicitly. The API resembles a subset of the Redis primitives http://redis.io/commands#strings without the key argument.
set
get
Appends a value at the end of the current value and returns its new length.
$len = $var->append( "foo" );
Decrements the value by one and returns its new value.
$num = $var->decr;
Decrements the value by the given number and returns its new value.
$num = $var->decrby( 2 );
Decrements the value by one and returns its old value.
$old = $var->getdecr;
Increments the value by one and returns its old value.
$old = $var->getincr;
Sets the value and returns its old value.
$old = $var->getset( "baz" );
Increments the value by one and returns its new value.
$num = $var->incr;
Increments the value by the given number and returns its new value.
$num = $var->incrby( 2 );
The implementation is inspired by Tie::StdScalar.
MCE, MCE::Core, MCE::Shared
Mario E. Roy, <marioeroy AT gmail DOT com>
To install MCE, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MCE
CPAN shell
perl -MCPAN -e shell install MCE
For more information on module installation, please visit the detailed CPAN module installation guide.