Tangram::Type::Extending 2.10 review
DownloadTangram::Type::Extending is a Perl module for teaching Tangram about new types. Tangram::Type is the root of a hierarchy of classe
|
|
Tangram::Type::Extending is a Perl module for teaching Tangram about new types.
Tangram::Type is the root of a hierarchy of classes that are responsible mapping individual field to SQL entities (columns in the simplest cases). There is one Type object per persistent field.
Adding support for new types amounts to adding subclasses to Tangram::Type.
WRITING NEW TYPES
Tangram is organized in several subsystems, described below.
Schema is the repository for information about all the persistent aspects of a system: classes, inheritance relationships, fields, etc. It also contains graph-traversal algorithms, which are not currently documented.
Storage deals with objects as a whole: insertion, updating, multiple load detection, cycle handling, transactions, connections. It also serves as an entry point in the system. Storage does not manipulate fields directly.
Cursor deals with polymorphic retrieval of objects. It builds SELECT statements on the basis of the information in the hash. Cursor does not manipulate fields directly either.
The Type hierarchy deals with individual fields, and not with entire objects. More about it in a moment.
The Expr hierarchy deals with entities on the remote side; this includes expressions proper, Filters and Remotes.
Types are responsible for performing the mapping between a field of a given Perl type and a relational entity. The simplest Types merely transfer between one Perl field and one column. Sometimes it makes sense to have several mappings (and hence several Types) for the same Perl type; for example, Perl arrays can be mapped either using a link table, or one or several columns that live on the element's table.
Users don't deal with Type objects directly: they indicate that a series of fields should be mapped in a certain way by putting the fields under a given 'typetag' in the field hash. The type registers itself with Tangram by adding a typetag in the %Tangram::Schema::TYPES hash. The value is the Type object. Up to now all Types have been singletons, but this is not a rule.
Anybody who's planning to write new Types should examine Scalar.pm first. It contains very simple mappings between one field and one column.
A Type must implement the methods described below. Keep the following facts in mind while reading further:
1. A Type is responsible for transfering all the *direct* fields for a given *class*. This excludes inherited fields. OTOH, the same Type can be called more than once for the same object, because the same Type may be used in several classes that appear in a particular object's inheritance graph.
Requirements:
Perl
Tangram::Type::Extending 2.10 search tags