Alter

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        use Alter ego => {};

    imports the "ego()" function and specifies a hash tape for
    autovivification. With autovivification you will usually not need to
    import the "alter" function at all.

    Specifying "NOAUTO" in place of a type specification switches
    autovivification off for the current class. This is also the default.

   Serialization Support
    Serialization is supported for human inspection in "Data::Dumper" style
    and for disk storage and cloning in "Storable" style.

    For "Data::Dumper" support "Alter" provides the class "Alter::Dumper"
    for use as a base class, which contains the single method "Dumper".
    "Dumper" returns a string that represents a hash in "Data::Dumper"
    format. The hash shows all *alter ego*s that have been created for the
    object, keyed by class. An additional key "(body)" (which can't be a
    class name) holds the actual body of the object. Formatting- and other
    options of "Data::Dumper" will change the appearance of the dump string,
    with the exception of $Data::Dumper::Purity, which will always be 1.
    "Dumper" can also be imported from "Alter" directly.

    Note that "eval()"-ing a dump string will *not* restore the object, but
    rather create a hash as described. Re-creation of an object is only
    available through "Storable".

    For "Storable" support the class "Alter::Storable" is provided with the
    methods "STORABLE_freeze", "STORABLE_thaw" and "STORABLE_attach". The
    three functions are also exported by "Alter" Their interaction with
    "Storable" is described there.

t/03_class.t  view on Meta::CPAN


# Class_A is a conventional hash-based class with two fields one_A and two_A
# Class_B is an Alter-based class with fields of one_B and two_B stored in an
# array.
# Both classes have an init() method that works as a creator when called
# as a class method. There are read-only accessors to the fields

# Class_C is a hybrid class inheriting both Class_A and Class_B
# For tests we set fields one_A and one_B to plain scalars.  two_A
# and two_B are set to hold a reference to the same array.  This identity
# must survive a freeze-thaw cycle by either Data::Dumper or Storable

### Class_A

{
    package Class_A;

    sub init {
        my $obj = shift;
        $obj = bless {}, $obj unless ref $obj;
        $obj->{ one_A} = shift;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.339 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )