Mercurial > pub > Impl
diff Lib/IMPL/Object/EventSource.pm @ 7:94d47b388442
Улучшены тесты
Исправлены ошибки
Улучшена документация
Работа над схемой DOM
author | Sergey |
---|---|
date | Mon, 24 Aug 2009 01:05:34 +0400 |
parents | 03e58a454b20 |
children | 16ada169ca75 |
line wrap: on
line diff
--- a/Lib/IMPL/Object/EventSource.pm Fri Aug 14 16:14:13 2009 +0400 +++ b/Lib/IMPL/Object/EventSource.pm Mon Aug 24 01:05:34 2009 +0400 @@ -51,7 +51,7 @@ no strict 'refs'; *{"${class}::$event"} = sub { - my $class = shift; + shift; if (not @_) { if (not defined wantarray and caller(1) eq $class) { $globalEventTable->Invoke($class); @@ -59,7 +59,7 @@ return $globalEventTable; } } else { - $globalEventTable->Invoke(@_); + $globalEventTable->Invoke($class,@_); } }; } @@ -131,3 +131,63 @@ return delete $this->{$Handlers}{$id}; } 1; + +__END__ +=pod +=head1 SYNOPSIS +package Foo; +use base qw(IMPL::Object IMPL::Object::EventSource); + +# declare events +__PACKAGE__->CreateEvent('OnUpdate'); +__PACKAGE__->CreateStaticEvent('OnNewObject'); + +sub CTOR { + my $this = shift; + // rise static event + $this->OnNewObject(); +} + +sub Update { + my ($this,$val) = @_; + + // rise object event + $this->OnUpdate($val); +} + +package Bar; + +// subscribe static event +Foo->OnNewObject->Subscribe(sub { warn "New $_[0] created" } ); + +sub LookForFoo { + my ($this,$foo) = @_; + + // subscribe object event + $foo->OnUpdate->Subscribe($this,'OnFooUpdate'); +} + +// event handler +sub OnFooUpdate { + my ($this,$sender,$value) = @_; +} + +=head1 DESCRIPTION + . +. + . + , , . + + ( ) +. , + ( ). + , + . + +=head1 METHODS +=level 4 +=back + +=head1 EventTable + +=cut \ No newline at end of file