The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

AnyEvent::FTP::Role::Event - Event interface for AnyEvent::FTP objects

VERSION

version 0.19

SYNOPSIS

 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

DESCRIPTION

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.

METHODS

define_events

 __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.

emit

 $obj->emit($event_name, @arguments);

This calls the callbacks associated with the given $event_name. It will pass to that callback the given @arguments.

SEE ALSO

AUTHOR

Author: Graham Ollis <plicease@cpan.org>

Contributors:

Ryo Okamoto

Shlomi Fish

José Joaquín Atria

COPYRIGHT AND LICENSE

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.