NAME

Trinket::Object - Base class for persistent objects managed by Trinket::Directory

SYNOPSYS

{
  package TestObject;

  BEGIN
    {
      our $VERSION      = "0.0";
      our @ISA          = qw( Trinket::Object );
      our $DESCRIPTION  = 'Test object class';
      our %PROPERTIES   =
        (
          ### name => [ type, indexed, desc ]
          mung       => [ 'char', 1, 'Mung'     ],
          bar        => [ 'char', 1, 'Bar'      ],
          baz        => [ 'char', 0, 'Baz'      ],
        );
    }

  use Trinket::Object;
}

$obj = new TestObject({ mung => 'mung_value' });

$obj->add_property( name => 'char', 0, 'The xzzxy property' );

$obj->set_name('value');

$obj->set(name=>'value');

$obj->set(id=>'1',name=>'value',...);

$val = $obj->get_name();

$val = $obj->get('name');

@vals = $obj->get('id','name');

$obj->add_property(foo=>'char',0,'Foo property');

$obj->remove_property('foo');

DESCRIPTION

Trinket::Object is the base class for all classes whose instances are intended to be managed by Trinket::Directory.

This base class serves several purposes: A mechanism is specified by which object data properties are described; accessor (get_*) and mutator (set_*) methods are automatically generated; changes in properties are tracked to facilitate object storage and indexing

The intent is to both serve as a convenient base class, as well as provide means of interrogation to Trinket::Directory so that the object can be managed transparently without any knowledge about the directory in the object itself. This should allow the object to be managed by any directory.

EXPORTS

CONSTANTS

  • META_TYPES - List of datatypes supported by object properties

  • META_PROP_TYPE - Property metadata spec index to the data type of the property. See: add_property()

  • META_PROP_INDEXED - Property metadata spec index to a 0/1 flag indicating whether the property should be indexed. See: add_property()

  • META_PROP_DESC - Property metadata spec index to the text description of the property. See: add_property()

  • DIRTY_OLD_VALUE - See:

  • DIRTY_NEW_VALUE

TODO

METHODS

$obj = new Trinket::Object({prop1=>'val1'});

Object constructor, accepts a hashref of named properties with which to initialize the object. In initialization, the object's set methods are called for each of initializing properties passed. '

$obj->init({prop=>$value, prop2=>$value2, ...});
$obj->init(prop=>$value, prop2=>$value2, ...);

Object initializer, called by new() with the initializing parameters sent to it. In the base class, this initializer iterates through each of the properties supplied and calls the appropriate mutator to set the value.

This method never needs to be called directly, but it can be overridden in subclasses.

AUTOLOAD

The AUTOLOAD method of this class automatically generates mutator and accessor methods on demand if they do not already exist. These methods each take the form of get_foo() and set_foo($value) where foo is the name of an object property. If a method matching this pattern already exists, AUTOLOAD will not be called, and will not overwrite it.

import

The import method of this base class facilitates the inheritance of class metadata. When a subclass is created, the list of properties and other class definition data will be merged into the subclass' own metadata. '

$obj->set(name=>'value');

In addition to auto-generated property mutators, set() is a generic mutator which can be used to set properties by name, and to set more than one in a single method call.

Note that this method accesses object property data directly, and does not call any overridden mutators in a subclass. Because of this, this method should only be used in overriding mutators and possibly object directory data access backends.

$val = $obj->get('name');

In addition to auto-generated property accessors, get() is a generic mutator which can be used to get properties by name, and to get more than one in a single method call.

Note that this method accesses object property data directly, and does not call any overridden accessors in a subclass. Because of this, this method should only be used in overriding accessors and possibly object directory data access backends.

$obj->has_property('name')

Tests whether an object has a given property.

$obj->type_property('name')

Query the data type for a given property

$obj->describe_property('name')

Query the data type for a given property

$obj->add_property(name=>'type',0,'Description');

Add a property to the object. The new property will be available to get and set methods, and will be handled by the object directory.

The metadata supplied are the property name, whether the property should be indexed (0/1), and a description of the property.

$obj->remove_property('prop_name');

Remove a named property from the object. After deletion, it will no longer be recognized as a property to set or get, and will not be used by the object directory in any operations.

$obj->list_properties();

Return a list of properties in the object.

$obj->list_indices();

Return a list of indexed properties in the object.

AUTHOR

Maintained by Leslie Michael Orchard <deus_x@pobox.com>

COPYRIGHT

Copyright (c) 2000, Leslie Michael Orchard. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.