AnyEvent::FTP::Role::Event - Event interface for AnyEvent::FTP objects
version 0.19
package AnyEvent::FTP::Foo; use Moo; with 'AnyEvent::FTP::Role::Event'; __PACKAGE__->define_events(qw( error good )); sub some_method { my($self) = @_; if($self->other_method) { $self->emit(good => 'paylod message'); } else { $self->emit(error => 'something went wrong!'); } }
later on somewhere else
use AnyEvent::FTP::Foo; my $foo = AnyEvent::FTP::Foo->new; $foo->on_good(sub { my($message) = @_; print "worked: $message"; }); $foo->on_error(sub { my($message) = @_; print "failed: $message"; }); $foo->some_method
This role provides a uniform even callback mechanism for classes in AnyEvent::FTP. You declare events by using the define_events method. Once declared you can use on_event_name to add a callback to a particular event and emit to trigger those callbacks.
define_events
on_
emit
__PACKAGE__->define_events( @list_of_event_names );
This is called within the class package to declare the event names for all events used by the class. It creates methods of the form on_event_name which can be used to add callbacks to events.
$obj->emit($event_name, @arguments);
This calls the callbacks associated with the given $event_name. It will pass to that callback the given @arguments.
$event_name
@arguments
AnyEvent::FTP
Author: Graham Ollis <plicease@cpan.org>
Contributors:
Ryo Okamoto
Shlomi Fish
José Joaquín Atria
This software is copyright (c) 2017-2021 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install AnyEvent::FTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::FTP
CPAN shell
perl -MCPAN -e shell install AnyEvent::FTP
For more information on module installation, please visit the detailed CPAN module installation guide.