view _test/Test/ORM/Schema.pm @ 28:6d33f75c6e1f

ORM in works
author Sergey
date Mon, 19 Oct 2009 04:13:54 +0400
parents
children dd4d72600c69
line wrap: on
line source

package Test::ORM::Schema;
use strict;
use warnings;

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();

package Test::ORM::Schema::Data::User;
use base qw(IMPL::ORM::Object);
use IMPL::Class::Property;

BEGIN {
    public property Name => prop_all, { type => 'String' }; # Field
    public property Id => prop_all, { type => 'String' }; # Field
    public property Roles => prop_all | prop_list, { type=> 'Test::ORM::Schema::Data::Role'}; # HasMany
}

package Test::ORM::Schema::Data::Role;
use base qw(IMPL::ORM::Object);
use IMPL::Class::Property;

BEGIN {
    public property Name => prop_all, { type => 'String' }; # Field
}

package Test::ORM::Schema::Data::Session;
use base qw(IMPL::ORM::Object);
use IMPL::Class::Property;
use IMPL::ORM::Helpers qw(Map);

BEGIN {
    public property Id => prop_get, { type => 'String' }; # Field
    public property User => prop_get, { type => 'Test::ORM::Schema::Data::User' }; # HasOne
    public property Data => prop_all, { type => Map( 'String','String' ) }; # HasOne
    public property AccessTime => prop_get { type => 'DateTime' }; # Field
}

package Test::ORM::Schema::Data;
use base qw(IMPL::ORM::Schema);

__PACKAGE__->usePrefix(__PACKAGE__);
__PACKAGE__->Classes qw(
    User
    Role
    Session
);

__PACKAGE__->ValueTypes (
    'String' => 'IMPL::ORM::Value::String',
    'DateTime' => 'IMPL::ORM::Value::DateTime',
    'Integer' => 'IMPL::ORM::Value::Inetger',
    'Float' => 'IMPL::ORM::Value::Float',
    'Decimal' => 'IMPL::ORM::Value::Decimal'
);

1;