Name : perl-Class-Tangram
| |
Version : 1.570.0
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : 1.4
| Date : 2024-03-08 00:20:41
|
Group : Unspecified
| Source RPM : perl-Class-Tangram-1.570.0-1.4.src.rpm
|
Size : 0.12 MB
| |
Packager : (none)
| |
Summary : Tangram-friendly classes, DWIM attributes
|
Description :
Class::Tangram is a tool for defining objects attributes. Simply define your object\'s fields/attributes using the same data structure introduced in _A Guided Tour of Tangram_ (see SEE ALSO) and detailed in Tangram::Schema, and you get objects that work As You\'d Expect(tm).
Class::Tangram has no dependancy upon Tangram, and vice versa. Neither requires anything special of your objects, nor do they insert any special fields into your objects. This is a very important feature with innumerable benefits, and few (if any) other object persistence tools have this feature.
So, fluff aside, let\'s run through how you use Class::Tangram to make objects.
First, you decide upon the attributes your object is going to have. You might do this using UML, or you might pick an existing database table and declare each column to be an attribute (you can leave out \"id\"; that one is implicit; also, leave out foreign keys until later).
Your object should use Class::Tangram as a base class;
use base qw(Class::Tangram)
or for older versions of perl:
use Class::Tangram; use vars qw(AATTISA); AATTISA = qw(Class::Tangram)
You should then define a \'$fields\' variable in the scope of the package, that is a *hash* from attribute *types* (see Tangram::Type) to either an *array* of *attribute names*, or another *hash* from *attribute names* to *options hashes* (or \'undef\'). The layout of this structure coincides exactly with the \'fields\' portion of a tangram schema (see Tangram::Schema), though there are some extra options available.
This will hereon in be referred to as the `object schema\' or just `schema\'.
For example,
package Orange; use base qw(Class::Tangram);
our $fields = { int => { juiciness => undef, segments => { check_func => sub { die \"too many segments\" if (${(shift)} > 30); }, init_default => 7, }, }, ref => { grower => { }, },
string => { type => { required => 1 },
tag => { required => \'\' }, },
transient => [ qw(_tangible) ], };
It is of critical importance to your sanity that you understand how anonymous hashes and anonymous arrays work in Perl. Some additional features are used above that have not yet been introduced, but you should be able to look at the above data structure and see that it satisfies the conditions stated in the paragraph before it. If it is hazy, I recommend reading perlref or perlreftut.
When the schema for the object is first imported (see Schema import), Class::Tangram defines accessor functions for each of the attributes defined in the schema. These accessor functions are then available as \'$object->function\' on created objects. By virtue of inheritance, various other methods are available.
From Class::Tangram 1.12 onwards, perl\'s \'AUTOLOAD\' feature is not used to implement accessors; closures are compiled when the class is first used.
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl/openSUSE_Tumbleweed/noarch |