NAME

POE::Component::Schedule - Schedule POE events using DateTime::Set iterators

SYNOPSIS

use POE qw(Component::Schedule);
use DateTime::Set;

POE::Session->create(
    inline_states => {
        _start => sub {
            $_[HEAP]{sched} = POE::Component::Schedule->add(
                $_[SESSION], Tick => DateTime::Set->from_recurrence(
                    after      => DateTime->now,
                    before     => DateTime->now->add(seconds => 3),
                    recurrence => sub {
                        return $_[0]->truncate( to => 'second' )->add( seconds => 1 )
                    },
                ),
            );
        },
        Tick => sub {
            print 'tick ', scalar localtime, "\n";
        },
        remove_sched => sub {
            # Three ways to remove a schedule
            # The first one is only for API compatibility with POE::Component::Cron
            $_[HEAP]{sched}->delete;
            $_[HEAP]{sched} = undef;
            delete $_[HEAP]{sched};
        },
        _stop => sub {
            print "_stop\n";
        },
    },
);

POE::Kernel->run();

DESCRIPTION

This component encapsulates a session that sends events to client sessions on a schedule as defined by a DateTime::Set iterator.

POE::Component::Schedule METHODS

spawn(Alias => name)

No need to call this in normal use, add() and new() all crank one of these up if it is needed. Start up a PoCo::Schedule. Returns a handle that can then be added to.

add()

my $sched = POE::Component::Schedule->add(
    $session_object,
    $event_name,
    $DateTime_Set_iterator,
    @event_args
);

Add a set of events to the schedule. The $session_object and $event_name are passed to POE without even checking to see if they are valid and so have the same warnings as ->post() itself. $session_object must be a real POE::Session, not a session ID. Else session reference count will not be increased and the session may end before receiving all events.

Returns a schedule handle. The event is removed from when the handle is not referenced anymore.

new

new is an alias for add

SCHEDULE HANDLE METHODS

delete

Removes a schedule using the handle returned from ->add or ->new.

DEPRECATED: Schedules are now automatically deleted when they are not referenced anymore. So just setting the container variable to undef will delete the schedule.

SEE ALSO

POE, DateTime::Set, POE::Component::Cron.

BUGS

You can look for information at:

ACKNOWLEDGMENT

This module is a friendly fork of POE::Component::Cron to extract the generic parts and isolate the Cron specific code in order to reduce dependencies on other CPAN modules.

The orignal author of POE::Component::Cron is Chris Fedde.

See https://rt.cpan.org/Ticket/Display.html?id=44442

AUTHORS

Olivier Mengué, dolmen@cpan.org
Chris Fedde, cfedde@cpan.org

COPYRIGHT AND LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.