Method
schema( $oref )
Determines the "Tangram::Schema" representation of a "use class" including the complete inhereted objects.
Constructing Tangram Schema WHEN WE HAVE TO DEPLOY (first time registering persistance).
schema() scans recursivle through the inheritance tree and creates all parent schemas also (Cave: You should
configure tangram also via the "persistance =>" key in your class.
For comulative schema (incl. "User"`s parent "Human" class) ,+ the non-inheritated "UserGroup" Class::Maker::
schema( 'User' , 'UserGroup' );
For single schema:
User->schema(); #(incl. "User"`s parent "Human" class)
or
UserGroup->schema; # no isa, no parent class schema`s !
NAME
Class::Maker::Extension::Schema - classes, reflection, schema, serialization, attribute inheritance and multiple inheritance
SYNOPSIS
use Class::Maker qw(class);
class UnixUser, { #You can use "." or "*" as a placeholder for the current package
isa => [qw( .ParentClassA ParentClassB )],
attribute =>
{
int => [qw(uid gid)],
string => [qw(name lastname)],
ref => [qw(father mother)],
array => [qw(friends)],
custom => [qw(anything)],
}
configure =>
{
# Future: also allow: ctor or dtor => $coderef
ctor => 'makenew',
explicit => 0,
},
};
sub UnixUser::hello : method { my $this = shift;
printf 'This is %s (%d)', $this->name, $this->uid;
return 1; }
my $a = UnixUser->new( uid => 1, gid => 2, name => Murat );
$a->father( UnixUser->new( name => Suleyman ) );
$a->hello();
$a->uid = 12;
DESCRIPTION
Class::Maker introduces the concept of classes via a "class" function. It automatically creates packages, ISA, new and attribute-handlers. The classes can inherit from common perl-classes and class-maker classes. Single and multiple inheritance is supported.
This package is for everybody who wants to program oo-perl and does not really feel comfortable with the common way.
Java-like reflection is also implemented and allows one to inspect the class properties and methods during runtime. This is helpfull for implementing persistance and serialization. A Tangram (see cpan) schema generator is included to the package, so one can use Tangram object-persistance on the fly as long as he uses Class::Maker classes.
INTRODUCTION
When you want to program oo-perl, mostly you suffer under the flexibility of perl. It is so flexibel, you have to do alot by hand. Here an example (slightly modified) from perltoot perl documentation for demonstration:
package Person;
@ISA = qw(Something);
sub new { my $self = {}; $self->{NAME} = undef; $self->{AGE} = undef; bless($self); # but see below return $self; }
sub name { my $self = shift; if (@_) { $self->{NAME} = shift } return $self->{NAME}; }
sub age { my $self = shift; if (@_) { $self->{AGE} = shift } return $self->{AGE}; }
After using cpan modules for some time, i felt still very uncomfortable because i am used to c++ which has really straightforward class decleration style. It looks really beautiful. I love good looking syntax. So i have written a "class" function which <easily> creates perl classes. And i want it to be smoothly integrated into perl code with comprehensive handling of package issues etc:
use Class::Maker qw(class);
class Person, { isa => [ Something ],
attributes =>
{
scalar => [qw( name age )],
},
};
When using "class", you do not explictly need "package". The function does all symbol creation for you. It is more a class decleration (like in java/cpp/..):