Mercurial > pub > Impl
view Lib/IMPL/Object.pm @ 4:e59f44f75f20
DOM - в разработке
Testing - по мелочи
Property - изменен механизм выбора имплементора
author | Sergey |
---|---|
date | Wed, 12 Aug 2009 17:36:07 +0400 |
parents | 78cd38551534 |
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;