Mercurial > pub > Impl
comparison Lib/IMPL/Object/EventSource.pm @ 7:94d47b388442
Улучшены тесты
Исправлены ошибки
Улучшена документация
Работа над схемой DOM
| author | Sergey |
|---|---|
| date | Mon, 24 Aug 2009 01:05:34 +0400 |
| parents | 03e58a454b20 |
| children | 16ada169ca75 |
comparison
equal
deleted
inserted
replaced
| 6:e2cd73ccc5bd | 7:94d47b388442 |
|---|---|
| 49 | 49 |
| 50 my $globalEventTable = new IMPL::Object::EventSource::EventTable($fullEventName); | 50 my $globalEventTable = new IMPL::Object::EventSource::EventTable($fullEventName); |
| 51 | 51 |
| 52 no strict 'refs'; | 52 no strict 'refs'; |
| 53 *{"${class}::$event"} = sub { | 53 *{"${class}::$event"} = sub { |
| 54 my $class = shift; | 54 shift; |
| 55 if (not @_) { | 55 if (not @_) { |
| 56 if (not defined wantarray and caller(1) eq $class) { | 56 if (not defined wantarray and caller(1) eq $class) { |
| 57 $globalEventTable->Invoke($class); | 57 $globalEventTable->Invoke($class); |
| 58 } else { | 58 } else { |
| 59 return $globalEventTable; | 59 return $globalEventTable; |
| 60 } | 60 } |
| 61 } else { | 61 } else { |
| 62 $globalEventTable->Invoke(@_); | 62 $globalEventTable->Invoke($class,@_); |
| 63 } | 63 } |
| 64 }; | 64 }; |
| 65 } | 65 } |
| 66 | 66 |
| 67 package IMPL::Object::EventSource::EventTable; | 67 package IMPL::Object::EventSource::EventTable; |
| 129 sub Remove { | 129 sub Remove { |
| 130 my ($this,$id) = @_; | 130 my ($this,$id) = @_; |
| 131 return delete $this->{$Handlers}{$id}; | 131 return delete $this->{$Handlers}{$id}; |
| 132 } | 132 } |
| 133 1; | 133 1; |
| 134 | |
| 135 __END__ | |
| 136 =pod | |
| 137 =head1 SYNOPSIS | |
| 138 package Foo; | |
| 139 use base qw(IMPL::Object IMPL::Object::EventSource); | |
| 140 | |
| 141 # declare events | |
| 142 __PACKAGE__->CreateEvent('OnUpdate'); | |
| 143 __PACKAGE__->CreateStaticEvent('OnNewObject'); | |
| 144 | |
| 145 sub CTOR { | |
| 146 my $this = shift; | |
| 147 // rise static event | |
| 148 $this->OnNewObject(); | |
| 149 } | |
| 150 | |
| 151 sub Update { | |
| 152 my ($this,$val) = @_; | |
| 153 | |
| 154 // rise object event | |
| 155 $this->OnUpdate($val); | |
| 156 } | |
| 157 | |
| 158 package Bar; | |
| 159 | |
| 160 // subscribe static event | |
| 161 Foo->OnNewObject->Subscribe(sub { warn "New $_[0] created" } ); | |
| 162 | |
| 163 sub LookForFoo { | |
| 164 my ($this,$foo) = @_; | |
| 165 | |
| 166 // subscribe object event | |
| 167 $foo->OnUpdate->Subscribe($this,'OnFooUpdate'); | |
| 168 } | |
| 169 | |
| 170 // event handler | |
| 171 sub OnFooUpdate { | |
| 172 my ($this,$sender,$value) = @_; | |
| 173 } | |
| 174 | |
| 175 =head1 DESCRIPTION | |
| 176 . | |
| 177 . | |
| 178 . | |
| 179 , , . | |
| 180 | |
| 181 ( ) | |
| 182 . , | |
| 183 ( ). | |
| 184 , | |
| 185 . | |
| 186 | |
| 187 =head1 METHODS | |
| 188 =level 4 | |
| 189 =back | |
| 190 | |
| 191 =head1 EventTable | |
| 192 | |
| 193 =cut |
