view Lib/IMPL/Object.pm @ 59:0f3e369553bd

Rewritten property implementation (probably become slower but more flexible) Configuration infrastructure in progress (in the aspect of the lazy activation) Initial concept for the code generator
author wizard
date Tue, 09 Mar 2010 02:50:45 +0300
parents cf23fd8423f4
children 259cd3df6e53
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'
}

1;

__END__

=pod

=head1 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!

=head1 Description

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

=head1 Members

=over

=item operator C<new>(@args)

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

=item operator C<surrogate>()

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

=back

=head1 Cavearts

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

=cut