GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MOJO::EVENTEMITTER (3)

.ds Aq ’

NAME

Mojo::EventEmitter - Event emitter base class

CONTENTS

SYNOPSIS



  package Cat;
  use Mojo::Base Mojo::EventEmitter;

  # Emit events
  sub poke {
    my $self = shift;
    $self->emit(roar => 3);
  }

  package main;

  # Subscribe to events
  my $tiger = Cat->new;
  $tiger->on(roar => sub {
    my ($tiger, $times) = @_;
    say RAWR! for 1 .. $times;
  });
  $tiger->poke;



DESCRIPTION

Mojo::EventEmitter is a simple base class for event emitting objects.

EVENTS

Mojo::EventEmitter can emit the following events.

    error



  $e->on(error => sub {
    my ($e, $err) = @_;
    ...
  });



This is a special event for errors, it will not be emitted directly by this class but is fatal if unhandled.



  $e->on(error => sub {
    my ($e, $err) = @_;
    say "This looks bad: $err";
  });



METHODS

Mojo::EventEmitter inherits all methods from Mojo::Base and implements the following new ones.

    catch



  $e = $e->catch(sub {...});



Subscribe to error event.



  # Longer version
  $e->on(error => sub {...});



    emit



  $e = $e->emit(foo);
  $e = $e->emit(foo, 123);



Emit event.

    has_subscribers



  my $bool = $e->has_subscribers(foo);



Check if event has subscribers.

    on



  my $cb = $e->on(foo => sub {...});



Subscribe to event.



  $e->on(foo => sub {
    my ($e, @args) = @_;
    ...
  });



    once



  my $cb = $e->once(foo => sub {...});



Subscribe to event and unsubscribe again after it has been emitted once.



  $e->once(foo => sub {
    my ($e, @args) = @_;
    ...
  });



    subscribers



  my $subscribers = $e->subscribers(foo);



All subscribers for event.



  # Unsubscribe last subscriber
  $e->unsubscribe(foo => $e->subscribers(foo)->[-1]);

  # Change order of subscribers
  @{$e->subscribers(foo)} = reverse @{$e->subscribers(foo)};



    unsubscribe



  $e = $e->unsubscribe(foo);
  $e = $e->unsubscribe(foo => $cb);



Unsubscribe from event.

DEBUGGING

You can set the MOJO_EVENTEMITTER_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.



  MOJO_EVENTEMITTER_DEBUG=1



SEE ALSO

Mojolicious, Mojolicious::Guides, <http://mojolicious.org>.
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 MOJO::EVENTEMITTER (3) 2016-03-15

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.