package RSSReader::Notifier; use strict; use Data::Dumper; use base qw( RSSReader::Logger ); sub notify_me { my $s = shift; my %a = @_; $s->log_spam("$a{caller} wants to be notified of $a{event}"); foreach my $n ( @{$s->{_events_to_notify}->{$a{event}}} ) { if ( $n->{package} eq $a{caller} && $n->{call} eq $a{call} ) { $s->log_spam("event $a{event} is already subscribed by you ($n->{package}) to call $n->{call}"); return undef; } } push @{$s->{_events_to_notify}->{$a{event}}}, { package => $a{caller}, call=>$a{call} }; } sub notify { my $s = shift; my $event = shift; $s->log_debug("I have a '".$event."' event"); foreach my $to_call ( @{$s->{_events_to_notify}->{$event}} ) { $s->log_debug("Notifying ".(ref($to_call) || $to_call)); my $obj = $to_call->{package}; my $call = $to_call->{call}; eval { $obj->$call(where=>$s, @_) }; $s->log_error("ERROR, something very wrong : $@") if $@; } } 1;