Alter Perl class offers Alter Ego Objects.
Synopsis
package MyClass;
use Alter ego => {}; # Alter ego of type hash
# Put data in it
my $obj = do { my $o };
ego( $obj)->{a} = 1;
ego( $obj)->{b} = 2;
# Retrieve it again
print ego( $obj)->{ b}, "n"; # prints 2
package OtherClass;
defined( ego $obj) or die; # dies, OtherClass hasn't set an alter ego
# Direct access to the corona of alter egos
my $crown = Alter::corona $obj;
Functions
Basic Functions
The functions described here accept a first argument named $obj. Despite the name, $obj can be any reference, it doesn't have to be blessed (though it usually will be). It is a fatal error if it is not a reference or if the reference points to a read-only value.
ego($obj)
Retrieves the class-specific alter ego assigned to $obj by alter() or by autovivification if that is enabled. If neither is the case, an undefined value is returned. The class is the package into which the call to ego() is compiled.
alter($obj, $val)
Assigns $val to the reference $obj as an alter ego for the caller's class. The class is the package into which the call to alter is compiled. Returns $obj (not the value assigned).
Alter::corona( $obj)
Direct access to the corona of alter ego's of $obj. The corona is a hash keyed by class name in which the alter ego's of an object are stored. Unlike alter() and ego(), this function is not caller-sensitive. Returns a reference to the corona hash, which is created if necessary. This function is not exported, if needed it must be called fully qualified.
Alter::is_xs
Returns a true value if the XS implementation of Alter is active, false if the pure Perl fallback is in place.
Product's homepage