Class::MakeMethods::Template::Flyweight - Method interfaces for flyweight objects
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}
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.
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.
Creates a new scalar ref object.
See the documentation on Scalar:new for interfaces and behaviors.
Scalar:new
Creates flyweight accessor methods which will store a scalar value for each instance.
See the documentation on Generic:scalar for interfaces and behaviors.
Generic:scalar
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!
Creates flyweight accessor methods which will store an array-ref value for each instance.
See the documentation on Generic:array for interfaces and behaviors.
Generic:array
Creates flyweight accessor methods which will store a hash-ref value for each instance.
See the documentation on Generic:hash for interfaces and behaviors.
Generic:hash
Creates flyweight accessor methods which will store a subroutine reference for each instance.
See the documentation on Generic:code for interfaces, behaviors, and parameters.
Generic:code
NEEDS TESTING
To install Class::MakeMethods::Template, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::MakeMethods::Template
CPAN shell
perl -MCPAN -e shell install Class::MakeMethods::Template
For more information on module installation, please visit the detailed CPAN module installation guide.