Aion-Emitter
view release on metacpan or search on metacpan
lib/Aion/Emitter.pm view on Meta::CPAN
0.1.0
=head1 SYNOPSIS
File lib/Event/BallEvent.pm:
package Event::BallEvent;
use Aion;
has radius => (is => 'rw', isa => Num);
has weight => (is => 'rw', isa => Num);
1;
File lib/Listener/RadiusListener.pm:
package Listener::RadiusListener;
use Aion;
#@listen Event::BallEvent
sub listen {
my ($self, $event) = @_;
$event->radius(10);
}
1;
File lib/Listener/WeightListener.pm:
package Listener::WeightListener;
use Aion;
#@listen Event::BallEvent
sub listen {
my ($self, $event) = @_;
$event->weight(12);
}
#@listen Event::BallEvent#mini âMinimize versionâ
sub minimize {
my ($self, $event) = @_;
$event->weight(3);
}
1;
File etc/annotation/listen.ann:
Listener::RadiusListener#listen,6=Event::BallEvent
Listener::WeightListener#listen,6=Event::BallEvent
Listener::WeightListener#minimize,6=Event::BallEvent#mini âMinimize versionâ
use lib 'lib';
use Aion::Emitter;
use Event::BallEvent;
my $emitter = Aion::Emitter->new;
my $ballEvent = Event::BallEvent->new;
$emitter->emit($ballEvent);
$ballEvent->radius # -> 10
$ballEvent->weight # -> 12
$ballEvent->radius(0);
$emitter->emit($ballEvent, "mini");
$ballEvent->weight # -> 3
$ballEvent->radius # -> 0
=head1 DESCRIPTION
This event dispatcher implements the B<Event Dispatcher> pattern in which an event is defined by the class of the event object (event).
The listener is registered as an aeon in the pleroma and will always be represented by one object.
The event processing method is marked with the C<#@listen> annotation.
=head1 SUBROUTINES
=head2 emit ($event, [$key])
Emits an event: calls all listeners associated with the C<$event> event.
The additional parameter C<$key> allows you to specify a qualifying event. Imagine that we have many controllers and we want to emit an event not for all, but for each specific controller. Writing a class that extends the request class for each contr...
C<$key> can contain letters, numbers, underscores, dashes, colons and periods.
=head1 AUTHOR
Yaroslav O. Kosmina L<mailto:dart@cpan.org>
=head1 LICENSE
â B<Perl5>
=head1 COPYRIGHT
The Aion::Emitter module is copyright (c) 2026 Yaroslav O. Kosmina. Rusland. All rights reserved.
( run in 0.429 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )