The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

ONE - A Node.js style AnyEvent class, using MooseX::Event

VERSION

version v0.2.0

SYNOPSIS

# General event loop:

    use ONE;
    
    ONE->start;

# Collation:

    use ONE;
    use ONE::Timer;
    
    collect {
         ONE::Timer->after( 2 => sub { say "two" } );
         ONE::Timer->after( 3 => sub { say "three" } );
    }; # After three seconds will have printed "two" and "three"

DESCRIPTION

EVENTS

idle

This is an AnyEvent idle watcher. It will repeatedly invoke the listener whenever the process is idle. Several thousand times per second on a moderately loaded system. Attaching a once listener to this will let you defer code until any active events have finished processing.

SIG*

You can register event listeners for any of the following events:

    SIGHUP   SIGINT  SIGQUIT SIGILL  SIGTRAP SIGABRT SIGBUS    SIGFPE    SIGKILL
    SIGUSR1  SIGSEGV SIGUSR2 SIGPIPE SIGALRM SIGTERM SIGSTKFLT SIGCHLD   SIGCONT
    SIGSTOP  SIGTSTP SIGTTIN SIGTTOU SIGURG  SIGXCPU SIGXFSZ   SIGVTALRM SIGPROF
    SIGWINCH SIGIO   SIGPWR  SIGSYS

Some of these may not actually be catchable (ie, SIGKILL), this is just the list from "kill -l" on a modern Linux system. Using one of these installs any AnyEvent signal watcher. As with AnyEvent, this will work

CLASS METHODS

our method instance() returns ONE

Return the singleton object for this class

our method loop()

Starts the main event loop. This will return when the stop method is called. If you call start with an already active loop, the previous loop will be stopped and a new one started.

our method stop()

Exits the main event loop.

HELPERS

collect { ... }

Will return after all of the events declared inside the collect block have been emitted at least once.

our method activate_event( $event )

This method is called by MooseX::Event when the first event listener for a particular event is registered. We use this to start the AE::idle or AE::signal event listeners. We wouldn't want them running when the user has no active listeners.

our method deactivate_event( $event )

This method is called by MooseX::Event when the last event listener for a particular event is removed. We use this to shutdown the AE::idle or AE::signal event listeners when the last acitve listener is removed.

our method unimport()

Removes the collect helper method

AUTHOR

Rebecca Turner <becca@referencethis.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Rebecca Turner.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.