Commit 1bf38d08d77d9570389ef45a07ae410c8d21b9ad
- Diff rendering mode:
- inline
- side by side
lib/Reflex/Role/Object.pm
(9 / 0)
|   | |||
| 365 | 365 | # Find all relevant methods in the obsever, and explicitly observe | |
| 366 | 366 | # the corresponding events. Heavy at setup, but light while | |
| 367 | 367 | # running. | |
| 368 | # | ||
| 369 | # TODO - We can probably optimize this. The methods shouldn't | ||
| 370 | # change often. Can we cache the methods and invalidate the cache | ||
| 371 | # at the proper times? | ||
| 368 | 372 | ||
| 369 | 373 | foreach my $callback ( | |
| 370 | 374 | grep /^on_${role}_\S+$/, | |
| … | … | ||
| 390 | 390 | sub emit { | |
| 391 | 391 | my ($self, @args) = @_; | |
| 392 | 392 | ||
| 393 | # TODO - Checking arguments is tedious, but _check_args() method | ||
| 394 | # calls add up. | ||
| 395 | |||
| 393 | 396 | my $args = $self->_check_args( | |
| 394 | 397 | \@args, | |
| 395 | 398 | [ 'event' ], | |
| … | … | ||
| 403 | 403 | my $callback_args = $args->{args} || {}; | |
| 404 | 404 | ||
| 405 | 405 | # Look for self-handling of the event. | |
| 406 | # TODO - can() calls are also candidates for caching. | ||
| 406 | 407 | ||
| 407 | 408 | if ($self->can("on_my_$event")) { | |
| 408 | 409 | my $method = "on_my_$event"; | |
| … | … | ||
| 418 | 418 | ); | |
| 419 | 419 | ||
| 420 | 420 | # This event is observed. Broadcast it to observers. | |
| 421 | # TODO - Accessor calls are expensive. Optimize them away. | ||
| 421 | 422 | ||
| 422 | 423 | while ( | |
| 423 | 424 | my ($observer, $callbacks) = each %{$self->watchers_by_event()->{$event}} |

