view Lib/IMPL/Object.pm @ 31:d59526f6310e

Small fixes to Test framework (correct handlinf of the compilation errors in the test units) Imported and refactored SQL DB schema from the old project
author Sergey
date Mon, 09 Nov 2009 01:39:16 +0300
parents e59f44f75f20
children 16ada169ca75
line wrap: on
line source

package IMPL::Object;
use strict;

use base qw(IMPL::Object::Abstract);

sub surrogate {
    bless {}, ref $_[0] || $_[0];
}

sub new {
    my $class = shift;
    my $self = bless {}, ref($class) || $class;    
    $self->callCTOR(@_);
  
    $self;
}

sub _PropertyImplementor {
    'IMPL::Class::Property::Direct'
}

=pod
=h1 SYNOPSIS

package Foo;
use base qw(IMPL::Object);

sub CTOR {
    my ($this,$arg) = @_;
    print "Foo: $arg\n";
}

package Bar;
use base qw(IMPL::Object);

sub CTOR {
    my ($this,$arg) = @_;
    print "Bar: $arg\n";
}

package Baz;
use base qw(Foo Bar);

our %CTOR = (
    Foo => sub { my %args = @_; $args{Mazzi}; },
    Bar => sub { my %args = @_; $args{Fugi}; }
);

package Composite;
use base qw(Baz Foo Bar);

our %CTOR = (
    Foo => undef,
    Bar => undef
);

sub CTOR {
    my ($this,%args) = @_;
    
    print "Composite: $args{Text}\n";
}

package main;

my $obj = new Composite(
    Text => 'Hello World!',
    Mazzi => 'Mazzi',
    Fugi => 'Fugi'
);

# will print
#
# Foo: Mazzi
# Bar: Fugi
# Bar:
# Composite: Hello World!

=h1 Description
Базовый класс для объектов, основанных на хеше.

=h1 Members

=level 4

=item operator C<new>(@args)

Создает экземпляр объекта и вызывает конструктор с параметрами @args.

=item operator C<surrogate>()

Создает неинициализированный экземпляр объекта.

=back

=р1 Cavearts

Нужно заметить, что директива C<use base> работает не совсем прозрачно, если в нашем примере
класс C<Composite> наследуется от C<Baz>, а затем C<Foo>, то наследование от
C<Foo> не произойдет поскольку он уже имеется в C<Baz>. Вот не задача:)

=cut

1;