Matthew Simon Cavalletto

NAME

Class::MakeMethods::Template::Flyweight - Method interfaces for flyweight objects

SYNOPSIS

  package MyObject;
  use Class::MakeMethods::Template::Flyweight (
    new             => [ 'new' ]
    scalar          => [ 'foo', 'bar' ]
  );
  
  package main;

  my $obj = MyObject->new( foo => "Foozle", bar => "Bozzle" );
  print $obj->foo();            # Prints Foozle
  $obj->bar("Bamboozle");       # Sets $obj->{bar}

DESCRIPTION

Supports the Generic object constructor and accessors meta-method types, but uses scalar refs as the underlying implementation type, with member data stored in external indices.

Each method stores the values associated with various objects in an hash keyed by the object's stringified identity. Since that hash is accessible only from the generated closures, it is impossible for foreign code to manipulate those values except through the method interface. (Caveat: the _flyweight_class_info class method currently exposes the meta-method information; this method should become private RSN.) A DESTROY method is installed to call the _destroy_flyweight_info method, removing data for expired objects from the various hashes, or you can call the _destroy_flyweight_info method from your own DESTROY method.

Common Parameters: The following parameters are defined for Flyweight meta-methods.

data

An auto-vivified reference to a hash to be used to store the values for each object.

Note that using Flyweight meta-methods causes the installation of a DESTROY method in the calling class, which deallocates data for each instance when it is discarded.

NOTE: This needs some more work to properly handle inheritance.

new

Creates a new scalar ref object.

See the documentation on Scalar:new for interfaces and behaviors.

scalar

Creates flyweight accessor methods which will store a scalar value for each instance.

See the documentation on Generic:scalar for interfaces and behaviors.

boolean_index

  boolean_index => [ qw / foo bar baz / ]

Like Flyweight:boolean, boolean_index creates x, set_x, and clear_x methods. However, it also defines a class method find_x which returns a list of the objects which presently have the x-flag set to true.

Note that to free items from memory, you must clear these bits!

array

Creates flyweight accessor methods which will store an array-ref value for each instance.

See the documentation on Generic:array for interfaces and behaviors.

hash

Creates flyweight accessor methods which will store a hash-ref value for each instance.

See the documentation on Generic:hash for interfaces and behaviors.

code

Creates flyweight accessor methods which will store a subroutine reference for each instance.

See the documentation on Generic:code for interfaces, behaviors, and parameters.

bits

NEEDS TESTING

instance

NEEDS TESTING