NAME
Net::BitTorrent::Emitter - Base class for event-driven objects
SYNOPSIS
class My::Class : isa(Net::BitTorrent::Emitter) { ... }
my $obj = My::Class->new;
$obj->on( 'my_event' => sub ($self, @args) { ... } );
DESCRIPTION
This class provides a simple event emitter mechanism. It is used as a base class for many components in Net::BitTorrent.
METHODS
on( $event, $callback )
Registers an event listener.
$obj->on('connected', sub ($obj, $peer) {
say "Connected to " . $peer->ip;
});
This method adds a callback to be executed when the specified event is emitted. It returns the emitter object for chaining.
Expected parameters:
$event-
The name of the event to listen for.
$callback-
The code reference to execute. It receives the emitter object as the first argument, followed by any arguments passed to the emit call.
set_parent_emitter( $parent )
Sets the parent emitter for event bubbling.
$obj->set_parent_emitter( $parent );
This method allows events emitted by this object to bubble up to a parent emitter.
Expected parameters:
AUTHOR
Sanko Robinson <sanko@cpan.org>
COPYRIGHT
Copyright (C) 2008-2026 by Sanko Robinson.
This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.