NAME

Class::MakeMethods::Template::Ref - Universal copy and compare methods

SYNOPSIS

package MyObject;
use Class::MakeMethods::Template::Ref (
  'Hash:new'      => [ 'new' ],
  clone           => [ 'clone' ]
);

package main;

my $obj = MyObject->new( foo => ["Foozle", "Bozzle"] );
my $clone = $obj->clone();
print $obj->{'foo'}[1];

DESCRIPTION

The following types of methods are provided via the Class::MakeMethods interface:

clone

Produce a deep copy of an instance of almost any underlying datatype.

Parameters:

init_method

If defined, this method is called on the new object with any arguments passed in.

prototype

Create new instances by making a deep copy of a static prototypical instance.

Parameters:

init_method

If defined, this method is called on the new object with any arguments passed in.

compare

Compare one object to another.

Templates

  • default

    Three-way (sorting-style) comparison.

  • equals

    Are these two objects equivalent?

  • identity

    Are these two references to the exact same object?

INTERNALS

The following functions are used by the above method types.

_clone()

Make a recursive copy of a reference.

_compare()

Attempt to recursively compare two references.

If they are not the same, try to be consistent about returning a positive or negative number so that it can be used for sorting. The sort order is kinda arbitrary.

SEE ALSO

See Class::MakeMethods for a reference to the internals of the Class::MakeMethods framework.

See Ref for the original version of the clone and compare functions used above.

See Clone (v0.09 on CPAN as of 2000-09-21) for a clone method with an XS implementation.

The Perl6 RFP #67 proposes including clone functionality in the core.

See Data::Compare (v0.01 on CPAN as of 1999-04-24) for a Compare method which checks two references for similarity, but it does not provide positive/negative values for ordering purposes.

See Class::MakeMethods::ReadMe for distribution and support information.

LICENSE

Copyright 1998, 2000, 2001 Evolution Online Systems, Inc.

M. Simon Cavalletto, simonm@evolution.com

Derived in part from Ref.pm, Copyright 1994, David Muir Sharnoff.