mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-11 12:32:37 +01:00
EventDispatcher: clean up comments
This commit is contained in:
parent
170db378c6
commit
479212b234
@ -72,14 +72,14 @@ sub dispatch_event {
|
|||||||
# debugging flag
|
# debugging flag
|
||||||
my $debug = $self->{pbot}->{registry}->get_value('eventdispatcher', 'debug') // 0;
|
my $debug = $self->{pbot}->{registry}->get_value('eventdispatcher', 'debug') // 0;
|
||||||
|
|
||||||
# event handler return value
|
# undef means no handlers have handled this event
|
||||||
my $dispatch_result= undef;
|
my $dispatch_result= undef;
|
||||||
|
|
||||||
# if the event-name has handlers
|
# if the event-name has handlers
|
||||||
if (exists $self->{handlers}->{$event_name}) {
|
if (exists $self->{handlers}->{$event_name}) {
|
||||||
# then dispatch the event to each one
|
# then dispatch the event to each one
|
||||||
foreach my $handler_id (keys %{$self->{handlers}->{$event_name}}) {
|
foreach my $handler_id (keys %{$self->{handlers}->{$event_name}}) {
|
||||||
# event handler subref
|
# get event handler subref
|
||||||
my $subref = $self->{handlers}->{$event_name}->{$handler_id};
|
my $subref = $self->{handlers}->{$event_name}->{$handler_id};
|
||||||
|
|
||||||
# debugging
|
# debugging
|
||||||
@ -87,28 +87,23 @@ sub dispatch_event {
|
|||||||
$self->{pbot}->{logger}->log("Dispatching $event_name to handler $handler_id\n");
|
$self->{pbot}->{logger}->log("Dispatching $event_name to handler $handler_id\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
# invoke event handler
|
# invoke an event handler. a handler may return undef to indicate
|
||||||
|
# that it decided not to handle this event.
|
||||||
my $handler_result = eval { $subref->($event_name, $event_data) };
|
my $handler_result = eval { $subref->($event_name, $event_data) };
|
||||||
|
|
||||||
# update $dispatch_result only to a defined handler result because
|
# update $dispatch_result only when handler result is a defined
|
||||||
# we want to know if at least one handler handled the event. the
|
# value so we remember if any handlers have handled this event.
|
||||||
# value of $dispatch_result will be undef if NONE of the handlers
|
|
||||||
# have kicked in. in other words, an event handler may return
|
|
||||||
# undef to indicate that they didn't handle the event after all.
|
|
||||||
$dispatch_result = $handler_result if defined $handler_result;
|
$dispatch_result = $handler_result if defined $handler_result;
|
||||||
|
|
||||||
# check for error
|
# check for exception
|
||||||
if (my $error = $@) {
|
if (my $exception = $@) {
|
||||||
chomp $error;
|
$self->{pbot}->{logger}->log("Exception in event handler: $exception");
|
||||||
$self->{pbot}->{logger}->log("Error in event handler: $error\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# return dispatch result. if at least one event handler returned a defined
|
# return undef if no handlers have handled this event; otherwise the return
|
||||||
# value, then this event is considered handled. if there were no handlers
|
# value of the last event handler to handle this event.
|
||||||
# or if all of the available handers returned undef then this value will
|
|
||||||
# be undef.
|
|
||||||
return $dispatch_result;
|
return $dispatch_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user